Update fp8_meta amax when copying into Float8Tensor #567
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.
While debugging a convergence issue with LLaMa SFT and NVIDIA/NeMo#7909, I've identified a subtle bug when a model with FP8 params loads a checkpoint. When the model is first initialized, it generates random weights and stores the amax value in
fp8_meta
. However, this amax becomes meaningless when we load the checkpoint and overwrite the weight values. The amax histories are used in the forward pass to update the scaling factors, resulting in bogus scaling factors that clip many FP8 values to the maxval or underflow them to zero.This PR changes the behavior of copying into a
Float8Tensor
so that it updates the latest amax history if it has anfp8_meta
. This is similar to how the FP8 cast kernel updates the latest amax history. This should fix the issue I'm seeing with LLaMa SFT, but it's not an entirely clean solution. In particular, it can't protect the user from abusingfp8_meta
(e.g. loading a checkpoint in the middle of training will result in a bogus amax history, with or withoutFloat8Tensor
). It might also result in unexpected amax updates when multiple tensors share the samefp8_meta
, e.g. copying into a tensor subview will affect the full tensor's amax history.