Add tutorial: DP fine-tuning of causal LMs with LoRA#830
Open
immu4989 wants to merge 1 commit into
Open
Conversation
Step-by-step tutorial covering GPT-2 + LoRA + opacus on E2E NLG. Compares non-DP LoRA baseline against DP LoRA at target epsilon=8 and reports BLEU, perplexity, peak GPU memory, throughput, and final epsilon. Includes a dedicated section on the three device-placement and training-mode ordering patterns that prevent silent corruption (the bug surfaced and root-caused in meta-pytorch#820). Notebook is fully executed; cell outputs are embedded. Closes meta-pytorch#827
|
This pull request has been imported. If you are a Meta employee, you can view this in D109661283. (Because this pull request was imported automatically, there will not be any future comments.) |
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.
Types of changes
Motivation and Context / Related issue
Closes #827.
Opacus has one LoRA tutorial today (
tutorials/building_text_classifier.ipynb), covering BERT for sequence classification. There's no tutorial for the more common contemporary case: causal language model fine-tuning with DP-SGD + LoRA. This PR adds that astutorials/building_dp_lora_for_llms.ipynb.The tutorial also bakes in the silent-corruption avoidance pattern surfaced and root-caused in #820. Three independent confirmations across CPU, Kaggle T4, and RTX 5090 settled it as a device-placement ordering issue (
model.to(device)beforeget_peft_model()). The tutorial demonstrates the safe ordering explicitly with inline rationale and links back to #820.What's in the tutorial
model.to(device)beforeget_peft_model()(Silent corrupted LoRA weight updates with Opacus 1.5.4 + PEFT 0.18.x: training appears normal but models are unusable #820 ordering)model.train()beforemake_private_with_epsilon(validator requirement)poisson_sampling=False(avoids GPT-2 forward-pass failure on empty Poisson batches)Canonical results on Kaggle T4 (embedded in the notebook)
DP costs about 26% relative BLEU at epsilon ~= 7 on this task, with about 22% memory overhead and negligible throughput impact.
What's intentionally out of scope
DP-full fine-tuning of GPT-2 with all 125M parameters trainable. Attempted via
opacus.validators.ModuleValidator.fix()(Conv1D -> Linear swap) plusgrad_sample_mode='functorch'; neither resolved a per-sample-gradient shape mismatch inclip_and_accumulatethat appears to stem from GPT-2's tiedwte/lm_headweights. The notebook's section 16 documents a recommended engineering recipe for a follow-up PR (untie weights, then re-apply fix and functorch). Felt cleaner to ship the LoRA portion as scoped here than to block on the DP-full work.How Has This Been Tested
End-to-end run on Kaggle T4 with pinned versions:
opacus 1.6.0peft 0.18.1transformers 5.0.0torch 2.10.0+cu128Cell outputs in the committed notebook reflect the actual run. The three safety patterns each addressed a real failure mode encountered during development.
Checklist