[PyTorch] Fix FP8 activation recompute #1254
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The amax reduction of all backward tensors happens in the first module (one of the base modules) in a given
fp8_autocast
. Thectx.reduce_and_update_bwd_fp8_tensors
flag is saved by querying theFP8GlobalStateManager.is_first_fp8_module()
which only returnsTrue
for the first module in thefp8_autocast
. However, this introduces a bug during activation recompute since the recompute phase runs outside the fp8 context, and the first module flags are never set. This results in the amaxes for gradients not getting reduced.Fixes #1190
Type of change
Changes
The
activation_recompute_forward
maintains a queue structure to pass values of theIS_FIRST_FP8_MODULE
flag from the forward phase to the recompute phase. During the recompute phase, it is reset back to not disturb any nested autocasts.Checklist: