{"record":{"id":"4be5d96fe272816a","repo":"huggingface/transformers","slug":"deepgemm-linear-requires-fp16-or-bf16-activations","errorCode":null,"errorMessage":"DeepGEMM linear requires FP16 or BF16 activations, got {input.dtype}","messagePattern":"DeepGEMM linear requires FP16 or BF16 activations, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/deepgemm.py","lineNumber":595,"sourceCode":"@deprecate_kwarg(\"output_dtype\", version=\"v5.16\")\ndef deepgemm_fp8_fp4_linear(\n    input: torch.Tensor,\n    weight: torch.Tensor,\n    weight_scale_inv: torch.Tensor,\n    bias: torch.Tensor | None = None,\n    block_size: tuple[int, int] | None = None,\n    output_dtype: torch.dtype | None = None,\n    activation_scale: torch.Tensor | None = None,\n) -> torch.Tensor:\n    \"\"\"End-to-end DeepGEMM linear: per-token activation quant + FP8/FP4 matmul.\n\n    Static (per-tensor) activation quantization is rejected — DeepGEMM needs\n    per-row SFs. Callers should route static activations through the Triton fallback.\n    \"\"\"\n    if activation_scale is not None:\n        raise NotImplementedError(\"DeepGEMM linear does not support static activation quantization.\")\n    if input.dtype not in (torch.bfloat16, torch.float16):\n        raise ValueError(f\"DeepGEMM linear requires FP16 or BF16 activations, got {input.dtype}\")\n\n    # Fail before the (hub-download + JIT) load if this device can't serve these dtypes.\n    _assert_sm100_requirements(weight, weight_scale_inv)\n\n    deepgemm = load_deepgemm_kernel()\n    cast_kwargs = _select_fp8_cast_kwargs(weight, weight_scale_inv, block_size, is_sm100())\n\n    input_2d = input.view(-1, input.shape[-1])\n    qinput_2d, scale_2d = deepgemm.per_token_cast_to_fp8(input_2d, **cast_kwargs)\n    output = torch.empty(qinput_2d.shape[0], weight.shape[0], device=input.device, dtype=input.dtype)\n\n    # Pass `(1, 1, gran_k)` for int-SF paths so the kernel uses the right K granularity\n    # (the default `(1, 1, 128)` mismatches FP4's gran_k=32). Float-SF leaves it None.\n    sf_recipe = (1, 1, cast_kwargs[\"gran_k\"]) if cast_kwargs.get(\"use_packed_ue8m0\") else None\n    deepgemm.fp8_fp4_matmul(\n        (qinput_2d, _coerce_sf_for_kernel(scale_2d, is_sm100(), expected_mn=qinput_2d.size(0))),\n        (weight, _coerce_sf_for_kernel(weight_scale_inv, is_sm100(), expected_mn=weight.size(0))),\n        output,","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/deepgemm.py#L577-L613","documentation":"Error \"DeepGEMM linear requires FP16 or BF16 activations, got {input.dtype}\" thrown in huggingface/transformers.","triggerScenarios":"Raised in DeepGEMM linear forward when input activations are not float16 or bfloat16.","commonSituations":"Running a DeepGEMM FP8 model with float32 activations instead of half precision.","solutions":["Cast activations to float16 or bfloat16 before the DeepGEMM linear.","Load the model with torch_dtype=torch.bfloat16."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}