-
Notifications
You must be signed in to change notification settings - Fork 338
[fix] Preserve original AutoConfig in MegatronWorker.init_configs #1727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dinhxuanvu
wants to merge
3
commits into
NovaSky-AI:main
Choose a base branch
from
dinhxuanvu:vdinh/fix-megatron-worker-config-mutation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """ | ||
| uv run --isolated --extra dev pytest tests/train/utils/test_update_model_config.py | ||
| """ | ||
|
|
||
| from copy import deepcopy | ||
| from types import SimpleNamespace | ||
|
|
||
| from skyrl.train.utils.utils import update_model_config | ||
|
|
||
|
|
||
| def _make_config(): | ||
| """Build a config-like object with a nested sub-config attribute.""" | ||
| sub = SimpleNamespace(mtp_num_layers=4, hidden_size=128) | ||
| return SimpleNamespace(num_nextn_predict_layers=4, sub_config=sub) | ||
|
|
||
|
|
||
| class TestUpdateModelConfigNonMutating: | ||
| """Lock in the non-mutating contract of ``update_model_config``.""" | ||
|
|
||
| def test_input_is_not_mutated_at_top_level(self): | ||
| cfg = _make_config() | ||
| before = deepcopy(cfg) | ||
| update_model_config(cfg, {"num_nextn_predict_layers": 0}) | ||
| assert cfg.num_nextn_predict_layers == before.num_nextn_predict_layers | ||
| assert cfg.sub_config.mtp_num_layers == before.sub_config.mtp_num_layers | ||
|
|
||
| def test_returned_copy_carries_top_level_overrides(self): | ||
| cfg = _make_config() | ||
| new_cfg = update_model_config(cfg, {"num_nextn_predict_layers": 0}) | ||
| assert new_cfg.num_nextn_predict_layers == 0 | ||
| assert new_cfg is not cfg | ||
|
|
||
| def test_nested_overrides_do_not_leak_back_into_input(self): | ||
| cfg = _make_config() | ||
| new_cfg = update_model_config(cfg, {"sub_config": {"mtp_num_layers": 0}}) | ||
| assert new_cfg.sub_config.mtp_num_layers == 0 | ||
| assert cfg.sub_config.mtp_num_layers == 4 | ||
| assert new_cfg.sub_config is not cfg.sub_config |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation of
_apply_overrides_in_placeassumes thatmodule_configand all its nested attributes are objects supportinggetattrandsetattr. However, many HuggingFace configurations contain standard dictionary attributes (e.g.,rope_scaling,quantization_config). If an override contains a nested dictionary for one of these attributes, callinggetattron it returns adict, and recursing into it will cause anAttributeErrorwhensetattris called on the dictionary keys.Additionally, if
module_configisNoneor if a nested attribute does not exist (returningNone), the function will crash. Enforcing defensive programming with properNonechecks and handling both dictionaries and objects will make this utility much more robust.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Real issue, but pre-existing — the recursive
getattr/setattrpattern is unchanged from the prior in-place version; I only relocated it. The only caller (init_configs) passes scalar overrides, so no observable regression today.Also, the suggested patch conflates "recurse into existing sub-config" with "assign new dict" when
current_val is None. Worth a dedicated PR. Happy to file a follow-up issue.