fix(dist-ckpt): handle bare BytesIO _extra_state in key recovery (TE FP8)#53
Merged
Conversation
…FP8) TE FP8 _extra_state can arrive as a bare io.BytesIO in the state dict, so len(tensors) in _replace_sharded_keys_with_state_dict_keys raises. Wrap it as a single empty uint8 tensor, which makes TE.set_extra_state skip restoring FP8 scaling state instead of crashing checkpoint key recovery.
7f52ebe to
e56a184
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Loading a TransformerEngine FP8 distributed checkpoint crashes in
_replace_sharded_keys_with_state_dict_keys: TE stores_extra_stateas a bareio.BytesIO, which_unwrap_pyt_sharded_tensorreturns unwrapped, soassert len(tensors) == ...raisesTypeError: object of type 'BytesIO' has no len(). (Upstream NVIDIA/Megatron-LM has the same unpatched code — this is a carried fix, not a sync gap.)Fix
When the value is a bare
io.BytesIO, substitute an emptyuint8tensor. TE'sset_extra_statetreats an empty tensor as "no FP8 state to restore" (early return), which is correct for RL training where FP8 is not used.Validation
Routed a realistic BytesIO
_extra_state(torch.save into io.BytesIO) through the exact recovery function:len(BytesIO)→ TypeError reproducedset_extra_state.Fixes radixark/miles#1293