feat(inference): uint16 routed-experts payload for >256-expert models (#3051)
Docker Push / Push CUDA image to Docker (push) Canceled after 0s
Docker Push / Push CUDA image to Docker (push) Canceled after 0s
* feat(inference): uint16 routed-experts payload for >256-expert models serialize_routed_experts packed expert indices as uint8, which overflows for models with >256 experts — NemotronH Super/Ultra route top-22 over 512 experts, so every /generate call with routed-experts capture 500'd (assert array.max() <= iinfo(uint8).max), stalling router-replay training. Make the payload self-describing: pick uint8 when indices fit, uint16 otherwise, and emit the chosen dtype in the payload. Consumers default to uint8 when the field is absent, so payloads from <=256-expert models are byte-identical to before. Decoder half: verifiers feat/routed-experts-dtype (must land first and be pinned here before a >256-expert model enables enable_return_routed_experts). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(trainer): dtype-agnostic routed-experts row size The batch packer sized routed-experts rows via a hardcoded dtype->itemsize table that lacked uint16 (KeyError on the first >256-expert batch). Use np.dtype(...).itemsize instead of maintaining the table. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore: bump verifiers to main (dtype-aware routed-experts decode) PrimeIntellect-ai/verifiers#2043 merged — the decoder half of the self-describing routed-experts payload. This pin makes the pair complete: uint16 payloads from this branch's encoder are decoded correctly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore: relock for the verifiers bump Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
013a7f8c25
commit
6b1604380c
Vendored
+1
-1
Submodule deps/verifiers updated: 1cfdd39cc2...19fdd9cae1
@@ -15,15 +15,21 @@ def serialize_routed_experts(routed_experts: Any, start: int = 0) -> dict[str, A
|
||||
array = np.asarray(routed_experts)
|
||||
assert array.ndim == 3
|
||||
assert np.issubdtype(array.dtype, np.integer)
|
||||
dtype = np.uint8
|
||||
if array.size:
|
||||
assert array.min() >= 0
|
||||
assert array.max() <= np.iinfo(np.uint8).max
|
||||
if array.max() > np.iinfo(np.uint8).max:
|
||||
# Models with >256 experts (e.g. NemotronH Super/Ultra: 512) need wider
|
||||
# indices. The payload self-describes via "dtype" so consumers pick it up.
|
||||
assert array.max() <= np.iinfo(np.uint16).max
|
||||
dtype = np.uint16
|
||||
|
||||
compact = np.ascontiguousarray(array.astype(np.uint8, copy=False))
|
||||
compact = np.ascontiguousarray(array.astype(dtype, copy=False))
|
||||
return {
|
||||
"data": pybase64.b64encode(memoryview(compact)).decode("ascii"),
|
||||
"shape": list(compact.shape),
|
||||
"start": start,
|
||||
"dtype": np.dtype(dtype).name,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,12 +7,6 @@ import numpy as np
|
||||
from prime_rl.trainer.utils import balanced_partition
|
||||
from prime_rl.transport.types import EncodedTensor, MicroBatch, RoutedExperts, TrainingSample
|
||||
|
||||
ROUTED_EXPERTS_DTYPE_ITEMSIZE = {
|
||||
"uint8": 1,
|
||||
"int16": 2,
|
||||
"int32": 4,
|
||||
}
|
||||
|
||||
# Backfill value per component weight stream when a packed sample doesn't
|
||||
# carry it: absent rl means weight 1.0 on the loss mask, absent ce/ref_kl
|
||||
# means no component (weight 0.0).
|
||||
@@ -28,7 +22,7 @@ def _copy_routed_experts(routed_experts: RoutedExperts) -> RoutedExperts:
|
||||
|
||||
|
||||
def _routed_experts_row_size(routed_experts: RoutedExperts) -> int:
|
||||
return routed_experts.shape[1] * routed_experts.shape[2] * ROUTED_EXPERTS_DTYPE_ITEMSIZE[routed_experts.dtype]
|
||||
return routed_experts.shape[1] * routed_experts.shape[2] * np.dtype(routed_experts.dtype).itemsize
|
||||
|
||||
|
||||
def _slice_routed_experts(routed_experts: RoutedExperts, seq_len: int) -> RoutedExperts:
|
||||
|
||||
@@ -7631,7 +7631,7 @@ requires-dist = [
|
||||
{ name = "python-dotenv", marker = "extra == 'browser'", specifier = ">=1.0.0" },
|
||||
{ name = "pyzmq", specifier = ">=27.1.0" },
|
||||
{ name = "reasoning-gym", marker = "extra == 'rg'" },
|
||||
{ name = "renderers", specifier = ">=0.1.8.dev40" },
|
||||
{ name = "renderers", specifier = ">=0.1.8" },
|
||||
{ name = "requests" },
|
||||
{ name = "requests", marker = "extra == 'rl'" },
|
||||
{ name = "rich" },
|
||||
|
||||
Reference in New Issue
Block a user