{"record":{"id":"ef9deac09235c600","repo":"huggingface/transformers","slug":"unsupported-p-p-n-n","errorCode":null,"errorMessage":"Unsupported p={p}, n={n}","messagePattern":"Unsupported p=(.+?), n=(.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/higgs.py","lineNumber":436,"sourceCode":"            ]\n        )\n    elif (p, n) == (1, 8):\n        return torch.tensor(\n            [\n                [-2.1519455909729004],\n                [-1.3439092636108398],\n                [-0.7560052871704102],\n                [-0.2450941801071167],\n                [0.2450941801071167],\n                [0.7560052871704102],\n                [1.3439092636108398],\n                [2.1519455909729004],\n            ]\n        )\n    elif (p, n) == (1, 4):\n        return torch.tensor([[-1.5104175806045532], [-0.4527800381183624], [0.4527800381183624], [1.5104175806045532]])\n    else:\n        raise NotImplementedError(f\"Unsupported p={p}, n={n}\")\n\n\ndef quantize_with_higgs(weight, bits: int = 4, p: int = 2, group_size: int = 256, hadamard_size: int = 1024):\n    assert len(weight.shape) == 2, \"Only 2D weights are supported for now\"\n\n    grid = get_higgs_grid(p, 2 ** (p * bits)).to(weight.device)\n    grid_norm_2 = torch.linalg.norm(grid, axis=-1) ** 2\n\n    device = weight.device\n    dtype = weight.dtype\n    weight = weight.to(copy=True, dtype=torch.float32)\n    # Pad to Hadamard transform size\n    weight = pad_to_block(weight, [1], hadamard_size)\n\n    # Scale and Hadamard transform\n    mult = weight.shape[1] // hadamard_size\n    weight = weight.reshape(-1, mult, hadamard_size)\n    scales = torch.linalg.norm(weight, axis=-1)","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/higgs.py#L418-L454","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the supported combinations: bits=4 with p=2 (n=16), or p=1 with bits=2/3/4 (n=4/8/16).","Keep the library defaults (`bits=4, p=2`) unless you know the (p, n) pair is precomputed.","If you truly need another lattice, precompute the grid yourself and contribute/patch the table rather than calling with unsupported arguments."],"exampleFix":"# before\nq = quantize_with_higgs(w, bits=8)  # NotImplementedError: p=2, n=65536\n\n# after\nq = quantize_with_higgs(w, bits=4, p=2)  # default, supported grid","handlingStrategy":"validation","validationCode":"SUPPORTED = {(2, 16), (2, 64), (1, 4), (1, 8), (1, 16)}\np, bits = 2, 4\nassert (p, 2 ** (p * bits)) in SUPPORTED, f\"unsupported Higgs grid p={p}, bits={bits}\"","typeGuard":"def higgs_grid_supported(p: int, bits: int) -> bool:\n    return (p, 2 ** (p * bits)) in {(2, 16), (2, 64), (1, 4), (1, 8), (1, 16)}","tryCatchPattern":"try:\n    q = quantize_with_higgs(w, bits=bits, p=p)\nexcept NotImplementedError:\n    q = quantize_with_higgs(w, bits=4, p=2)  # fall back to the default supported grid","preventionTips":["Stick to the shipped defaults (bits=4, p=2) unless you verified the (p, n) pair exists.","Keep the supported-pairs check next to any exposed quantization hyperparameters."],"tags":["quantization","higgs","not-implemented","unsupported-arguments"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}