torchtune icon indicating copy to clipboard operation
torchtune copied to clipboard

Set expandable_segments explicitly via cuda memory API

Open mirceamironenco opened this issue 5 months ago • 1 comments

Context

What is the purpose of this PR? Is it to

  • [x] add a new feature
  • [x] 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?

  • This PR modifies the way torchtune by default sets expandable_segments to True for the CUDA allocator, making it more robust to the order in which torch and torchtune are imported.
  • I've added an explicit check to allow the user to deactivate this option if they desire, i.e. by adding expandable_segments:False to the PYTORCH_CUDA_ALLOC_CONF environment variable.
  • This setting was similarly turned on in tests/__init__.py but it's unclear to me if this is necessary anymore. I can re-add this if tests are failing due to memory issues.

Note that if torchtune adds e.g. weight syncing via CUDA IPC it will be necessary to add a decorator that turns this off and on again since IPC for expandable segment tensors is not yet implemented in torch IIUC.

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.

  • [x] 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
  • [x] 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

  • [x] I did not change any public API
  • [ ] I have added an example to docs or docstrings

mirceamironenco avatar Jul 14 '25 16:07 mirceamironenco

:link: Helpful Links

:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/2881

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

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

pytorch-bot[bot] avatar Jul 14 '25 16:07 pytorch-bot[bot]