refactor: migrate TransformerConfig validations to __post_init__ (Part of #3568)#3675
Open
CodersAcademy006 wants to merge 4 commits intoNVIDIA:mainfrom
Open
Conversation
Part of NVIDIA#3568. Moves two pure-validation assertions from validate_args() in arguments.py into TransformerConfig.__post_init__() for co-location, automatic enforcement at config-construction time, and unit testability. Migrated validations: - hidden_size % num_attention_heads == 0 (guarded inside kv_channels derivation) - num_moe_experts % expert_model_parallel_size == 0 (was entirely missing from TransformerConfig; only existed in validate_args) Both asserts are retained in validate_args for legacy model paths that bypass TransformerConfig construction entirely. Adds 11 unit tests: tests/unit_tests/test_transformer_config_validation.py
Contributor
Author
|
@maanug-nv Hey, can you please take a look at this, thank you. Please provide me suggestions on what can be better. |
Member
|
/claude review |
|
|
||
| Part of #3568: moves pure-validation assertions from validate_args() in | ||
| arguments.py into TransformerConfig so they fire at config-construction time | ||
| and can be exercised without a full training process. |
There was a problem hiding this comment.
The comment says "moves pure-validation assertions from validate_args()", but the original assert checks in arguments.py are still present:
arguments.py:1049—assert args.hidden_size % args.num_attention_heads == 0arguments.py:1263–1266—assert args.num_experts % args.expert_model_parallel_size == 0
If this PR is intentionally only the "add to __post_init__" half of the migration (with a follow-up to remove from arguments.py), the docstring here should say "adds" or "copies" rather than "moves" to avoid confusion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Partial resolution of #3568. Migrates two pure-validation assertions from
validate_args()intoTransformerConfig.__post_init__()for co-location, automatic enforcement at config-construction time, and unit testability.What Changed
hidden_size % num_attention_heads == 0check inside thekv_channelsderivation block inTransformerConfig.__post_init__num_moe_experts % expert_model_parallel_size == 0check inside a consolidatedif expert_model_parallel_size > 1block inTransformerConfig.__post_init__(this check was entirely absent from the config class before — only existed invalidate_args)validate_args()for legacy model paths with an explanatory commenttests/unit_tests/test_transformer_config_validation.pyWhat Is NOT in This PR
ConfigContainercross-config validations (pending pattern discussion)validate_args()— intentionally left in placeTesting
Notes
Some entries in
validate_args()mutate args conditionally rather than purely validating — those are not touched as they require afinalize()pattern discussion before migration.Closes #3568 (partial)