{"record":{"id":"8f37973b14b91d0d","repo":"jax-ml/jax","slug":"name-does-not-accept-dtype-dtype-to-string-aval","errorCode":null,"errorMessage":"{name} does not accept dtype {dtype_to_string(aval.dtype)}. Support for narrow-width integers is platform-dependent and limited to a few specific operations, e.g. basic arithmetic and type casting.","messagePattern":"(.+?) does not accept dtype (.+?)\\. Support for narrow-width integers is platform-dependent and limited to a few specific operations, e\\.g\\. basic arithmetic and type casting\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":4264,"sourceCode":"\ndef unop_dtype_rule(result_dtype, accepted_dtypes, name, aval,\n                    supports_narrow_ints=True, **kwargs):\n  if aval.dtype == dtypes.float0:\n    raise TypeError(\n        f\"Called {name} with a float0 array. \"\n        \"float0s do not support any operations by design, because they \"\n        \"are not compatible with non-trivial vector spaces. No implicit dtype \"\n        \"conversion is done. You can use np.zeros_like(arr, dtype=np.float) \"\n        \"to cast a float0 array to a regular zeros array. \\n\"\n        \"If you didn't expect to get a float0 you might have accidentally \"\n        \"taken a gradient with respect to an integer argument.\")\n  if not any(dtypes.issubdtype(aval.dtype, t) for t in accepted_dtypes):\n    msg = '{} does not accept dtype {}. Accepted dtypes are subtypes of {}.'\n    typename = dtype_to_string(aval.dtype)\n    accepted_typenames = (t.__name__ for t in accepted_dtypes)\n    raise TypeError(msg.format(name, typename, ', '.join(accepted_typenames)))\n  if (not supports_narrow_ints) and aval.dtype in [dtypes.uint2, dtypes.int2, dtypes.uint4, dtypes.int4]:\n    raise TypeError(f'{name} does not accept dtype {dtype_to_string(aval.dtype)}.'\n                    ' Support for narrow-width integers is platform-dependent'\n                    ' and limited to a few specific operations, e.g. basic'\n                    ' arithmetic and type casting.')\n  return result_dtype(aval.dtype, **kwargs)\n\ndef default_unop_reduced_rule(aval):\n  return getr(aval)\n\ndef unop_ur_rule(name, aval, **kwargs):\n  reduced = default_unop_reduced_rule(aval)\n  if any(getu(aval)):\n    raise NotImplementedError(\n        f'unreduced rule for {name} is not implemented. Please'\n        ' file an issue at https://github.com/jax-ml/jax/issues')\n  return frozenset(), reduced, None\n\ndef unop(result_dtype, accepted_dtypes, name, supports_narrow_ints=True):\n  dtype_rule = partial(unop_dtype_rule, result_dtype, accepted_dtypes, name,","sourceCodeStart":4246,"sourceCodeEnd":4282,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L4246-L4282","documentation":"Some lax ops disallow narrow-width integer dtypes (uint2/int2/uint4/int4) because backend support is platform-dependent. When supports_narrow_ints=False and the input has one of these dtypes, this TypeError is raised.","triggerScenarios":"Passing int2/uint2/int4/uint4 arrays into lax ops that do not opt into narrow-int support (most transcendental/unusual unops).","commonSituations":"Using experimental 4-bit/2-bit quantized activations with the full lax op set; importing models that stored weights in sub-byte dtypes and calling arbitrary lax ops on them.","solutions":["Widen the values before the op: x.astype(jnp.int32) or jnp.float32, then narrow back if needed","Use only the supported ops (basic arithmetic and casting) on narrow dtypes, per the message","Keep narrow dtypes confined to storage; compute in int8/int32"],"exampleFix":"// before\ny = lax.some_op(x_int4)\n// after\ny = lax.some_op(x_int4.astype(jnp.int32)).astype(jnp.int4)","handlingStrategy":"validation","validationCode":"NARROW = {jnp.uint2, jnp.int2, jnp.uint4, jnp.int4}\nif x.dtype in NARROW:\n    x = x.astype(jnp.int32)\nout = lax.some_op(x)","typeGuard":"def is_narrow_int(x) -> bool:\n    import jax.numpy as jnp\n    return x.dtype in {jnp.uint2, jnp.int2, jnp.uint4, jnp.int4}","tryCatchPattern":null,"preventionTips":["Compute in int32/float32; keep 2/4-bit dtypes for storage only","Restrict narrow-dtype usage to arithmetic and casting ops"],"tags":["jax","lax","narrow-int","int4","dtype-validation"],"backgroundTag":"unsupported-dtype-for-operation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}