Skip to content

Add custom section support to SFT TOML configuration#57

Open
main-voice wants to merge 4 commits into
NVIDIA:mainfrom
main-voice:feat/support-custom-config-fields
Open

Add custom section support to SFT TOML configuration#57
main-voice wants to merge 4 commits into
NVIDIA:mainfrom
main-voice:feat/support-custom-config-fields

Conversation

@main-voice

Copy link
Copy Markdown

No description provided.

Signed-off-by: Alex Peng <haopeng@nvidia.com>

# Import lazily so this module stays cheap to import in non-training contexts.
from cosmos_framework.utils.config import load_config
import importlib

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.

Should we directly load the config from module file by default? I think the original load_config will handle all cases: yaml, py?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agree with one entrypoint. But the interpolation requirement for ${custom} mandates that custom be injected into the tree prior to the resolution step within override(). To accommodate this, a pre_override hook has been added to load_config to enable this logic.

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.

dataloader_train: object = None


class TestCustomInterpolationAndAccess:

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.

The test here could put into cosmos_framework/ and make this test in the same format with the other *test.py in cosmos_framework/ such as inference/prompt_upsampling_test.py? to make sure the unittest job in the current ci tests could automatically grep and run it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good call, thanks to clarify the tests structure

Updated the `load_experiment_from_toml` function to utilize `load_config` with a `pre_override` hook for injecting the `[custom]` section into the config before applying overrides. This ensures that custom configurations are part of the OmegaConf tree resolved by Hydra. Additionally, modified the `load_config` and `_load_py_config` functions to accept the `pre_override` parameter for enhanced configurability.

Documentation for SFT configuration has been updated to reflect these changes.
Signed-off-by: Alex Peng <haopeng@nvidia.com>
@main-voice main-voice marked this pull request as ready for review June 25, 2026 08:01
@foreverlms foreverlms requested a review from yy-code-nv June 25, 2026 08:40
data_setting: DataSetting = attrs.field(factory=DataSetting)
# Free-form, project-owned escape hatch fed by the SFT TOML's [custom] section.
# Default-empty so ${custom} interpolation and config.custom always resolve.
custom: dict = attrs.field(factory=dict)

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.

For those two hydra configs, we prefer not changing anything here. Can you do it in this way:

  • Only Add custom in sft_config
  • pop custom_dict after load toml
  • load_config in old way to get hydra config
  • Using setattr(config, 'custom', custom_dict) to inject custom into hydra config

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.

4 participants