Skip to content

feat: size routed_experts carry dtype from the model's expert count - #3113

Merged
terrykong merged 1 commit into
NVIDIA-NeMo:mainfrom
zyzhou5:zezhou/r3-routed-experts-int16
Jul 17, 2026
Merged

terrykong merged 1 commit into
NVIDIA-NeMo:mainfrom
zyzhou5:zezhou/r3-routed-experts-int16

Conversation

@zyzhou5

@zyzhou5 zyzhou5 commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Resolve the narrowest signed dtype that fits expert ids plus the -1 missing-route sentinel (int8 <=128 experts, int16 <=32768, int32 beyond; int16 fallback when undetectable) once per run, and use it at every routed_experts ingestion point instead of hardcoded int32. Shrinks route payloads 2-4x across message logs, transports, replay buffers, and checkpoints. A one-time per-process range check turns a mis-detected expert count into a loud error instead of silent wraparound. The Megatron replay install still converts to int64 at the gather site, so training math is unchanged.

Validation

We observed no regression after the change.
Screenshot 2026-07-08 at 1 48 07 PM

@zyzhou5
zyzhou5 requested review from a team as code owners July 8, 2026 03:59
@copy-pr-bot

copy-pr-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@zyzhou5 zyzhou5 added the CI:L1 Run doctests, unit tests, and functional tests label Jul 8, 2026
@zyzhou5

zyzhou5 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c4074b7

Resolve the narrowest signed dtype that fits expert ids plus the -1
missing-route sentinel (int8 <=128 experts, int16 <=32768, int32 beyond;
int16 fallback when undetectable) once per run, and use it at every
routed_experts ingestion point instead of hardcoded int32. Shrinks route
payloads 2-4x across message logs, transports, replay buffers, and
checkpoints. A one-time per-process range check turns a mis-detected
expert count into a loud error instead of silent wraparound. The Megatron
replay install still converts to int64 at the gather site, so training
math is unchanged.

Signed-off-by: Zeyu Zhou <[email protected]>
@zyzhou5
zyzhou5 force-pushed the zezhou/r3-routed-experts-int16 branch from c4074b7 to 8520240 Compare July 8, 2026 21:36
@zyzhou5

zyzhou5 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8520240

Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/models/generation/interfaces.py Resolved
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

Thanks a lot. @zyzhou5 LGTM!

@terrykong
terrykong merged commit f2705e0 into NVIDIA-NeMo:main Jul 17, 2026
93 checks passed
arnavk-nvidia pushed a commit that referenced this pull request Jul 17, 2026
pjin-nvidia added a commit that referenced this pull request Oct 8, 2026
vLLM 0.29 stores routed expert ids as uint16 once a model has more
than 256 experts (RoutedExpertsManager), and torch implements no
reductions for uint16. The one-time range check in
_as_routed_experts_tensor (#3113) called tensor.max() on those ids,
so with router replay on Super v3.5 (512 experts) every chat
completion that carried routes failed with

  NotImplementedError: "max_all" not implemented for 'UInt16'

and, since the check sets its flag only after it passes, so did
every later one: Gym saw HTTP 500 on each policy call.

- Take the max in int64 for uint16, uint32 and uint64 ids; the ids
  are then cast to the carry dtype as before.
- Tests: numpy and torch uint16 ids convert to int16, and a uint16
  id past the carry dtype is still rejected.

Signed-off-by: Peter Jin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants