Load target embeddings without full model init#11
Open
zhangxin81 wants to merge 1 commit into
Open
Conversation
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.
Summary
AutoModelForCausalLMduring trainer startup.lm_headweights from HF checkpoints.safetensorscheckpoints, PyTorch.binfallbacks, common Qwen/Gemma key prefixes, and tied embedding checkpoints withoutlm_head.weight.GPU memory impact
Previously, trainer startup instantiated the entire target model only to read
get_input_embeddings()andget_output_embeddings(). In environments where that temporary target model is materialized on CUDA, the peak GPU memory includes the full target checkpoint's BF16 parameter footprint. This PR keeps target checkpoint tensors on CPU and copies only into the already-existing draft embedding/head parameters, so the extra target-model GPU peak is effectively removed.Estimated peak GPU memory avoided per rank for the current training configs:
Notes:
model.safetensors.index.json.metadata.total_sizefor the public HF checkpoints, converted from bytes to GiB.11,959,730,224) × 2 bytes, converted to GiB.embed_tokens/lm_headparameters are unchanged; this only removes the temporary full target model allocation.from_pretrained()fully on CPU, then the GPU saving is smaller, but this still avoids constructing/loading all unneeded target layers and reduces CPU memory/init overhead.Testing
PYTHONPYCACHEPREFIX=/private/tmp/deepspec-pycache python3 -m py_compile deepspec/trainer/base_trainer.py deepspec/trainer/eagle3_trainer.py deepspec/utils/target_weights.pygit diff --check