TorchedUp
ProblemsPremium
TorchedUp
QLoRA NF4 DequantizeMedium
ProblemsPremium

NF4 Dequantization (QLoRA)

In QLoRA, base weights are stored as 4-bit NF4 indices. To use them in a forward pass we must dequantize: look up the float value in the NF4 codebook and multiply by a per-block scale.

Signature: def nf4_dequantize(quantized: np.ndarray, scale: float, codebook: np.ndarray) -> np.ndarray

  • quantized: integer indices in [0, 16) (the 4-bit codes)
  • scale: per-block float scale
  • codebook: the 16-entry NF4 lookup table

Returns: codebook[quantized] * scale — float array same shape as quantized.

Math

Asked at

Python (numpy)0/3 runs today

Test Results

○simple lookup
○with scale
○2D block🔒 Premium
Advertisement