huggingface/transformers · error · NotImplementedError

Unsupported p={p}, n={n}

Error message

Unsupported p={p}, n={n}

What it means

`get_higgs_grid(p, n)` returns precomputed Higgs lattice quantization grids only for the (p, n) pairs it hard-codes — with n = 2**(p*bits): (2, 16), (2, 64) style lattices for p=2 and (1, 4), (1, 8), (1, 16) for p=1. Any other combination raises NotImplementedError, because the lattice must be precomputed numerically rather than derived at runtime.

Source

Thrown at src/transformers/integrations/higgs.py:436

            ]
        )
    elif (p, n) == (1, 8):
        return torch.tensor(
            [
                [-2.1519455909729004],
                [-1.3439092636108398],
                [-0.7560052871704102],
                [-0.2450941801071167],
                [0.2450941801071167],
                [0.7560052871704102],
                [1.3439092636108398],
                [2.1519455909729004],
            ]
        )
    elif (p, n) == (1, 4):
        return torch.tensor([[-1.5104175806045532], [-0.4527800381183624], [0.4527800381183624], [1.5104175806045532]])
    else:
        raise NotImplementedError(f"Unsupported p={p}, n={n}")


def quantize_with_higgs(weight, bits: int = 4, p: int = 2, group_size: int = 256, hadamard_size: int = 1024):
    assert len(weight.shape) == 2, "Only 2D weights are supported for now"

    grid = get_higgs_grid(p, 2 ** (p * bits)).to(weight.device)
    grid_norm_2 = torch.linalg.norm(grid, axis=-1) ** 2

    device = weight.device
    dtype = weight.dtype
    weight = weight.to(copy=True, dtype=torch.float32)
    # Pad to Hadamard transform size
    weight = pad_to_block(weight, [1], hadamard_size)

    # Scale and Hadamard transform
    mult = weight.shape[1] // hadamard_size
    weight = weight.reshape(-1, mult, hadamard_size)
    scales = torch.linalg.norm(weight, axis=-1)

View on GitHub (pinned to a597f97485)

Solutions

  1. Use the supported combinations: bits=4 with p=2 (n=16), or p=1 with bits=2/3/4 (n=4/8/16).
  2. Keep the library defaults (`bits=4, p=2`) unless you know the (p, n) pair is precomputed.
  3. If you truly need another lattice, precompute the grid yourself and contribute/patch the table rather than calling with unsupported arguments.

Example fix

# before
q = quantize_with_higgs(w, bits=8)  # NotImplementedError: p=2, n=65536

# after
q = quantize_with_higgs(w, bits=4, p=2)  # default, supported grid
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {(2, 16), (2, 64), (1, 4), (1, 8), (1, 16)}
p, bits = 2, 4
assert (p, 2 ** (p * bits)) in SUPPORTED, f"unsupported Higgs grid p={p}, bits={bits}"

Type guard

def higgs_grid_supported(p: int, bits: int) -> bool:
    return (p, 2 ** (p * bits)) in {(2, 16), (2, 64), (1, 4), (1, 8), (1, 16)}

Try / catch

try:
    q = quantize_with_higgs(w, bits=bits, p=p)
except NotImplementedError:
    q = quantize_with_higgs(w, bits=4, p=2)  # fall back to the default supported grid

Prevention

When it happens

Trigger: Calling `quantize_with_higgs(weight, bits=8)` (n = 2**(2*8) = 65536, unsupported), `quantize_with_higgs(weight, bits=4, p=3)`, or `get_higgs_grid(p, n)` directly with an unsupported pair. Defaults bits=4, p=2 give n=16, which is supported.

Common situations: Experimenting with Higgs quantization at bit-widths or lattice dimensions beyond the shipped precomputed grids (e.g. 3-bit p=2 → n=64 may be supported, 8-bit is not); passing a custom `p` when copying research code.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/ef9deac09235c600. Report an issue: GitHub.