Skip to content

Fix config parsing for Nemotron-H checkpoints saved by transformers - #1857

Merged
michalk8 merged 4 commits into
ml-explore:mainfrom
brunopistone:fix/nemotron-h-config-compat
Sep 17, 2026
Merged

michalk8 merged 4 commits into
ml-explore:mainfrom
brunopistone:fix/nemotron-h-config-compat

Conversation

@brunopistone

Copy link
Copy Markdown
Contributor

Loading or converting a Nemotron-H checkpoint written by a recent transformers release fails in three separate places:

  • num_hidden_layers is a property of layers_block_type in transformers, so it never appears in the saved config and ModelArgs raises "missing 1 required positional argument: 'num_hidden_layers'". Derive the layer count from the block list instead, accept layer_types as an alias for layers_block_type, map both the current and the legacy block-type spellings, and raise a listed-values error for unknown ones.

  • transformers tags non-finite floats, e.g. {"__float__": "Infinity"}, so that config.json stays valid JSON for every parser. load_config passed the tag through untouched, so time_step_limit reached mx.clip as a dict. Decode the tags on load and re-encode them on save, which keeps a converted config readable by both libraries.

  • A config missing a required key surfaced as a bare __init__ TypeError naming only the first missing argument and no model type. Report the model type and every missing key instead.

Each new test fails on main with the corresponding error.

  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure:
    The patch was co-written with Claude Code under my directions. Manual reviews and live tests were performed.

brunopistone and others added 3 commits September 7, 2026 15:41
Loading or converting a Nemotron-H checkpoint written by a recent
transformers release fails in three separate places:

- num_hidden_layers is a property of layers_block_type in transformers,
  so it never appears in the saved config and ModelArgs raises
  "missing 1 required positional argument: 'num_hidden_layers'".
  Derive the layer count from the block list instead, accept layer_types
  as an alias for layers_block_type, map both the current and the legacy
  block-type spellings, and raise a listed-values error for unknown ones.

- transformers tags non-finite floats, e.g. {"__float__": "Infinity"},
  so that config.json stays valid JSON for every parser. load_config
  passed the tag through untouched, so time_step_limit reached mx.clip
  as a dict. Decode the tags on load and re-encode them on save, which
  keeps a converted config readable by both libraries.

- A config missing a required key surfaced as a bare __init__ TypeError
  naming only the first missing argument and no model type. Report the
  model type and every missing key instead.

Each new test fails on main with the corresponding error.

@michalk8 michalk8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've reverted the change in ModelArgs.__init__, as it's out-of-scope of this PR. Otherwise, LGTM!

@michalk8
michalk8 merged commit 28e9ccd into ml-explore:main Sep 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants