DevTools Logo

LoRA Config Calculator

LoRA Config Calculator

Derive trainable parameters, adapter size and scaling from rank, alpha, target modules and model architecture.

Runs in your browserLlama 3 8Br=16 · α=32
Try an example

Base model

32 layers · 4096 hidden

LoRA config

4 targets

Target modules

Adapter estimate

425,984 params

Summary

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

ModuleShapesParamsMB
q_proj4096 → 4096131,0720.26
k_proj4096 → 102481,9200.16
v_proj4096 → 102481,9200.16
o_proj4096 → 4096131,0720.26

Rank sweep

RankParamsMB% base
4106,4960.210.0013%
8212,9920.430.0027%
16 (current)425,9840.850.0053%
32851,9681.700.0106%
641,703,9363.410.0212%
1283,407,8726.820.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

Input
Llama 3 8B, r=16, q/k/v/o
Output
424,984 params, 0.85 MB

A cheap first adaptation for style and format changes.

All-linear

Input
Llama 3 8B, r=16, seven targets
Output
1,309,720 params, 2.62 MB

Adds the three MLP projections for more capacity.

Embedding LoRA

Input
r=16 with embed_tokens on 128k vocab
Output
~2.06M params for embeddings alone

Large vocabularies make embedding adapters surprisingly heavy.

Rank sweep

Input
r = 4 … 128
Output
parameter/MB/% table

Read 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

  1. Pick an architecture

    Select a Llama, Mistral, Qwen2 or Gemma preset, or edit layers, hidden size, heads, KV heads, intermediate size and vocabulary directly.

  2. 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.

  3. Read the breakdown

    Compare per-module parameter counts, adapter megabytes and the rank sweep table; toggle optimizer memory for a training-time estimate.

  4. 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

TargetLoRA parameters
q_proj / o_projr × (hidden + hidden) per layer
k_proj / v_projr × (hidden + kv_heads × head_dim) per layer
gate_proj / up_projr × (hidden + intermediate) per layer
down_projr × (intermediate + hidden) per layer
embed_tokensr × (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