Conversation
Fixes hpcaitech#6253. `detach()` and `clone()` of a padded tensor copy the padding metadata to the new tensor but do not hijack its own `detach`/`clone`, so the copy looks like a padded tensor to `is_padded_tensor` while `to_unpadded_tensor` fails on it with AttributeError: 'Tensor' object has no attribute '_unpad_detach' `HybridParallelCheckpointIO` always saves `param.detach()`, so `booster.save_model` crashes with `HybridParallelPlugin(tp_size=1)` (any `pp_size`, sharded or not) for every model whose vocab size is not a multiple of `make_vocab_size_divisible_by`, e.g. GPT-2 (50257) or OPT, whose embedding and lm_head are wrapped in `PaddingEmbedding` / `PaddingLMHead`. With `tp_size > 1` the parameter is a distributed tensor and takes a different path, which is why the existing checkpoint tests (LLaMA, vocab 32000) never hit it. Make the copies full padded tensors. Add a unit test for detach/clone + unpad, and a HybridParallelPlugin save/load round trip with a padded vocab (tp=1 with pp=1 and pp=2, sharded and unsharded) that also checks the checkpoint holds the unpadded vocab size.
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.
📌 Checklist before creating the PR
[doc/gemini/tensor/...]: A concise descriptionpip install pre-commit && pre-commit install(ran the pinned hooks manually instead: black 24.10.0--line-length=120, isort 5.13.2--profile black, autoflake 2.3.1, all clean)🚨 Issue number
fixed #6253
📝 What does this PR do?
booster.save_modelwithHybridParallelPlugin(tp_size=1)crashes for any model whose vocab size is not a multiple ofmake_vocab_size_divisible_by(64), e.g. GPT-2 (50257), sharded or not, with or without pipeline parallelism:Cause. With
tp_size=1the embedding / lm_head weights are padded tensors (PaddingEmbedding/PaddingLMHead).detach()andclone()of a padded tensor copy the padding metadata to the new tensor but do not hijack the new tensor's owndetach/clone. The copy therefore looks like a padded tensor tois_padded_tensor, butto_unpadded_tensorfails on it because_hijack_back_detach_and_clonelooks for_unpad_detach.HybridParallelCheckpointIO._model_sharderalways unpadsparam.detach(), so every save hits this.With
tp_size > 1the parameter is a distributed tensor and takes a different path, which is why the existing checkpoint tests (LLaMA, vocab 32000, a multiple of 64) never hit it.Fix. Hijack
detach/cloneof the copies too, so they are complete padded tensors.Tests.
test_padded_tensor.py:detach(),clone()anddetach().clone()of a padded tensor can be unpadded and give the original values.test_hybrid_parallel_plugin_checkpoint_io.py: save/load round trip of a GPT-2 with vocab 1000 fortp=1, pp=1andtp=1, pp=2, sharded and unsharded, also checking that the checkpoint holds the unpadded vocab size.Results (4x H200, torch 2.5.1+cu124)
AttributeError: '_unpad_detach'save_model, GPT-2 vocab 1000, tp=1 pp=1 / tp=1 pp=2, sharded and unshardedtest_padded_tensor(4 GPUs),exam_state_dictin the hybrid checkpoint test withuse_async=FalseThe
use_async=Trueparametrizations were not run:tensornvmedoes not build on my machine.💥 Checklist before requesting a review
⭐️ Do you enjoy contributing to Colossal-AI?