Implement QLoRA-style NF4 4-bit quantization of a weight matrix plus a LoRA adapter, verif

SFT, Instruction Tuning & PEFT5 / 6

Chapter 115 / 6

SFT, Instruction Tuning & PEFT

Implement QLoRA-style NF4 4-bit quantization of a weight matrix plus a LoRA adapter, verif

Super-hard

Implement QLoRA-style NF4 4-bit quantization of a weight matrix plus a LoRA adapter, verifying the forward matches fp16++adapter within tolerance.

Target interface
quantize_nf4(W, block=64)

Implement the function/class skeleton in the editor. Any correct approach is accepted.

Hints0 / 2
Reference solution
Your own code stays in the editor.