Skip to content

Add formal YaRN RoPE config fields and CLI plumbing for hybrid models - #5461

Closed
guihong-nv wants to merge 1 commit into
NVIDIA:mainfrom
guihong-nv:mbridge-yarn
Closed

guihong-nv wants to merge 1 commit into
NVIDIA:mainfrom
guihong-nv:mbridge-yarn

Conversation

@guihong-nv

@guihong-nv guihong-nv commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do ?

Declares the YaRN RoPE parameters as formal TransformerConfig fields so that --position-embedding-type yarn is actually usable for hybrid models.

HybridModel already instantiates YarnRotaryEmbedding from getattr(self.config, "yarn_*") (added in #4244), but those yarn_* attributes were never declared on TransformerConfig — they were only set dynamically in tests. As a result, launching with --position-embedding-type yarn raised AttributeError.

  • megatron/core/transformer/transformer_config.py — declares the 7 YaRN fields on TransformerConfig with safe defaults (yarn_rotary_scaling_factor, yarn_original_max_position_embeddings, yarn_beta_fast, yarn_beta_slow, yarn_mscale, yarn_mscale_all_dim, yarn_correction_range_round_to_int). The default yarn_rotary_scaling_factor=1.0 is a no-op, so existing configs are unaffected.
  • tests/unit_tests/models/test_hybrid_model.py — drives the YaRN test config via the constructor (the formal-field path) and adds two tests: one asserting the fields exist as dataclass fields with the expected defaults, and one asserting the config values flow into the YarnRotaryEmbedding instance.

The matching --yarn-* CLI flags are produced automatically: _add_network_size_args builds a TransformerConfig argument group via ArgumentGroupFactory(TransformerConfig), which derives one CLI flag (and the args→config plumbing) per dataclass field. No manual argument plumbing is needed — adding the flags by hand would duplicate the auto-generated ones and raise argparse: conflicting option string.

No behavior change for non-YaRN paths. Validated on GPU: the full arg parser builds with the --yarn-* flags auto-generated (no conflict), and tests/unit_tests/models/test_hybrid_model.py plus tests/unit_tests/transformer/test_multi_latent_attention.py pass (one pre-existing, environment-related context-parallel SIGABRT reproduces on unmodified main and is unrelated to this change).

Issue tracking

Related to #4244 (which added the YaRN wiring in HybridModel).

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

HybridModel already builds YarnRotaryEmbedding from getattr(self.config,
"yarn_*") (NVIDIA#4244), but those attributes were never declared on
TransformerConfig and had no CLI plumbing, so --position-embedding-type yarn
raised AttributeError and YaRN could not be configured from the command line.

- transformer_config.py: declare the 7 yarn_* fields with safe defaults
  (yarn_rotary_scaling_factor default 1.0 is a no-op).
- arguments.py: add matching --yarn-* args; dest names match the field names
  so core_transformer_config_from_args plumbs them through automatically.
- test_hybrid_model.py: drive the yarn test config via the constructor and add
  tests for the dataclass fields and config->embedding plumbing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Guihong Li <guihongl@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jun 23, 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.

@guihong-nv

Copy link
Copy Markdown
Contributor Author

/ok to test 8ec9a40

This branch was previously deployed

2 inactive deployments
public — 8ec9a400 Deployed Jun 23, 2026 by copy-pr-bot[bot] via finalize / publish-docs #2527
test — 8ec9a400 Deployed Jun 23, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #15709
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.

1 participant