Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-326

NF4 Level Lookup

Problem

Look up an NF4 (4-bit NormalFloat) quantization level. NF4 uses the 16 fixed levels from -1.0 to 1.0 indexed by code 0-15, with non-uniform spacing dense near zero. Return level[code] * scale + zero_point.

The signature is nf4_level_lookup(code, scale, zero_point=0.0).

Hint

NF4 levels are quantiles of a standard normal, not uniformly spaced.

Test cases

case 1
in: [7,1,0]
expected: 0
case 2
in: [15,1,0]
expected: 1
case 3
in: [0,2,0.5]
expected: -1.5
case 4
in: [8,1,0]
expected: 0.07958029955625534
case 5
in: [1,1,0]
expected: -0.6961928009986877
Starter codePython
def nf4_level_lookup(code, scale, zero_point=0.0):
    # Your code here
    pass

5 test cases · run your code against them in the editor