Skip to content
SurogateSurogateDocs
↑↓ to move↵ to openesc to close

Quantized LoRA (QLoRA)

QLoRA lets you fine-tune with much less memory. The frozen base model weights are quantized, and the LoRA adapters (see LoRA settings) train in higher precision. Surogate supports two modes:

  • Online QLoRA: Surogate quantizes the weights at startup from a standard BF16/FP16 checkpoint.
  • Pre-quantized models: you load a model that is already quantized (for example, from the Hugging Face Hub). The supported formats are Fine-Grained FP8 (compatible with NVIDIA ModelOpt FP8 exports), ModelOpt NVFP4 (two-level FP8+FP32 block scaling), compressed-tensors NVFP4 (llm-compressor exports, such as NVFP4 experts beside per-channel FP8 projections) and MXFP4 (microscaling FP4, GPT-OSS models). These skip the quantization step at startup and load straight into the quantized format.

Online QLoRA comes in three formats:

AspectFP8 QLoRAFP4 QLoRANF4 QLoRA (BitsAndBytes)
FormatE4M3 (fwd), E5M2 (bwd)E2M1 (both)NF4 (4-bit normal float)
ScalingPer-tensor delayedTwo-level block (FP8 + FP32)Per-block absmax (+ double quant)
GPU RequirementSM89+ (Ada, Hopper, Blackwell)SM100+ (Blackwell only)Any CUDA GPU
Memory Compression~50% vs FP16~75% vs FP16~75% vs FP16

When a Hugging Face model already ships pre-quantized weights (a ModelOpt-quantized checkpoint, for example), Surogate loads the quantized tensors straight from the safetensors files, with no quantization pass at startup. For large models this saves a lot of startup time, and your training run uses exactly the quantized representation of the published checkpoint.

FormatHF quant_methodData dtypeScale dtypeNotes
Fine-Grained FP8fp8FP8 E4M3FP32 (inverse scale)Per-block 2D tile scaling
ModelOpt NVFP4modelopt / NVFP4FP4 E2M1FP8 block + FP32 globalTwo-level scaling (FP8 + FP32)
compressed-tensors NVFP4compressed-tensors (nvfp4-pack-quantized group)FP4 E2M1FP8 block + FP32 global per expertllm-compressor exports; other modules load as stored (see below)
MXFP4mxfp4FP4 E2M1FP8 per-blockGPT-OSS models only; uses _blocks/_scales tensor naming

At startup Surogate reads the quantization_config in the model’s Hugging Face config.json and detects the pre-quantized format from it. You don’t need any extra config keys.

Hugging Face tensor naming:

FormatData tensorBlock scale tensorGlobal scale tensor
Fine-Grained FP8{name}.weight{name}.weight_scale_inv—
ModelOpt NVFP4{name}.weight{name}.weight_scale{name}.weight_scale_2
compressed-tensors NVFP4{name}.weight_packed{name}.weight_scale{name}.weight_global_scale
MXFP4{base}_blocks{base}_scales—

MXFP4 names tensors differently. There is no .weight suffix: the packed FP4 data is stored as {base}_blocks and the FP8 scales as {base}_scales.

In every format, layers listed in the model’s modules_to_not_convert (usually the embedding and LM head) load at full BF16 precision.

Some fused weight tensors (such as gate_up_proj) are stored as separate pieces in pre-quantized checkpoints. Surogate loads, dequantizes, fuses and re-quantizes them for you.

  • Requires lora: true (LoRA settings). The base weights are frozen and only the LoRA adapters train.
  • Can’t be combined with online QLoRA (QLoRA settings): qlora_fp8, qlora_fp4, and qlora_bnb must all be false.
  • No adapter merging: adapter_path is not supported, because there is no BF16 intermediate.
yaml
model: nvidia/Llama-3.1-8B-Instruct-FP8
lora: true
lora_rank: 16
recipe: bf16

You don’t need quantization flags. The format is detected from the checkpoint’s quantization_config.

yaml
model: nvidia/Llama-3.1-8B-Instruct-NVFP4
lora: true
lora_rank: 16
recipe: nvfp4

compressed-tensors NVFP4 (llm-compressor exports)

Section titled “compressed-tensors NVFP4 (llm-compressor exports)”

A checkpoint whose quantization_config has quant_method: compressed-tensors and a config_groups entry of format nvfp4-pack-quantized loads as a pre-quantized NVFP4 base. The NVFP4 modules arrive as E2M1 codes (weight_packed), E4M3 block scales (weight_scale) and a global scale (weight_global_scale, the encode scale, inverted on load). The trainer quantizes weights only: input_global_scale is not used, and NVFP4 weights are dequantized to BF16 where they are used.

  • MoE experts stored one by one (experts.{e}.{gate,up,down}_proj, as llm-compressor writes them) are stacked for Qwen3.5 / Qwen3.6 MoE models. Each expert keeps its own global scale. The dequant kernel applies one decode scale per expert; folding them into one would re-round the E4M3 block scales (up to ~6 % error).
  • Every other module loads as the checkpoint stores it. Per-channel FP8 Linears (in a Qwen3.5-35B-A3B export: the attention and Gated DeltaNet projections and the lm-head) stay FP8 (codes + row scales) and stream with their stage under parallelism: dispatch_pp (Dispatch Pipeline Parallelism). They do not become a BF16 copy on every GPU. BF16 modules load at full precision.
  • Recipe: bf16.
yaml
model: /path/to/nvfp4-checkpoint # NVFP4 in compressed-tensors format
lora: true
lora_rank: 16
lora_target_modules: [gate_proj, up_proj, down_proj]
recipe: bf16

