Skip to content

Log config only on rank zero at torchtune/recipes/full_finetune_distributed.py #2711

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

Conversation

kabir2505
Copy link

Context

What is the purpose of this PR? Is it to

  • fix a bug
    This PR ensures that log_config is only called on rank zero in distributed runs to avoid redundant logging across devices.

Address: #2700

Please link to any issues this PR addresses.

Changelog

What are the changes made in this PR?
- Added a rank check to only log config on rank zero

Test plan

Please make sure to do each of the following if applicable to your PR. If you're unsure about any one of these just ask and we will happily help. We also have a contributing page for some guidance on contributing.

  • run pre-commit hooks and linters (make sure you've first installed via pre-commit install)
  • add unit tests for any new functionality
  • update docstrings for any new or updated methods or classes
  • run unit tests via pytest tests
  • run recipe tests via pytest tests -m integration_test
  • manually run any new or modified recipes with sufficient proof of correctness
  • include relevant commands and any other artifacts in this summary (pastes of loss curves, eval results, etc.)

UX

If your function changed a public API, please add a dummy example of what the user experience will look like when calling it.
Here is a docstring example
and a tutorial example

  • I did not change any public API

Copy link

pytorch-bot bot commented May 9, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/2711

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure

As of commit dbab003 with merge base 3310946 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 9, 2025
@@ -1056,7 +1057,9 @@ def recipe_main(cfg: DictConfig) -> None:
- Parameters specified in config (see available configs through ``tune ls``)
- Overwritten by arguments from the command-line
"""
config.log_config(recipe_name="FullFinetuneRecipeDistributed", cfg=cfg)
if torch.distributed.get_rank() == 0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we move this inside the recipe's setup and use if self._is_rank_zero?

Copy link
Contributor

@ebsmothers ebsmothers left a comment

Choose a reason for hiding this comment

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

@kabir2505
Copy link
Author

Hey @SalmanMohammadi @ebsmothers — just to confirm, should config.log_config() be moved to setup()?

@joecummings
Copy link
Contributor

Hey @SalmanMohammadi @ebsmothers — just to confirm, should config.log_config() be moved to setup()?

Correct!

Copy link
Contributor

@joecummings joecummings left a comment

Choose a reason for hiding this comment

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

Couple comments, but looking good

@@ -13,6 +13,7 @@
from warnings import warn

import torch
import torch.distributed
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this for?

@@ -287,9 +287,9 @@ def setup(self, cfg: DictConfig) -> None:
"""
if self._is_rank_zero:
self._metric_logger = config.instantiate(cfg.metric_logger)

# log config with parameter override
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this still needs to log config here. The naming is bad, but one logs it to the metric logger (meaning it's saved into the WandB or Tensorboard run), and the other just prints it to disk

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 Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants