Skip to content

[PoC] Typed JobConfig - #767

Merged
tianyu-l merged 15 commits into
pytorch:mainfrom
jfncs:jfrancis/nightly
Apr 19, 2025
Merged

tianyu-l merged 15 commits into
pytorch:mainfrom
jfncs:jfrancis/nightly

Conversation

@jfncs

@jfncs jfncs commented Jan 1, 2025

Copy link
Copy Markdown
Contributor

Incase theres any interest for type hinting of config args, at the expense of an added dependency (tyro).

Re; #753

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 1, 2025
@jfncs
jfncs marked this pull request as ready for review January 4, 2025 00:31
@jfncs

jfncs commented Jan 14, 2025

Copy link
Copy Markdown
Contributor Author
  1. Fixes the following parsing issues

# TODO: store_true & default=True make impossible for cmd to set it to False

# without this special case, type inference breaks here,
# since the inferred type is just 'list' and it ends up flattening
# e.g. from ["layers.0", "layers.1"] into ["l", "a", "y", "e", "r", "s", ".0", ...]
aux_parser.add_argument("--" + arg, type=string_list)

# toml has no split points, but cmdline splits are specified

  1. Typing LSP support: image

  2. Fuzzy matching

image

@jfncs

jfncs commented Apr 16, 2025

Copy link
Copy Markdown
Contributor Author

FYI @tianyu-l – will begin to rebase w/ latests here. Lmk if anything else comes to mind

Will also look into ways to support custom args and extension w/ tyro (as introduced via 048f65d)

cc: @brentyi

@jfncs
jfncs force-pushed the jfrancis/nightly branch from 141a0b4 to fc9b25b Compare April 18, 2025 01:50
@jfncs
jfncs marked this pull request as ready for review April 18, 2025 01:52
@jfncs

jfncs commented Apr 18, 2025 •

Copy link
Copy Markdown
Contributor Author

hi @tianyu-l, ready for review

custom_args implementation changed, not sure if it's what we want, but was one way I it got to work.

class ExtendedConfig:
"""
This is an example of how to extend the tyro parser with custom config classes.
"""
custom_args: CustomArgs = field(default_factory=CustomArgs)
custom_args_two: CustomArgsTwo = field(default_factory=CustomArgsTwo)

@brentyi brentyi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

left some minor notes! torchtitan/docs/extension.md also looks like it would need to be updated

Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks reasonable after the first pass.
I left many comments, lol.

Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread tests/assets/argparser_example.py Resolved
Comment thread torchtitan/config_manager.py Outdated
def parse_args(self, args=None) -> None:
if args is None:
args = sys.argv[1:]
config_cls = self.maybe_add_custom_args(args)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd like to be a bit careful here.
Before this PR, we support custom_args_module even if it's only given from the .toml file.
It seems to me that in this PR, it only supports custom_args_module from cmdline input.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added a test to confirm custom args parse from .toml file is okay --

however, reading comma separated string via toml loader not working

"converters": ["float8", "mxfp"]
# "converters": "float8,mxfp" # does not work

@fegin fegin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given that the dataclasses merge allow users to overwrite (not just extend) the existing fields, we should document the expected behaviors.

Comment thread torchtitan/config_manager.py Resolved
Comment thread tests/assets/argparser_example.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks really good.

I have two more requests:

  1. can we support custom_args_module even if it's only given in toml file
  2. could you do a global audit (at least for train.py file, llama3 folder, llama4 folder) and modify the callsites: (1) ConfigManager + JobConfig - maybe_add_custom_args() (2) in toml files, turn list[str] args from "single str with comma" to "list of strings".

