Skip to content

Nemotron-H fast_inference via vLLM weight sharing (fallback on older unsloth_zoo); drop vLLM-only kwargs on fallback - #13440

Merged
danielhanchen merged 6 commits into
mainfrom
fix-nemotronh-fast-inference-fallback
Oct 13, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
fix-nemotronh-fast-inference-fallback

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Fixes unslothai/unsloth-zoo#565

Companion: unslothai/unsloth-zoo#1733 (vLLM weight sharing for Nemotron-H).

Problem

fast_inference = True on Nemotron-H (for example nvidia/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:

  • Reporter (unsloth 2026.3.15, vLLM 0.18): UnboundLocalError: cannot access local variable 'prefix'.
  • Current main (vLLM 0.31): 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_eager or max_num_seqs on to transformers' from_pretrained, which then fails with TypeError: ... __init__() got an unexpected keyword argument 'enforce_eager'.

Change

  • With fast_inference for Nemotron-H: share vLLM's Mamba-2, attention, MLP and MoE weights unsloth-zoo#1733 installed, Nemotron-H loads through vLLM and shares its weights with the training model. An unsloth_zoo without unsloth_zoo.empty_model.extract_nemotron_h_mixer falls back to Unsloth inference before vLLM starts, with the same message as gpt-oss.
  • Under fast_inference, Nemotron-H's routed MoE experts stay out of LoRA (printed note): vLLM 0.31 serves them only through the 2D FusedMoEWithLoRA, which cannot take Unsloth's stacked expert adapter. Attention, Mamba and MLP LoRA are served; fast_inference = False still trains the experts.
  • The fallbacks drop vLLM-only arguments (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)

Case main this PR
tiny Nemotron-H, fast_inference = True, zoo main AttributeError: ... 'embedding_norm' after the vLLM load falls back to Unsloth inference, generate works
same, plus enforce_eager = True, max_num_seqs = 8 TypeError: NemotronHForCausalLM.__init__() got an unexpected keyword argument 'enforce_eager' falls back, prints the ignored arguments
unsloth/NVIDIA-Nemotron-3-Nano-4B, GRPO 3 steps, fast_inference = True, zoo #1733 (B200) crash at load passed: loss -0.013 / 0.001 / -0.021, grad norm 0.234 / 0.136 / 0.147, peak 16.5 GB, vLLM engine attached
unsloth/Nemotron-3-Nano-30B-A3B, same, zoo #1733 (Colab G4) crash at load passed: grad norm 0.231 / 0.135 / 0.167, reward std 0.78 / 0.57 / 0.56, peak 81.9 GB
tests/fast_inference/test_nemotron_h_fallback.py, test_gpt_oss_fallback.py Nemotron fallback test fails 3 passed

@danielhanchen danielhanchen self-assigned this Oct 12, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T15:26:21.882714Z 4b469fd Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread unsloth/models/loader.py Outdated
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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread unsloth/models/loader.py Outdated
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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danielhanchen danielhanchen changed the title Fall back to Unsloth inference for Nemotron-H with fast_inference=True Nemotron-H fast_inference via vLLM weight sharing (fallback on older unsloth_zoo); drop vLLM-only kwargs on fallback Oct 13, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread unsloth/models/vision.py
Comment on lines +4675 to +4678
if (
target_parameters
and getattr(model, "vllm_engine", None) is not None
and getattr(getattr(model, "config", None), "model_type", None) == "nemotron_h"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread unsloth/models/loader.py
Comment on lines +2300 to 2301
_vllm_unsupported = _vllm_unsupported_model_types(model_types) if fast_inference else []
if fast_inference and _vllm_unsupported:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread unsloth/models/loader.py
Comment on lines +975 to +985
_VLLM_ENGINE_KWARGS = (
"max_loras",
"use_async",
"use_engine",
"enforce_eager",
"enable_prefix_caching",
"compilation_config",
"conservativeness",
"max_logprobs",
"max_num_seqs",
"return_args",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 652663f: training joins the dropped vLLM-only arguments.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 652663f15a

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 4b469fdc1f

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for fast_inference in Nemotron-3-nano-30b-a3b-bf16

1 participant