Skip to content

Add QLoRA and FP8 to finetuning tutorial (part 2) #2542

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

Merged
merged 1 commit into from
Jul 15, 2025

Conversation

andrewor14
Copy link
Contributor

This is part 2 of the end-to-end tutorial. Previously we already had QAT. This commit also adds QLoRA and FP8. To preview, visit https://docs-preview.pytorch.org/pytorch/ao/2542/finetuning.html

Copy link

pytorch-bot bot commented Jul 14, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/2542

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 5 Pending

As of commit e6c8194 with merge base 2e2ce0b (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 14, 2025
@andrewor14 andrewor14 added the topic: documentation Use this tag if this PR adds or improves documentation label Jul 14, 2025
@andrewor14 andrewor14 requested review from drisspg and jerryzh168 July 14, 2025 23:18
self.weight.requires_grad_(False)
if self.bias is not None:
self.bias.requires_grad_(False)
nf4_weight = to_nf4(self.weight, **quantization_kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we extend this to support any quantization? I just added a AOBaseTensorConfig that might be able to help: #2463

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll add a note to say it's possible to extend to other quantization, but want to keep this example NF4 since that's what's used in the QLoRA paper


.. code::

tune run lora_finetune_single_device --config llama3_2/3B_qlora_single_device.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about integration with the transformer peft library?

also isn't tune deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow I didn't realize we had an integration with peft, don't think this was documented in any of our docs? Will add a note here

For torchtune I don't think there's a mature replacement yet from pytorch so I feel it's OK. Also that's where most of our fine-tuning integrations live today

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, thanks!

@andrewor14 andrewor14 force-pushed the finetuning-tutorial-part2 branch from 6ccc6b1 to d04acdd Compare July 15, 2025 19:13
This is part 2 of the end-to-end tutorial. Previously we already
had QAT. This commit also adds QLoRA and FP8. To preview, visit
https://docs-preview.pytorch.org/pytorch/ao/2542/finetuning.html
@andrewor14 andrewor14 force-pushed the finetuning-tutorial-part2 branch from d04acdd to e6c8194 Compare July 15, 2025 19:17
@andrewor14 andrewor14 merged commit 975bd57 into main Jul 15, 2025
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: documentation Use this tag if this PR adds or improves documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants