<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/dtype_policies/dtype_policy.py#L291-L361) |

Quantized dtype policy for int4 quantization.

Inherits From: [`QuantizedDTypePolicy`](https://www.tensorflow.org/api_docs/python/tf/keras/dtype_policies/QuantizedDTypePolicy), [`DTypePolicy`](https://www.tensorflow.org/api_docs/python/tf/keras/DTypePolicy)

    tf.keras.dtype_policies.Int4DTypePolicy(
        mode, source_name=None
    )

This policy helps propagate quantization settings for int4 sub-channel
quantization when loading a quantized model in Keras format.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `mode` | The quantization mode. This should be a string in the format `"int4/<block_size>"`. <br /> - `"int4"`: The identifier for the quantization algorithm. - `<block_size>`: The block size for sub-channel quantization. Use -1 for per-channel (legacy) quantization. Any positive integer enables sub-channel quantization with that block size. Example: `"int4/128"` for sub-channel with 128-element groups. |
| `source_name` | The source dtype policy name, e.g. "float32". |

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `compute_dtype` | The compute dtype of this policy. <br /> This is the dtype layers will do their computations in. Typically layers output tensors with the compute dtype as well. Note that even if the compute dtype is float16 or bfloat16, hardware devices may not do individual adds, multiplies, and other fundamental operations in float16 or bfloat16, but instead may do some of them in float32 for numeric stability. The compute dtype is the dtype of the inputs and outputs of the ops that the layer executes. Internally, many ops will do certain internal calculations in float32 or some other device-internal intermediate format with higher precision than float16/bfloat16, to increase numeric stability. |
| `name` | Returns the name of this policy. |
| `quantization_mode` | The quantization mode of this policy. |
| `variable_dtype` | The variable dtype of this policy. <br /> This is the dtype layers will create their variables in, unless a layer explicitly chooses a different dtype. If this is different than [`DTypePolicy.compute_dtype`](https://www.tensorflow.org/api_docs/python/tf/keras/DTypePolicy#compute_dtype), Layers will cast variables to the compute dtype to avoid type errors. Variable regularizers are run in the variable dtype, not the compute dtype. |

<br />

## Methods

### `convert_input`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/dtype_policies/dtype_policy.py#L150-L175)

    convert_input(
        x, autocast, dtype
    )

Converts the input dtype based on `autocast` and `dtype`.

Note that `x` can be a tensor, symbolic tensor or numpy array, and this
method will keep integer inputs untouched and only apply casting to
floats.

### `from_config`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/dtype_policies/dtype_policy.py#L180-L182)

    @classmethod
    from_config(
        config
    )

### `get_config`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/dtype_policies/dtype_policy.py#L356-L361)

    get_config()

### `__eq__`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/dtype_policies/dtype_policy.py#L351-L354)

    __eq__(
        other
    )

Return self==value.