rl-alignment-lora-low-rank-adapters built LoRA's forward and backward passes, this question quantifies exactly WHY anyone would bother: how many fewer parameters LoRA actually trains compared to a full fine-tune of the same layer, and, a second, often-overlooked source of savings: how much less optimizer memory that translates into, since a frozen parameter needs no optimizer state at all.
Implement full_finetune_parameter_count, lora_parameter_count, optimizer_state_bytes, and compare_full_finetune_vs_lora, bundling all four numbers together for a single layer.
full_finetune_parameter_count(in_features, out_features) returns in_features * out_features + out_features (weight matrix plus bias).lora_parameter_count(in_features, out_features, rank) returns rank * in_features + out_features * rank.optimizer_state_bytes(num_trainable_params) returns num_trainable_params * 8: Adam's fp32 momentum plus fp32 variance, 4 bytes each, PER TRAINABLE parameter only.compare_full_finetune_vs_lora bundles both parameter counts and both optimizer-memory figures, plus their ratio, into one dict.Open one at a time. Each gives away a little more than the last.
Optimizer state is only ever computed for TRAINABLE parameters: a full fine-tune's optimizer memory scales with full_finetune_parameter_count, while LoRA's scales with the much smaller lora_parameter_count, since the frozen base weight needs zero bytes of optimizer state, not just zero gradient computation.
compare_full_finetune_vs_lora doesn't need any new math beyond calling the three other functions with the right arguments and packaging the results: the interesting part is just seeing all four numbers side by side.
No results yet
Run your code to check it against the examples, or submit to run every test.