TransformerEngine icon indicating copy to clipboard operation
TransformerEngine copied to clipboard

[PyTorch] Bunch of memory management fixes

Open pggPL opened this issue 7 months ago • 8 comments

Description

This PR changes:

  • adds tensor removing after prepare for saving for the internal tensors,
  • cached weight is changed not to be internal tensor - otherwise it would be removed between the microbatches,
  • test that catches the error above,
  • scaling factors are saved for backward - it enables offloading them,
  • enables weight offloading test for MXFP8 - it was disabled because of the problems with the scaling factors offloading.
  • fixes .clear() - removes also scale_inv tensors and works correctly for .*TensorBase

This PR breaks compatibility with the Thunder

Type of change

  • [ ] Documentation change (change only to the documentation, either a fix or a new content)
  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] Infra/Build change
  • [ ] Code refactoring

Checklist:

  • [x] I have read and followed the contributing guidelines
  • [x] The functionality is complete
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes

pggPL avatar Apr 15 '25 09:04 pggPL

/te-ci pytorch

pggPL avatar Apr 15 '25 09:04 pggPL

/te-ci pytorch

pggPL avatar Apr 15 '25 10:04 pggPL

/te-ci pytorch

pggPL avatar Apr 15 '25 12:04 pggPL

/te-ci pytorch

pggPL avatar Apr 22 '25 09:04 pggPL

/te-ci pytorch

ksivaman avatar Apr 24 '25 17:04 ksivaman

@guyueh1 offline confirmed that the NeMo/MCore sanity tests pass with this change, including parallelisms.

ptrendx avatar Apr 25 '25 00:04 ptrendx

/te-ci pytorch

ksivaman avatar Apr 25 '25 02:04 ksivaman

/te-ci pytorch

pggPL avatar Apr 25 '25 13:04 pggPL

/te-ci pytorch

pggPL avatar Apr 29 '25 15:04 pggPL

The Thunder integration bug is fixed with https://github.com/Lightning-AI/lightning-thunder/pull/1826.

timmoon10 avatar May 28 '25 18:05 timmoon10