Repository navigation
Route dense NemotronH models to the transformers 5.10 tier - #6541
Conversation
Dense NemotronH models (e.g. unsloth/NVIDIA-Nemotron-3-Nano-4B) describe their
layer stack with a hybrid_override_pattern that includes '-' (MLP) layers.
transformers only learned to parse that ('-' -> 'mlp' in pattern_mapping, 'mlp'
in valid_types and MIXER_TYPES) in 5.10; on 5.3/5.5 the config raises
KeyError: '-'. The model also ships auto_map remote code, so training and
inference that approve trust_remote_code load fine, but a native (TRC=False)
load such as export hits the built-in parser and fails with
'Failed to load checkpoint: -'.
Detect dense NemotronH from config.json (a '-' in hybrid_override_pattern, or
'mlp' in an expanded layers_block_type) and route it to the 5.10 tier, where the
model loads natively without remote code. Pure-MoE NemotronH configs are
unaffected and keep their existing tier.
Covers both the local config.json and the remote HF-id paths, and adds tests for
the detector and the resulting tier selection.
There was a problem hiding this comment.
Code Review
This pull request adds support for routing dense NemotronH models (which use MLP layers requiring transformers>=5.10) to the 5.10 transformers sidecar. It introduces a helper function _nemotron_h_needs_mlp_support to detect these models based on their configuration pattern or block types, integrates this check into _config_needs_510, and adds comprehensive unit tests to verify the behavior for both local and remote configurations. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: daf90a3d26
ℹ️ 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".
| ) | ||
|
|
||
| with patch("urllib.request.urlopen") as mock_urlopen: | ||
| assert get_transformers_tier(str(tmp_path)) == "510" |
There was a problem hiding this comment.
Cover local checkpoints through activation
This local-checkpoint case calls get_transformers_tier() directly, but the workers actually enter through activate_transformers_for_subprocess(), which first resolves local adapters/checkpoints to base_model_name_or_path/model_name before tiering. In offline or private-base scenarios that discards the local config.json, the remote config fetch cannot see the NemotronH - pattern, and the same local dense NemotronH checkpoint can still route to 530/default and hit KeyError: '-'; please cover and fix the activation path, e.g. by consulting the local config before resolving away from it.
Useful? React with 👍 / 👎.
| ).encode() | ||
|
|
||
| with patch("urllib.request.urlopen", return_value = _Response()): | ||
| assert get_transformers_tier("unsloth/NVIDIA-Nemotron-3-Nano-4B") == "510" |
There was a problem hiding this comment.
Add an offline path for known NemotronH IDs
This remote test only exercises the successful urlopen path; when HF_HUB_OFFLINE/TRANSFORMERS_OFFLINE is set (or the raw config fetch is blocked) but the HF model is already cached, _load_config_json() returns None before seeing hybrid_override_pattern and the name has no 510 substring fallback, so unsloth/NVIDIA-Nemotron-3-Nano-4B still selects default/530 and the cached load can hit the same KeyError: '-'. Please add a no-network detector for the known dense Nemotron IDs or use the HF cache, and cover that path.
Useful? React with 👍 / 👎.
| 5.10 tier. Detected via the raw pattern or an already-expanded | ||
| ``layers_block_type`` list. | ||
| """ | ||
| if cfg.get("model_type") != "nemotron_h": |
There was a problem hiding this comment.
Inspect nested NemotronH configs
This top-level model_type check misses wrapper configs whose dense NemotronH language model is under llm_config/text_config; for example nvidia/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16 has top-level model_type NemotronH_Nano_VL_V2, but its nested llm_config is nemotron_h with a hybrid_override_pattern containing -. Those models still route to default/530 and can hit the same native config parser failure, so the detector should recurse into the nested language config before returning false.
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
3 similar comments
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Three gaps could still route a dense NemotronH (MLP '-' layers) to a tier below 5.10 and hit KeyError: '-': - VL wrappers (e.g. NemotronH_Nano_VL_V2) keep the dense language model under llm_config/text_config; the detector only checked the top-level model_type. Recurse into nested language configs. - Offline or blocked config fetches returned None for an already-downloaded repo. Read config.json from the HF hub cache before any network. - A local checkpoint resolves to its base before tiering, so an offline/private base discarded the local config that revealed the dense pattern. Prefer the higher tier of the resolved base and the original path.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex review |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 62738af0f9
ℹ️ 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 model_name != resolved: | ||
| # Prefer the higher tier: a local checkpoint's own config may reveal a dense | ||
| # NemotronH the (offline/private) base does not. Avoids KeyError: '-'. | ||
| tier = _higher_tier(tier, get_transformers_tier(model_name)) |
There was a problem hiding this comment.
Avoid using path-name heuristics for local adapters
When model_name is a local LoRA adapter that resolves through adapter_config.json, this added call runs the full tier detector on the adapter directory path itself. If the adapter has no config.json and lives under a path such as /runs/gemma-4-experiment/llama-lora, get_transformers_tier(model_name) hits the substring heuristics and _higher_tier upgrades a Llama adapter to the 5.5/5.x sidecar even though the resolved base model was default; the local re-check should be limited to actual local config/tokenizer metadata rather than arbitrary path names.
Useful? React with 👍 / 👎.
| cfg = _config_json_from_hf_cache(model_name) | ||
| if cfg is not None: | ||
| _config_json_cache[cache_key] = cfg | ||
| return cfg |
There was a problem hiding this comment.
Fetch remote configs before trusting stale HF cache
For HF repo IDs that are already present in the hub cache, this returns the cached config.json without attempting the authenticated/raw fetch below. If the repo was updated after an earlier download, tier selection and the model-config/GPU-estimate callers keep using stale metadata even while online, which can misroute newly dense NemotronH/Gemma variants or show wrong config values; the cache fallback should be reserved for offline mode or after the network fetch fails.
Useful? React with 👍 / 👎.
| from huggingface_hub import try_to_load_from_cache | ||
| path = try_to_load_from_cache(model_name, "config.json") |
There was a problem hiding this comment.
Preserve subprocess sidecar isolation
For remote IDs that reach the slow config path, this imports the default-environment huggingface_hub before activate_transformers_for_subprocess prepends the selected .venv_t5_* directory. That function only changes sys.path and does not purge sys.modules, so a dense NemotronH routed to transformers 5.10 can later reuse the already-loaded default hub module instead of the pinned sidecar huggingface_hub==1.8.0, defeating the version isolation and risking import/runtime mismatches.
Useful? React with 👍 / 👎.
Address review of the nested/cached/resolved-away detection: - The local re-check ran the full tier detector on the original path, so a bare LoRA adapter under e.g. /runs/gemma-4-x/llama-lora could upgrade a default base via directory-name substrings. Gate the re-check on a real local config.json so it reads metadata, not path names. - The HF hub cache was read before any network, so an online tier check could serve stale config.json after the repo changed upstream. Consult the cache only offline or after a failed fetch. - Reading the cache imported huggingface_hub during tier detection, which runs before a sidecar venv is activated and could pin the default-env hub into sys.modules. Resolve the cache path with stdlib only.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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 |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 785f8b22e3
ℹ️ 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".
| return None | ||
| # Fall back to the hub cache if the fetch failed (rate limit, transient block). | ||
| cfg = _config_json_from_hf_cache(model_name) | ||
| _config_json_cache[cache_key] = cfg |
There was a problem hiding this comment.
Avoid caching stale HF fallback configs
When an online fetch fails transiently and a cached Hub snapshot exists, this stores the fallback config under the normal (model_name, token) cache key; because _load_config_json returns that key before attempting the network, the same long-lived backend process will keep serving the stale snapshot even after connectivity recovers. This can leave tier detection stuck on old metadata for updated models, despite online mode being expected to prefer fresh config.json; consider not caching the HF-cache fallback (or caching it separately only for offline mode).
Useful? React with 👍 / 👎.
| try: | ||
| if ref_main.is_file(): | ||
| candidates.append(repo_dir / "snapshots" / ref_main.read_text().strip() / "config.json") | ||
| candidates += sorted(repo_dir.glob("snapshots/*/config.json")) |
There was a problem hiding this comment.
Prefer the newest cached snapshot without refs/main
When a cached repo has multiple snapshots but no refs/main file (for example after commit-pinned downloads), this lexicographic sort can pick an older SHA rather than the snapshot Hugging Face would actually load; the existing cache utilities use snapshot mtime for that reason. In offline or fetch-failure tier detection, choosing an old config.json can keep a newly downloaded Nemotron/Gemma config on the wrong transformers tier, so the fallback should select the newest snapshot instead of the first sorted path.
Useful? React with 👍 / 👎.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
…fetches The HF cache fallback in tier detection picked the lexicographically-first snapshot when refs/main was absent (commit-pinned downloads), which can be an older SHA than the Hub would load. Sort snapshots by mtime instead. A transient online fetch failure cached the hub-cache fallback under the normal (model_name, token) key, so a long-lived worker kept serving stale metadata even after connectivity recovered. Return the fallback without memoizing it so the next call retries the network.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0739c52572
ℹ️ 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".
| return None | ||
| # Transient failure (rate limit, block): serve the hub cache but do NOT cache it, | ||
| # so a later call retries the network once connectivity returns. | ||
| return _config_json_from_hf_cache(model_name) |
There was a problem hiding this comment.
Keep cache-fallback config results retryable
When this fallback is used after a transient fetch error, _load_config_json avoids _config_json_cache, but get_transformers_tier() still memoizes the derived result in _config_needs_510_cache/_config_needs_550_cache. If the local Hub config is stale or missing for a dense NemotronH repo during a rate limit or network blip, later tier checks in the same process skip urlopen entirely and keep selecting 530/default even after connectivity returns. Signal that this came from a non-definitive cache fallback, or skip/clear the tier caches for these reads.
Useful? React with 👍 / 👎.
| except Exception as exc: | ||
| logger.debug("Could not fetch config.json for '%s': %s", model_name, exc) | ||
| _config_json_cache[cache_key] = None | ||
| return None | ||
| # Transient failure (rate limit, block): serve the hub cache but do NOT cache it, | ||
| # so a later call retries the network once connectivity returns. | ||
| return _config_json_from_hf_cache(model_name) |
There was a problem hiding this comment.
Don't use Hub cache after authorization failures
Because this catches every fetch exception, a 401/403/404 from the raw Hub request is treated the same as a transient outage. On a shared Studio host where a private or gated repo was already cached by an authenticated user, a later request with no or wrong token can still read that cached config.json and proceed with metadata/tier detection, bypassing the failed access check and exposing private model metadata. Limit this fallback to offline/timeouts/5xx cases, or require an authenticated cache hit before serving it.
Useful? React with 👍 / 👎.
… blips - _load_config_json: a 401/403/404 from the raw Hub request is a definitive access answer, not an outage. Return None instead of falling back to the HF hub cache, so an unauthenticated or wrong-token request can never read another caller's cached private metadata. - _check_config_needs_510/550: only memoize the derived tier when the underlying config read was definitive (local file, offline cache, or a completed fetch). A transient fetch fallback is no longer pinned, so the tier is re-evaluated once connectivity returns instead of staying stuck on the lower tier.
|
@codex review |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex Review: Didn't find any major issues. 👍 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 usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
What
Fixes
Failed to load checkpoint: '-'when loading or exporting a dense NemotronHmodel (e.g.
unsloth/NVIDIA-Nemotron-3-Nano-4B) in Studio.Root cause
Dense NemotronH models describe their layer stack with a
hybrid_override_patternstring that mixes
M(mamba),*(attention),E(moe) and-(mlp), for exampleM-M-M-MM-M-M*-M-M*-.... transformers only learned to parse the-(MLP) layer in5.10:
pattern_mappinggained"-": "mlp", andvalid_types/MIXER_TYPESgained"mlp". On 5.3 / 5.5 the config raisesKeyError: '-'in_pattern_to_list.Studio's tier selector routed this model to the 5.3 tier (530) via the
TokenizersBackendtokenizer check. The model also shipsauto_mapremote code, sotraining and inference (which run with
trust_remote_code=Trueafter consent) loadthrough the model's own code and work. But a native load with
trust_remote_code=False(such as export loading a LoRA's base model) hits the built-in 5.3 parser and fails.
Reproduced:
AutoConfig.from_pretrained(<NemotronH>, trust_remote_code=False)raisesKeyError: '-'on transformers 5.3.0, and loads cleanly on 5.10.2 (42 layers,block types
{mamba, attention, mlp}).Fix
Detect a dense NemotronH config (
model_type == "nemotron_h"with a-inhybrid_override_pattern, or"mlp"in an already-expandedlayers_block_type) androute it to the 5.10 tier, where it loads natively without remote code. Pure-MoE
NemotronH configs (no MLP layers) are unaffected and keep their existing tier.
Wired into
_config_needs_510, so both the local-checkpoint and remote-HF-id pathspick it up, and it takes precedence over the 530 tokenizer check.
Tests
tests/test_transformers_version.py: detector unit tests (dash pattern, expandedmlpblock list, MoE-only negative, non-NemotronH negative) and tier-selection testsfor a local dense-NemotronH checkpoint (510 beats the 530 tokenizer signal) and a
remote HF id. Full file: 63 passed.