Skip to content

Hpc setup #1004

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adding optional env config for hpc
Optional adds to the toml files for running in environments that uses non-torchrun launchers.
  • Loading branch information
githubsgi committed Mar 22, 2025
commit a91bbc27ad1599cb30514f6af8eb425deb3ce8ed
17 changes: 17 additions & 0 deletions torchtitan/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,20 @@ def __init__(self):
help="The minimum number of FT replica for each step.",
)

# hpc , slurm etc settings
self.parser.add_argument(
"--hpc.rank_var",
type=str,
default=None,
help="The enviroment var set by launcher ( e.g. mpirun, mpiexec, ect.) for rank.",
)
self.parser.add_argument(
"--hpc.local_rank_var",
type=str,
default=None,
help="The enviroment var set by launcher ( e.g. mpirun, mpiexec, ect.) for local rank.",
)

self.parser.add_argument(
"--experimental.custom_import",
type=str,
Expand Down Expand Up @@ -807,6 +821,9 @@ def maybe_add_custom_args(self) -> None:
]
func = getattr(module, public_functions[0])
func(self.parser)
)



def to_dict(self):
return self.args_dict
Expand Down
8 changes: 8 additions & 0 deletions torchtitan/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
maybe_enable_profiling,
)

def hpc_setup(job_config: JobConfig):
if job_config.hpc.rank_var:
os.environ['RANK'] = os.getenv(job_config.hpc.rank_var)
if job_config.hpc.local_rank_var:
os.environ['LOCAL_RANK'] = os.getenv(job_config.hpc.local_rank_var)


class Trainer(torch.distributed.checkpoint.stateful.Stateful):
job_config: JobConfig
Expand Down Expand Up @@ -463,6 +469,8 @@ def close(self) -> None:
config = JobConfig()
config.maybe_add_custom_args()
config.parse_args()
hpc_setup(config)

trainer: Optional[Trainer] = None

try:
Expand Down