Skip to content
nonconvexcard

Implement LoRA and measure the spectrum

CodingAdvanced⏱ 3 hoursFine-Tuningloraimplementationspectrumeckart-young

Problem

  1. Implement a LoRA layer wrapping a frozen linear layer, with correct initialisation and α/r\alpha/r scaling, and verify it computes the base function at step 0.
  2. Fine-tune a small model fully, and measure the singular value spectrum of the resulting ΔW\Delta W per layer.
  3. Use Eckart–Young to compute, per layer, the rank needed to capture 90% of ∥ΔW∥F2\|\Delta W\|_F^2.
  4. Train LoRA at that rank and at half of it, and compare against full fine-tuning.

Implement it, then check the implementation against something you can verify independently.

Write it

Solve it here8 tests · Python runs in your browser
⌘/Ctrl + ↵ to run · limit 60s · draft saved in this browser
8 tests will run against your code. The first run downloads the Python runtime — several megabytes, once per browser.

Solution

Opening this before you have a real attempt on paper is the fastest way to feel like you understand something you cannot reproduce.

Related problems

All problems
SolvedProblemFieldTypeDifficultyTime
Adapter parameter countsFine-TuningNumericalFoundation15 min
LoRA parameter accountingLLMsNumericalBeginner15 min
Will this fine-tune fit?Fine-TuningNumericalBeginner30 min
Implement backpropagation from scratch runDeep LearningCodingIntermediate3 hours
Implement kernel ridge regression runClassical MLCodingIntermediate1 hour