Skip to content

Conversation

mirceamironenco
Copy link
Contributor

Context

What is the purpose of this PR? Is it to

  • add a new feature
  • fix a bug
  • update tests and/or documentation
  • other (please add here)

Please link to any issues this PR addresses.

Changelog

What are the changes made in this PR?

  • Currently the torchtune CLI acts as a wrapper around the torch.distributed/torchrun launcher when running distributed recipes. However because run is called directly users might have trouble tracing multiprocessing errors. This PR adds the record decorator (see https://pytorch.org/docs/stable/elastic/errors.html) to the entry point of a distributed run (another location where this could be added is the recipe entrypoint, however the current choice allows the recipe writer to not have to worry about it).

Since we are wrapping torchrun I haven't added an explicit test. One should be able to validate this works for example by running any distributed recipe and just killing it before it completes (keyboard interrupt, etc), e.g. assuming files are already downloaded:

TORCH_ELASTIC_ERROR_FILE=./error_log.txt
tune run --nnodes 1 --nproc_per_node 2 lora_finetune_distributed --config llama2/7B_lora

Now error_log.txt should show something like (truncated for brevity):

{"message": {"message": "SignalException: Process 20453 got signal: 2", "extraInfo": {"pycallstack": "Traceback (most recent call last):\n  File "/opt/conda/lib/python3.11/site-packages/torch/distributed/elastic/multiprocessing/errors/__init.py", line 348, in wrapper\n    return f(args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^\n  File "/root/torchtune/torchtune/_cli/run.py", line 91, in rundistributed\n    run(args)\n  File "/opt/conda/lib/python3.11/site-packages/torch/distributed/run.py", line 892, in run\n    elastic_launch(\n  File "/opt/conda/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 133, in __call\n    return launch_agent(self._config, self._entrypoint, list(args))\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/opt/conda/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 255, in launch_agent\n    result = agent.run()\n             ^^^^^^^^^^^\n  File "/opt/conda/lib/python3.11/site-packages/torch/distributed/elastic/metrics/api.py", line 124, in wrapper\n    result = f(args, **kwargs)\n             ^^^^^^^^^^^^^^^^^^\n  File "/opt/conda/lib/python3.11/site-packages/torch/distributed/elastic/agent/server/api.py", line 680, in run\n    result = self._invoke_run(role)\n             ^^^^^^^^^^^^^^^^^^^^^^\n  File "/opt/conda/lib/python3.11/site-packages/torch/distributed/elastic/agent/server/api.py", line 835, in _invoke_run

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
  • I have added an example to docs or docstrings

Copy link

pytorch-bot bot commented Sep 30, 2024

🔗 Helpful Links

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

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:

✅ No Failures

As of commit d71764a with merge base 3fddc56 (image):
💚 Looks good so far! There are no failures yet. 💚

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 Sep 30, 2024
Copy link
Collaborator

@RdoubleA RdoubleA left a comment

Choose a reason for hiding this comment

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

Thanks for improving our debuggability! LGTM

@RdoubleA RdoubleA merged commit 3c450ef into pytorch:main Sep 30, 2024
17 checks passed
@mirceamironenco mirceamironenco deleted the add-distrib-error-record branch September 30, 2024 19:51
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.

3 participants