liveBook · Manning

NormalFloat4

As explained in Transformers in Action

NF4 is a four-bit numerical data type optimized for representing neural-network weights with an approximately normal distribution.

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.

How Transformers in Action covers it

How deep it goes
Explains NF4’s distributional rationale, quantile quantization, double quantization, and storage-computation type separation.
Examples
Uses Falcon 7B loading with bitsandbytes and a configuration enabling NF4, double quantization, and bfloat16 computation.
What it assumes
Defines quantization basics while assuming familiarity with neural-network weights and parameter-efficient LLM fine-tuning.
What you can do after
Operate/configure four-bit model loading with bitsandbytes using NF4 storage, double quantization, and bfloat16 computation.
How it connects
Connects NF4 with QLoRA, quantization, double quantization, LoRA, and bfloat16 computation.

Also explained in

Compare how 2 books explain NormalFloat4 →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transformers in Action. The section links point to the parts of the book it draws on.