keras/src/layers/core/dense.py/Dense/quantize
class Dense:    def quantize(self, mode, type_check=True):
        import gc

        # Prevent quantization of the subclasses
        if type_check and (type(self) is not Dense):
            raise self._quantize_not_implemented_error()
        self._check_quantize_args(mode, self.compute_dtype)

        self._tracker.unlock()
        if mode == "int8":
            # Quantize `self._kernel` to int8 and compute corresponding scale
            kernel_value, kernel_scale = quantizers.abs_max_quantize(
                self._kernel, axis=0
            )
            kernel_scale = ops.squeeze(kernel_scale, axis=0)
            self._untrack_variable(self._kernel)
            kernel_shape = self._kernel.shape
            del self._kernel
            # Utilize a lambda expression as an initializer to prevent adding a
            # large constant to the computation graph.
            self._int8_build(
                kernel_shape,
                lambda shape, dtype: kernel_value,
                lambda shape, dtype: kernel_scale,
            )
        elif mode == "float8":
            self._float8_build()
        else:
            raise self._quantization_mode_error(mode)
        self._tracker.lock()

        # Set new dtype policy
        if self.dtype_policy.quantization_mode is None:
            policy = dtype_policies.get(f"{mode}_from_{self.dtype_policy.name}")
            self.dtype_policy = policy

        # Release memory manually because sometimes the backend doesn't
        gc.collect()