LoRA Config Calculator
Derive trainable parameters, adapter size and scaling from rank, alpha, target modules and model architecture.
Base model
32 layers · 4096 hiddenLoRA config
4 targetsTarget modules
Adapter estimate
425,984 paramsSummary
425,984 trainable parameters
0.85 MB adapter · 0.0053% of base · scaling α/r = 2.00
Enable optimizer memory for a training-time estimate.
Llama 3 8B · r=16 · alpha=32 · 425,984 trainable params (0.005%) · 0.85 MB bf16 · scaling 2.00
Per-module breakdown
| Module | Shapes | Params | MB |
|---|---|---|---|
| q_proj | 4096 → 4096 | 131,072 | 0.26 |
| k_proj | 4096 → 1024 | 81,920 | 0.16 |
| v_proj | 4096 → 1024 | 81,920 | 0.16 |
| o_proj | 4096 → 4096 | 131,072 | 0.26 |
Rank sweep
| Rank | Params | MB | % base |
|---|---|---|---|
| 4 | 106,496 | 0.21 | 0.0013% |
| 8 | 212,992 | 0.43 | 0.0027% |
| 16 (current) | 425,984 | 0.85 | 0.0053% |
| 32 | 851,968 | 1.70 | 0.0106% |
| 64 | 1,703,936 | 3.41 | 0.0212% |
| 128 | 3,407,872 | 6.82 | 0.0424% |
Guidance (rules of thumb)
r = 4–8 for simple style or format changes; 16–32 for mid-sized task adaptation; 64+ for complex behavior or large datasets. These are rules of thumb, not guarantees.
alpha = 2r is the common PEFT default; alpha = r makes the scaling factor 1. The effective adapter update is (alpha / r) × B·A.
Attention-only targets are cheapest and often enough for style tasks. Adding MLP projections increases capacity and memory; embedding LoRA is powerful but can dominate parameter count on large vocabularies.
PEFT snippet
base_model_name_or_path: llama-3-8b peft_type: LORA r: 16 lora_alpha: 32 lora_dropout: 0.05 bias: none task_type: CAUSAL_LM target_modules: [q_proj, k_proj, v_proj, o_proj]
Examples
Attention-only
Llama 3 8B, r=16, q/k/v/o424,984 params, 0.85 MBA cheap first adaptation for style and format changes.
All-linear
Llama 3 8B, r=16, seven targets1,309,720 params, 2.62 MBAdds the three MLP projections for more capacity.
Embedding LoRA
r=16 with embed_tokens on 128k vocab~2.06M params for embeddings aloneLarge vocabularies make embedding adapters surprisingly heavy.
Rank sweep
r = 4 … 128parameter/MB/% tableRead the same formulas at six candidate ranks for budgeting.
About this tool
The LoRA Config Calculator turns a fine-tuning configuration into exact adapter math. Choose a base-model architecture, set rank and alpha, select target modules, and get the trainable parameter count, adapter size, percentage of the base model and the alpha/r scaling factor.
Per-module rows show the input and output dimensions used for each B(d×r)·A(r×k) pair, including GQA-aware key and value projection widths. A rank sweep compares 4 through 128 for the same target set, and an optional optimizer estimate adds gradients, an fp32 master copy and Adam moments to the training-time memory contribution.
Guidance panels explain the usual rank ranges, alpha conventions and the trade-off between attention-only and attention-plus-MLP targets. The PEFT-style YAML snippet is generated from the current configuration so you can move from planning to a training run without transcribing numbers. Everything is client-side.
What this tool does not do
- No training is executed; this is parameter and memory arithmetic only.
- Custom architectures are approximations — real configs may tie embeddings or use different projection names.
- Optimizer memory is an additive estimate, not a full training-time VRAM model.
How to use this tool
Pick an architecture
Select a Llama, Mistral, Qwen2 or Gemma preset, or edit layers, hidden size, heads, KV heads, intermediate size and vocabulary directly.
Choose targets and rank
Tick q/k/v/o, MLP projections or embed_tokens and set rank r plus alpha. Warnings appear for rank-capped modules and zero alpha.
Read the breakdown
Compare per-module parameter counts, adapter megabytes and the rank sweep table; toggle optimizer memory for a training-time estimate.
Copy the config
Copy or download the PEFT YAML snippet and use it as the starting point for your training job.
Use cases
Fine-tune planning
Choose a rank and target set that fit a memory budget before starting a job.
Capacity comparison
See how much extra capacity attention-plus-MLP targets buy over attention-only.
Config review
Check a colleague's PEFT config for GQA-correct shapes and scaling choices.
Module shapes
| Target | LoRA parameters |
|---|---|
| q_proj / o_proj | r × (hidden + hidden) per layer |
| k_proj / v_proj | r × (hidden + kv_heads × head_dim) per layer |
| gate_proj / up_proj | r × (hidden + intermediate) per layer |
| down_proj | r × (intermediate + hidden) per layer |
| embed_tokens | r × (vocab + hidden), counted once |
Adapter MB uses decimal megabytes and the selected dtype (2 bytes for bf16/fp16, 4 for fp32).
Common mistakes
Mistake:Using hidden size for k/v outputs on GQA models.
Fix:k_proj and v_proj output kv_heads × head_dim; the calculator does this for each preset.
Mistake:Assuming alpha changes parameter count.
Fix:Alpha only changes the scaling factor alpha/r; rank and target shapes determine the parameter count.
Mistake:Forgetting embedding adapters are per vocabulary, not per layer.
Fix:The embed row is counted once and flags large vocabularies explicitly.
Mistake:Treating rank guidance as a guarantee.
Fix:Ranges are rules of thumb; validate quality on your own evaluation set.
Frequently asked questions
How many trainable parameters does LoRA add?
For each wrapped matrix, r × (in + out). A Llama 3 8B adapter with r=16 on q/k/v/o has 424,984 parameters; adding the three MLP projections brings it to 1,309,720. The per-module table shows every term so you can audit the total.
What rank should I use?
r = 4–8 is common for simple style or format changes, 16–32 for mid-sized task adaptation, and 64+ for complex behavior with larger datasets. These are rules of thumb; evaluate on your own task rather than treating them as guarantees.
What does alpha do?
Alpha sets the scaling factor: the adapter update is multiplied by alpha/r. alpha = 2r is the common PEFT default; alpha = r gives a factor of 1. Alpha does not change the number of trainable parameters or the adapter file size.
How much VRAM does a LoRA need?
The adapter itself is small — a few megabytes in bf16 — but training also needs the frozen base weights, activations, gradients and optimizer states. Enable the optimizer toggle for the adapter-side contribution, then use the VRAM calculator for a full deployment estimate.
Which modules should I target?
Attention-only (q/k/v/o) is the cheapest starting point and often enough for style changes. Adding gate/up/down increases capacity. Embedding LoRA can be very effective for vocabulary-level changes but is counted once over the full vocabulary and can dominate the adapter on 128k-token models.
Does the calculator handle grouped-query attention?
Yes. For presets such as Llama 3 8B and Mistral 7B, k_proj and v_proj use kv_heads × head_dim as the output width instead of the full hidden size, so their parameter counts are correctly smaller than in an MHA model.
References & standards
Related tools
Agent Tool Flowchart Builder
Design agentic tool-call DAGs with decision branches and bounded loops. Validates reachability, cycle handling, and emits clean Mermaid flowcharts — fully in your browser.
AI Agent Memory & Buffer Simulator
Compare sliding window, summary buffer, and vector memory strategies
AI API Client SDK Generator
Generate typed API client SDK files from OpenAPI specifications or cURL requests
AI Code Explainer
Explain code snippets with grounded cloud AI
AI Code Security Auditor
Scan source code for high-confidence OWASP Top 10 vulnerabilities
AI Code Translator
Translate code into idiomatic implementations in another language