-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] Activation offloading for distributed lora recipe #1645
[Feat] Activation offloading for distributed lora recipe #1645
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/1645
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 7be67c4 with merge base 4e69db8 (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Hi @Jackmin801! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
While we were working on this PR, we observed a weird behaviour in the trace.
Steps to reproduce1. Clone repo at this branchgit clone --branch feat-activation-offloading-streams-dist git@github.com:Jackmin801/torchtune
cd torchtune 2. Dev Install with torch nightlypip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121
pip install torchao
pip install matplotlib pandas numpy
pip install -e ".[dev]" 3. Login to huggingface and download modelhuggingface-cli login --token <HF_TOKEN> tune download meta-llama/Meta-Llama-3.1-8B-Instruct --output-dir /tmp/Meta-Llama-3.1-8B-Instruct --ignore-patterns "original/*.pth" 4. Run single device#tune run --nnodes 1 --nproc-per-node 2 lora_finetune_distributed --config recipes/configs/llama3_1/8B_lora.yaml \
tune run lora_finetune_single_device --config recipes/configs/llama3_1/8B_lora.yaml \
optimizer_in_bwd=False \
enable_activation_offloading=False \
enable_activation_checkpointing=True \
compile=False \
model.lora_attn_modules="[q_proj,v_proj]" \
model.apply_lora_to_mlp=False \
model.apply_lora_to_output=False \
model.lora_rank=8 \
model.lora_alpha=16 \
dataset.source=Yukang/LongAlpaca-12k \
dataset.packed=False \
dataset.split=train[:10%] \
dataset.train_on_input=True \
tokenizer.max_seq_len=8192 \
metric_logger=torchtune.training.metric_logging.StdoutLogger \
metric_logger.project=recipe_profiling \
log_every_n_steps=1 \
log_peak_memory_stats=True \
gradient_accumulation_steps=1 \
max_steps_per_epoch=4 \
epochs=1 \
batch_size=2 \
metric_logger.name=llama3__qlora__seqlen_8192__act_ckpt_True__act_off_True__bs2 \
profiler.enabled=True \
profiler.profile_memory=True \
profiler.with_stack=True \
profiler.wait_steps=0 \
profiler.warmup_steps=2 \
profiler.active_steps=2 \
profiler.num_cycles=1 5. Observe the traceWeird right? Observations@yf225 figured out that theres a warning from cuDNN sdpa about memory layout that is likely the culprit /data/users/weif/pytorch/torch/autograd/graph.py:826: UserWarning: cuDNN SDPA backward got grad_output.strides() != output.strides(), attempting to materialize a grad_output with matching strides... (Triggered internally at /data/users/weif/pytorch/aten/src/ATen/native/cudnn/MHA.cpp:674.)
return Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass |
662271b
to
7886acc
Compare
ah. will lint haha. wanted to start hacking first |
e0c60b4
to
7be67c4
Compare
Thanks the PR!! Would you be able to run it with activation on and off for ~25-50 steps and compare loss, memory, tps? If you use weights and biases, its probably the easiest way to take a screenshot (you can login with your gmail, get the token, pip install wandb, wandb login, insert your token) then you can run your config like this: Please use dataset.packed=True, compile=True, enable_activation_checkpoint=True, enable_activation_offload=true/false if loss and TPS is about the same, but memory is much lower, this should be easy to approve. |
will get to this tomorrow. Thanks for posting the results! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! Thanks for the PR!
Context
What is the purpose of this PR? Is it to
Please link to any issues this PR addresses.
Changelog
What are the changes made in this PR?
activation_checkpoint
->enable_activation_checkpoint
enable_activation_offloading
and logic to do activation offloadingTest plan
Please make sure to do each of the following if applicable to your PR. If you're unsure about any one of these just ask and we will happily help. We also have a contributing page for some guidance on contributing.
pre-commit install
)pytest tests
pytest tests -m integration_test
UX
If your function changed a public API, please add a dummy example of what the user experience will look like when calling it.
Here is a docstring example
and a tutorial example