Repository navigation
Nemotron-H fast_inference via vLLM weight sharing (fallback on older unsloth_zoo); drop vLLM-only kwargs on fallback - #13440
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff7ac055da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| SUPPORTS_GEMMA4 = transformers_version >= Version("5.5.0") | ||
| # unsloth_zoo cannot share these models' vLLM weights with the training model. | ||
| VLLM_UNSUPPORTED_MODEL_TYPES = ("gpt_oss",) | ||
| VLLM_UNSUPPORTED_MODEL_TYPES = ("gpt_oss", "nemotron_h") |
There was a problem hiding this comment.
Preserve pinned revisions during Nemotron fallback
When a Nemotron-H base model is loaded with both revision=... and fast_inference=True, FastLanguageModel.from_pretrained and FastModel.from_pretrained clear base_revision before probing the config because they still expect vLLM to own the weights (lines 1235–1243 and 2103–2109); this newly added match only disables fast_inference later at lines 2261–2267. The fallback therefore loads the default-branch config and weights instead of the requested revision, potentially changing experimental results despite ultimately using the in-process loader. Detect this unsupported architecture before discarding the revision, or restore the resolved revision when switching to Unsloth inference.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping this as is: the same pre-existing ordering applies to the merged gpt_oss fallback, the user is told the revision is ignored under fast_inference and that fast_inference = False loads the pin, and before this change the same call crashed after the vLLM load, so no pinned Nemotron-H fast_inference load worked to regress.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff7ac055da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| SUPPORTS_GEMMA4 = transformers_version >= Version("5.5.0") | ||
| # unsloth_zoo cannot share these models' vLLM weights with the training model. | ||
| VLLM_UNSUPPORTED_MODEL_TYPES = ("gpt_oss",) | ||
| VLLM_UNSUPPORTED_MODEL_TYPES = ("gpt_oss", "nemotron_h") |
There was a problem hiding this comment.
Apply the Nemotron fallback before requiring vLLM
When fast_inference=True is passed on a machine without vLLM, both FastLanguageModel.from_pretrained and FastModel.from_pretrained raise _vllm_unavailable_error() before reaching the new model-type check, even though Nemotron-H is now supposed to load through native Unsloth inference and never use vLLM. The new test masks this case by skipping unless vLLM is installed. Detect this unsupported architecture before the vLLM availability checks, or defer those checks until after the fallback decision.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping this as is: without vLLM, fast_inference = True stops at once with the clear install vLLM message, the same as the merged gpt_oss fallback; nothing is loaded wrong, and the user either installs vLLM (then gets this fallback) or sets fast_inference = False.
… experts out of LoRA under fast_inference
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb73a672fb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ( | ||
| target_parameters | ||
| and getattr(model, "vllm_engine", None) is not None | ||
| and getattr(getattr(model, "config", None), "model_type", None) == "nemotron_h" |
There was a problem hiding this comment.
Apply the Nemotron guard to explicit target parameters
When a caller passes a nonempty target_parameters list to get_peft_model for a Nemotron-H model loaded with fast_inference=True, execution takes the branch at line 4643, so this guard inside the auto-detection else never runs. PEFT therefore still creates adapters for the stacked expert parameters, and the vLLM load_lora path can refuse them mid-run for exactly the incompatibility described here. Move the guard after both branches (or reject the explicit request) so explicit expert targeting cannot bypass it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping this to the auto-detected targets: an explicit expert target_parameters request with fast_inference is rare, and vLLM's load_lora already refuses it with a clear message instead of training something it cannot serve.
| _vllm_unsupported = _vllm_unsupported_model_types(model_types) if fast_inference else [] | ||
| if fast_inference and _vllm_unsupported: |
There was a problem hiding this comment.
Fall back before loading expert-targeting adapters
When model_name is an existing Nemotron-H PEFT adapter whose saved config has nonempty target_parameters, a zoo with the new extractor makes this check leave fast_inference enabled, but the adapter is later attached directly by PeftModel.from_pretrained at line 3086 and never passes through the new get_peft_model guard. The resulting adapter still contains the stacked expert LoRA weights that vLLM cannot serve, so synchronizing it to the engine or generating can fail in load_lora. Inspect the adapter config and fall back to native inference before starting vLLM when it targets these experts.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar for this PR: reloading an adapter that trained Nemotron-H experts (only possible with fast_inference = False) into a fast_inference session is a rare path, and load_lora refuses it with a clear message rather than generating wrong output.
| _VLLM_ENGINE_KWARGS = ( | ||
| "max_loras", | ||
| "use_async", | ||
| "use_engine", | ||
| "enforce_eager", | ||
| "enable_prefix_caching", | ||
| "compilation_config", | ||
| "conservativeness", | ||
| "max_logprobs", | ||
| "max_num_seqs", | ||
| "return_args", |
There was a problem hiding this comment.
Drop the vLLM training argument during fallback
When a caller passes the supported vLLM knob training=False through **kwargs and any fallback is taken (an older GPU, DGX Spark, gpt-oss, or Nemotron-H with an older zoo), _drop_vllm_engine_kwargs leaves that argument behind because it is absent from this tuple. load_vllm declares training and the normal fast path forwards it dynamically, but the native path instead passes it into Transformers' model constructor, where classes such as NemotronHForCausalLM reject it as an unexpected keyword argument. Include training among the stripped engine-only arguments so these fallbacks do not reproduce the constructor failure this helper is intended to prevent.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 652663f: training joins the dropped vLLM-only arguments.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes unslothai/unsloth-zoo#565
Companion: unslothai/unsloth-zoo#1733 (vLLM weight sharing for Nemotron-H).
Problem
fast_inference = Trueon Nemotron-H (for examplenvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16) starts vLLM, loads the whole model, then crashes when unsloth_zoo rebuilds the training model from vLLM's weights:UnboundLocalError: cannot access local variable 'prefix'.AttributeError: 'NemotronHModel' object has no attribute 'embedding_norm'.Separately, every "will switch to Unsloth inference" fallback (gpt-oss, GPUs below compute capability 7, DGX Spark) passes vLLM engine arguments such as
enforce_eagerormax_num_seqson to transformers'from_pretrained, which then fails withTypeError: ... __init__() got an unexpected keyword argument 'enforce_eager'.Change
unsloth_zoo.empty_model.extract_nemotron_h_mixerfalls back to Unsloth inference before vLLM starts, with the same message as gpt-oss.fast_inference, Nemotron-H's routed MoE experts stay out of LoRA (printed note): vLLM 0.31 serves them only through the 2DFusedMoEWithLoRA, which cannot take Unsloth's stacked expert adapter. Attention, Mamba and MLP LoRA are served;fast_inference = Falsestill trains the experts.enforce_eager,max_num_seqs,compilation_config, ...) and say so:Unsloth: Ignoring vLLM-only arguments ['enforce_eager', 'max_num_seqs'] since vLLM is not used.Testing (vLLM 0.31.0, transformers 5.17.0, torch 2.13.0, TRL 0.25.1)
fast_inference = True, zoo mainAttributeError: ... 'embedding_norm'after the vLLM loadgenerateworksenforce_eager = True, max_num_seqs = 8TypeError: NemotronHForCausalLM.__init__() got an unexpected keyword argument 'enforce_eager'unsloth/NVIDIA-Nemotron-3-Nano-4B, GRPO 3 steps,fast_inference = True, zoo #1733 (B200)unsloth/Nemotron-3-Nano-30B-A3B, same, zoo #1733 (Colab G4)tests/fast_inference/test_nemotron_h_fallback.py,test_gpt_oss_fallback.py