LoRA Parameter Calculator — Trainable Params & Adapter Size
Work out exactly how many trainable parameters a LoRA or QLoRA fine-tune adds to Llama 3, Mistral, Qwen2.5, Gemma 2, or a custom LLM — plus the percentage of the base model, the adapter file size, and the training memory. Matches PEFT, no signup, sources cited below.
How it works
Low-Rank Adaptation (LoRA) freezes the base model and inserts a small, trainable low-rank update beside each targeted weight matrix. For a linear layer with weight W ∈ ℝ^(out × in), LoRA learns two matrices — A ∈ ℝ^(r × in) and B ∈ ℝ^(out × r) — and adds their product to the frozen weight. Only A and B are trained, so each module contributes exactly r · (in + out) trainable parameters (Hu et al., arXiv:2106.09685).
- Resolve the architecture dimensions from the chosen preset (taken from each model's official
config.json) or from your custom inputs: hidden size, layers, attention heads, KV heads, head dim, and MLP intermediate size. - Find each projection's in/out size. Attention:
q_projisd_model → n_heads·head_dim;k_proj/v_projared_model → n_kv_heads·head_dim(narrower under Grouped-Query Attention);o_projisn_heads·head_dim → d_model. MLP:gate_proj/up_projared_model → intermediateanddown_projisintermediate → d_model. - Compute per-module LoRA parameters as
r · (in + out), sum across the selected modules, then multiply by the number of layers. Alpha is excluded — it only scalesΔW = (α/r)·B·Aat inference and does not change the count. - Derive the base-model parameter count from the same dimensions (embeddings, per-layer attention and MLP weights, and norms) so the trainable percentage is internally consistent.
- Adapter file size = trainable × bytes-per-parameter (fp16/bf16 = 2, fp32 = 4), reported in MB (÷ 1024²). Training memory = trainable × (param + gradient at adapter precision + 8 bytes for the Adam fp32 moment states) — 12 bytes per parameter in fp16. The frozen base weights and activations are counted separately.
The result reproduces what Hugging Face PEFT's print_trainable_parameters() prints for the same rank and target_modules. The tool also cross-checks the total two independent ways — the r·(in + out) identity and counting the A and B matrices separately — which must agree to the parameter.
Worked examples
Frequently asked questions
Sources & references
- Hu et al. — LoRA: Low-Rank Adaptation of Large Language Models (arXiv:2106.09685)
- Dettmers et al. — QLoRA: Efficient Finetuning of Quantized LLMs (arXiv:2305.14314)
- Hugging Face PEFT documentation — reference implementation
- Meta Llama 3 8B — official config.json (architecture dims)
The model architecture dimensions and formulas on this page were last cross-checked against the cited papers and config.json files on 2026-07-02. LoRA sizing is architecture-driven, so figures change only when a model's config changes.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want another model preset added?
Email me at [email protected] — most fixes ship within 24 hours.