We checked this on an NVFP4 export of a Qwen3.5-35B-A3B model (8× RTX 5090, parallelism: dispatch_pp, zero LoRA delta), against our serving engine’s rollouts of the same checkpoint, as k3 KL per token:

Comparisonk3
vs the engine’s decode, 6 rollouts of at most 8k0.0050
vs the engine’s prefill, 21 rollouts of at most 32k (chunked)0.0056
vs the engine with its MoE pinned to W4A160.0036-0.0047
FP8 base against the FP8 engine, for comparison0.0087

At 131k with replicated LoRA r8, the peak per card is 27.3 GB, against 29.7 GB with the FP8 export.

yaml
model: nvidia/Nemotron-H-47B-Base-MXFP4
lora: true
lora_rank: 16
recipe: bf16

MXFP4 is only supported for GPT-OSS model architectures for now. The format is detected from the checkpoint’s quantization_config.


QLoRA decides how the frozen base model weights are stored and used in the forward pass. The base weights stay quantized and are never updated.

The recipe decides the precision of the LoRA adapter computations, activations and gradients during training.

You can pair any QLoRA format with any compatible recipe:

QLoRA (base weights) + Recipe (LoRA training) = Full Configuration

FP8 QLoRA stores the base model weights in FP8, which uses ~50% less memory than FP16/BF16.

Base weights are quantized to FP8 in two formats, one for each pass:

FormatExponentMantissaMax ValueUse Case
E4M34 bits3 bits448Forward pass (higher precision)
E5M25 bits2 bits57344Backward pass (larger dynamic range)

Delayed scaling computes scale factors from the previous iteration’s abs-max values (over a history window of 1024 by default). This trains more stably than just-in-time scaling.

ParameterDefaultDescription
qlora_fp8#falseEnable FP8 QLoRA
margin#0Margin for scale factor computation
amax_history_len#1024Length of amax history window
amax_compute_algo#MAXAlgorithm: MAX or MOST_RECENT
reduce_amax#trueReduce amax across distributed group
skip_quant_first_layers#0Skip quantization for first N layers
skip_quant_last_layers#0Skip quantization for last N layers
RecipeUse Case
bf16Maximum LoRA accuracy, any GPU (Recommended)
fp8-hybridFaster LoRA compute on SM89+ GPUs
nvfp4Maximum speed on Blackwell (experimental)
yaml
qlora_fp8: true
skip_quant_first_layers: 1
skip_quant_last_layers: 2
recipe: bf16
lora: true
lora_rank: 16

FP4 QLoRA stores the base model weights in NVIDIA’s FP4 E2M1 format, which uses ~75% less memory than FP16/BF16. It needs a Blackwell GPU (SM100+).

FP4 E2M1 compresses hard: it has only 8 representable values per sign.

PropertyValue
Exponent bits2
Mantissa bits1
Values±{0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0}
Storage2 values per byte (4 bits each)

Two-level block scaling:

  • Level 1: FP8 E4M3 scales per block (16 values for activations, 16x16 for weights)
  • Level 2: FP32 global amax baked into block scales

Stability techniques:

  • Random Hadamard Transform (RHT) spreads outliers out before quantization.
  • Stochastic rounding stops quantization bias from accumulating in gradients.
  • Four-Over-Six (4/6) adaptive scaling picks the best scale for each block.
  • Layer skipping keeps sensitive layers (embedding, lm_head) in BF16 (see Layer quantization skip options).
ParameterDefaultDescription
qlora_fp4#falseEnable FP4 QLoRA
skip_quant_first_layers#0Skip FP4 for first N layers
skip_quant_last_layers#0Skip FP4 for last N layers
backend#cutlassBackend: cudnn or cutlass
RecipeUse Case
nvfp4Maximum speed, full FP4 pipeline (Recommended)
bf16Higher LoRA accuracy, slower
fp8-hybridBalance of speed and accuracy
yaml
qlora_fp4: true
recipe: nvfp4
lora: true
lora_rank: 16
skip_quant_first_layers: 1
skip_quant_last_layers: 4

NF4 QLoRA uses the BitsAndBytes NF4 (NormalFloat4) quantization format. It saves ~75% of memory and runs on almost any GPU.

NF4 is a 4-bit data type designed for normally distributed weights:

PropertyValue
Bits per value4
Storage2 values per byte
Quantile-based16 levels mapped to normal distribution quantiles
Block sizeConfigurable (default: 64 values per block)

Block-wise quantization:

  • Weights are divided into blocks (default 64 values)
  • Each block stores an FP32 absmax scale factor
  • Values are quantized to 4-bit indices into a fixed NF4 lookup table

Double quantization (optional):

  • Absmax scales are further quantized to INT8
  • Groups of 256 blocks share an FP32 scale and offset
  • Reduces scale overhead from 4 bytes to ~1 byte per block

For a weight tensor with N elements using block size 64:

ComponentSize (bytes)With Double Quant
NF4 dataN / 2N / 2
Absmax scales(N / 64) × 4(N / 64) × 1
Double quant—(N / 64 / 256) × 8
ParameterDefaultDescription
qlora_bnb#falseEnable BitsAndBytes NF4 QLoRA
qlora_bnb_block_size#64Block size for quantization (64 or 128)
qlora_bnb_double_quant#trueEnable double quantization for scales

FP8 and FP4 QLoRA need specific GPU architectures. NF4 QLoRA works on any CUDA GPU, and dequantizes on the fly during the forward and backward passes.

RecipeUse Case
bf16Best accuracy, broad compatibility (Recommended)
fp8-hybridFaster compute on SM89+ GPUs
yaml
model: Qwen/Qwen3-4B
lora: true
lora_rank: 16
lora_alpha: 32
qlora_bnb: true
qlora_bnb_block_size: 64
qlora_bnb_double_quant: true
recipe: bf16