NormalFloat4 (NF4) is a four-bit numerical data type designed for neural-network weights that approximately follow a normal (Gaussian) distribution. In QLoRA, it reduces storage requirements while supporting memory-efficient fine-tuning. section 8.3.4 section 8.3
NF4’s implementation role combines several memory-saving choices:
- Packs normally distributed weights into four bits, assigning denser representation to more common values according to information-theoretic principles. section 8.3.4
- Uses quantile quantization to approximate input-tensor quantiles through the empirical cumulative distribution function. section 8.3.4
- Can be paired with double quantization, which quantizes the constants from the first quantization step to reduce additional memory use. section 8.3.4
- Serves as the storage type while QLoRA uses bfloat16 as the computation type. section 8.3.4
Configure NF4 with bitsandbytes
A four-bit model configuration enables NF4 storage, double quantization, and bfloat16 computation: `BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_use_double_quant=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16)`. Passing this configuration to `AutoModelForCausalLM.from_pretrained` loads the quantized model.

