Set expandable_segments explicitly via cuda memory API
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_segmentstoTruefor 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:Falseto thePYTORCH_CUDA_ALLOC_CONFenvironment variable. - This setting was similarly turned on in
tests/__init__.pybut 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
:link: Helpful Links
:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/2881
- :page_facing_up: Preview Python docs built from this PR
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.