TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

153. QLoRA NF4 Dequantize

Medium

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

wi​=codebook[qi​]⋅s

Asked at

NumPy

import numpy as np

 

def nf4_dequantize(...):

    pass

🔒

Premium problem

Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.

Upgrade to PremiumBack to problems

Already premium?