Comment thread tests/assets/argparser_example.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread tests/unit_tests/test_job_config.py Outdated
config = config_manager.parse_args(
[
f"--job.config_file={fp.name}",
f"--experimental.custom_args_module={path}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what I meant was:
Before this PR, even if we don't specify this line, the custom_args_module in toml would be imported. Can we still support this use case, presumably with some inefficiency?

Comment thread docs/extension.md Resolved
@jfncs
jfncs force-pushed the jfrancis/nightly branch from d224068 to e461c11 Compare April 18, 2025 23:11

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me! I believe this is a great improvement to the configuration system in torchtitan, in terms of user experience, readability, typing, and extensibility. Thank you for the solid work!

Please address remaining nits before we merge.

Comment thread docs/extension.md Resolved
Comment thread torchtitan/config_manager.py Resolved
Comment thread torchtitan/config_manager.py Resolved
class MyJobConfig:
checkpoint: Checkpoint = field(default_factory=Checkpoint)

MergedJobConfig = ConfigManager._merge_configs(JobConfig, MyJobConfig)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This use case may indicate _merge_configs could be made public. I think we can do it later once it is more "popular".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

agree, these two scripts under llama4/ were the only instances of such

@jfncs
jfncs force-pushed the jfrancis/nightly branch from 384beea to 2449037 Compare April 19, 2025 02:43
@tianyu-l
tianyu-l merged commit c1c2f55 into pytorch:main Apr 19, 2025
tianyu-l added a commit that referenced this pull request Apr 19, 2025
a followup fix of #767
should be safe to land
@lkhphuc

lkhphuc commented Apr 19, 2025

Copy link
Copy Markdown
Contributor

Amazing works. This is such a nice improvement. I've been wanting something like this for awhile. I can close #1059 now. Thanks everyone.

@tianyu-l tianyu-l linked an issue Apr 19, 2025 that may be closed by this pull request
@jfncs
jfncs deleted the jfrancis/nightly branch April 19, 2025 21:48
wwwjn added a commit that referenced this pull request Apr 29, 2025
…n layer shape issue (#1153)

## What changed?
1. Refactor Flux arg parser to follow #767 new argparse practice
2. Explicitly change dtype for flux model to avoid #1137 (when FSDP is
not enabled)
3. Fix txt_in layer shape issue by changing the config of schnell and
dev model #1146


## dtype management in Flux Training 

Without FSDP (fsdp dim = 1) :
- Encoder's dtype = float32, Flux model's dtype = float32

With FSDP enabled:
- Encoder's dtype = bfloat16, Text and Image encodings' dtype=bfloat16
- Flux Model's dtype: sharded params are in fp32, reduce-scatter is in
fp32, so gradient updates happen in fp32. dtype when
calculation=bfloat16

cc @CarlosGomes98
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
Incase theres any interest for type hinting of config args, at the
expense of an added dependency (`tyro`).

Re; pytorch#753

---------

Co-authored-by: Jayson Francis <[email protected]>
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
a followup fix of pytorch#767
should be safe to land
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
…n layer shape issue (pytorch#1153)

## What changed?
1. Refactor Flux arg parser to follow pytorch#767 new argparse practice
2. Explicitly change dtype for flux model to avoid pytorch#1137 (when FSDP is
not enabled)
3. Fix txt_in layer shape issue by changing the config of schnell and
dev model pytorch#1146


## dtype management in Flux Training 

Without FSDP (fsdp dim = 1) :
- Encoder's dtype = float32, Flux model's dtype = float32

With FSDP enabled:
- Encoder's dtype = bfloat16, Text and Image encodings' dtype=bfloat16
- Flux Model's dtype: sharded params are in fp32, reduce-scatter is in
fp32, so gradient updates happen in fp32. dtype when
calculation=bfloat16

cc @CarlosGomes98
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
Incase theres any interest for type hinting of config args, at the
expense of an added dependency (`tyro`).

Re; pytorch#753

---------

Co-authored-by: Jayson Francis <[email protected]>
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
a followup fix of pytorch#767
should be safe to land
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
…n layer shape issue (pytorch#1153)

## What changed?
1. Refactor Flux arg parser to follow pytorch#767 new argparse practice
2. Explicitly change dtype for flux model to avoid pytorch#1137 (when FSDP is
not enabled)
3. Fix txt_in layer shape issue by changing the config of schnell and
dev model pytorch#1146


## dtype management in Flux Training 

Without FSDP (fsdp dim = 1) :
- Encoder's dtype = float32, Flux model's dtype = float32

With FSDP enabled:
- Encoder's dtype = bfloat16, Text and Image encodings' dtype=bfloat16
- Flux Model's dtype: sharded params are in fp32, reduce-scatter is in
fp32, so gradient updates happen in fp32. dtype when
calculation=bfloat16

cc @CarlosGomes98
drisspg added a commit that referenced this pull request Nov 12, 2026
attn-gym 0.0.20 changes chunk_kda BF16 bits (meta-pytorch/attention-gym#764,
#767), so kimi_k3_mm_muon no longer matches the old reference. The new
values are from this branch's B200 run:
https://github.com/pytorch/torchtitan/actions/runs/43270645434
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JobConfig does not support typing

7 participants