LoRA parameter counter
LoRA fine-tunes a model without touching its weights. For each matrix you choose to adapt, it freezes the original and learns two thin matrices whose product is the update. Only those thin matrices are trained and saved, so the adapter is a small fraction of the model.
Rank 16 on 4 module types trains 13.6M parameters, saved as a 27.3 MB bf16 file.
Inputs
8B parameters as published; 32 layers, hidden size 4,096.
The update is scaled by alpha / r = 2.
| Module | Shape (in × out) | Per layer | All layers |
|---|---|---|---|
| Query (q_proj) | 4,096 × 4,096 | 131,072 | 4,194,304 |
| Key (k_proj) | 4,096 × 1,024 | 81,920 | 2,621,440 |
| Value (v_proj) | 4,096 × 1,024 | 81,920 | 2,621,440 |
| Output (o_proj) | 4,096 × 4,096 | 131,072 | 4,194,304 |
| Rank | Trainable | Share of base | File size |
|---|---|---|---|
| 4 | 3.41M | 0.043% | 6.8 MB |
| 8 | 6.82M | 0.085% | 13.6 MB |
| 16 (yours) | 13.6M | 0.17% | 27.3 MB |
| 32 | 27.3M | 0.341% | 54.5 MB |
| 64 | 54.5M | 0.682% | 109.1 MB |
| 128 | 109M | 1.363% | 218.1 MB |
What it shows
A matrix that maps d_in values to d_out values gets r × (d_in + d_out) adapter parameters at rank r. That sum depends on the real shapes: with grouped-query attention the key and value projections are narrower than the query projection, and the three MLP matrices use the intermediate size, not the hidden size.
This counter uses the shapes of real dense models and adds up the modules you tick across every layer. It converts the result into a share of the base model, an adapter file size and the optimiser memory you avoid compared with training every weight with Adam.
How to read it
- “Trainable parameters” is the total across all layers for the ticked modules. The per-module table shows each matrix’s shape and count.
- “Share of the base model” divides by the published parameter count, which models round to one decimal. Expect the percentage to be right to about that precision.
- “Scale” is alpha divided by rank. LoRA multiplies the learned update by it, so doubling the rank at a fixed alpha halves the scale.
- “Adam states saved” compares 8 bytes per parameter for Adam’s two fp32 moments on the full model with the adapter alone. It leaves out gradients, master weights and activations.
- The rank table keeps your modules and shows how the adapter grows from rank 4 to 128, with your rank marked.
Questions
What do rank and alpha control?
Rank r is the width of the thin matrices, so it sets capacity and the parameter count: doubling it doubles the adapter. Alpha sets the scale alpha / r applied to the learned update. Many recipes fix alpha and vary rank, which changes the effective step size as well as capacity, so retune the learning rate when you change either.
Which modules should I adapt?
The LoRA paper adapted only the query and value matrices in its main experiments. Many fine-tuning recipes since adapt every linear layer, which costs several times more parameters. There is no universal answer; compare on your own task.
Does LoRA reduce activation memory?
No. The forward and backward passes still run through the full frozen model, so activations are about the same. LoRA saves the gradients and optimiser states for the frozen weights. QLoRA also quantises the frozen weights, which this counter does not model.
Does the adapter slow down inference?
Not if you merge it. The learned update can be added into the frozen weights once, after training, which leaves the model the same shape and speed as the original. Keeping adapters separate lets you swap them at a small extra cost.
Why are mixture-of-experts models missing?
The presets cover dense models whose projection shapes are published. Expert layers and fused projections need different counting rules. Use the custom model option for any dense shape you know.
Sources
- Hu et al. (2021). LoRA: low-rank adaptation of large language models.
- Ainslie et al. (2023). GQA: training generalized multi-query transformer models from multi-head checkpoints.
- Dubey et al. (2024). The Llama 3 herd of models, table 3.
- Dettmers et al. (2023). QLoRA: efficient finetuning of quantized LLMs.
Explore further
- Hugging Face PEFTWidely used library for LoRA and other parameter-efficient fine-tuning methods.
Last updated
More tools
All tools- estimatorTraining compute budgetSplit a training budget between model size and tokens using fitted scaling laws, or check an existing run.Open tool
- estimatorTraining cost estimatorTurn parameters and tokens into FLOPs, GPU-hours, days and a cost at a price you enter.Open tool
- estimatorTraining memory plannerEstimate per-GPU memory for training: weights, gradients, optimiser states and activations, by ZeRO stage.Open tool