tf.keras.dtype_policies.Int4DTypePolicy

Quantized dtype policy for int4 quantization.

Inherits From: QuantizedDTypePolicy, DTypePolicy

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

mode The quantization mode. This should be a string in the format "int4/<block_size>".

  • "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".

compute_dtype The compute dtype of this policy.

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.

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, Layers will cast variables to the compute dtype to avoid type errors.

Variable regularizers are run in the variable dtype, not the compute dtype.

Methods

convert_input

View source

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

get_config

View source

__eq__

View source

Return self==value.