Skip to content

[training] fix: support MCore tokenizer padding fields - #4075

Merged
yaoyu-33 merged 1 commit into
mainfrom
yuya/nvbug-6232591-tokenizer-config
May 29, 2026
Merged

yaoyu-33 merged 1 commit into
mainfrom
yuya/nvbug-6232591-tokenizer-config

Conversation

@yaoyu-33

Copy link
Copy Markdown
Contributor

Summary

Add the MCore tokenizer padding fields that Bridge's TokenizerConfig needs when it is passed through megatron.core.tokenizers.utils.build_tokenizer:

  • make_vocab_size_divisible_by
  • tensor_model_parallel_size
  • rank

The defaults are neutral for Bridge checkpoint conversion because Bridge applies model vocab padding separately.

Testing

  • uv run --active --no-sync pre-commit run --all-files
  • uv run --active --no-sync ruff check src/megatron/bridge/training/tokenizers/config.py tests/unit_tests/training/test_model_load_save.py
  • uv run --active --no-sync ruff format --check src/megatron/bridge/training/tokenizers/config.py tests/unit_tests/training/test_model_load_save.py
  • uv run --active --no-sync python -m py_compile src/megatron/bridge/training/tokenizers/config.py tests/unit_tests/training/test_model_load_save.py

Targeted pytest was attempted locally, but this workstation Python environment is missing Transformer Engine, which prevents importing the full megatron.bridge package before the selected test starts.

Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented May 29, 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.

@claude

claude Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Light Code Review

Clean, focused change. The three new fields (make_vocab_size_divisible_by, tensor_model_parallel_size, rank) are required by MCore's build_tokenizer path, and the defaults (1, 1, 0) are neutral — they won't affect existing callers or recipes that don't pass these kwargs.

No bugs, typos, or missing coverage found.

One minor observation: the test at tests/unit_tests/training/test_model_load_save.py:1096 uses Mock(spec=TokenizerConfig), which means hasattr checks will pass for the new dataclass fields. This is correct behavior, but note the mock won't run __post_init__, so the test only verifies the setattr path in load_tokenizer, not the full config initialization. This is fine for the scope of this PR.

Suggested test cases

No perf tests impacted.

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test edfcc3e

@yaoyu-33
yaoyu-33 merged commit b17fd65 into main May 29, 2026
103 checks passed
@yaoyu-33
yaoyu-33 deleted the yuya/nvbug-6232591-tokenizer-config branch May 29, 2026 23:03
@yaoyu-33 yaoyu-33 added area:training Training loop, callbacks, and runtime integration bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer labels May 29, 2026
vasunvidia pushed a commit to vasunvidia/Megatron-Bridge that referenced this pull request Jun 10, 2026
)

Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: Vasudevan Rengasamy <vrengasamy@nvidia.com>

This branch was previously deployed

2 inactive deployments
public — edfcc3ed Deployed May 29, 2026 by copy-pr-bot[bot] via release / finalize / publish-docs #921
test — edfcc3ed Deployed May 29, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #15398
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:training Training loop, callbacks, and runtime integration bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant