@@ -53,7 +53,6 @@ def __init__(
5353 quant_min : int | float ,
5454 quant_max : int | float ,
5555 qparams_calculator : QParamsCalculatorBase ,
56- quantization_target : CompressionTargetTensor ,
5756 n_bits : int | None = None ,
5857 ** kwargs ,
5958 ):
@@ -65,7 +64,6 @@ def __init__(
6564 self .quant_min = quant_min
6665 self .quant_max = quant_max
6766 self .qparams_calculator = qparams_calculator
68- self .quantization_target = quantization_target
6967 self .register_buffer ("_disabled" , torch .tensor (False ))
7068
7169 # Infer n_bits from dtype if not provided
@@ -78,6 +76,11 @@ def qscheme(self) -> QuantizationScheme:
7876 """The quantization scheme, delegated to the qparams_calculator."""
7977 return self .qparams_calculator .qscheme
8078
79+ @property
80+ def quantization_target (self ) -> CompressionTargetTensor :
81+ """Getter for quantization target."""
82+ return self .qparams_calculator .quantization_target
83+
8184 @property
8285 def granularity (self ) -> QuantizationGranularity :
8386 """Getter for granularity."""
@@ -359,7 +362,7 @@ def _quantize_int(
359362
360363 This function quantizes the values in tensor but keeps the quantized tensor dtype in FP.
361364 """
362- block_size = self .granularity .get_block_size (tensor .shape )
365+ block_size = self .granularity .get_block_size (tensor .shape , self . quantization_target )
363366 original_shape , blockwise_shape , reduced_shape = _get_quantization_shapes (
364367 tensor , block_size
365368 )
@@ -384,7 +387,7 @@ def _dequantize_int(
384387 output_dtype : torch .dtype ,
385388 ) -> torch .Tensor :
386389 """Integer dequantization. See :func:`_dequantize_int` for the math."""
387- block_size = self .granularity .get_block_size (tensor .shape )
390+ block_size = self .granularity .get_block_size (tensor .shape , self . quantization_target )
388391 original_shape , blockwise_shape , reduced_shape = _get_quantization_shapes (
389392 tensor , block_size
390393 )
@@ -406,7 +409,7 @@ def _quantize_float(
406409 """
407410 Floating-point quantization: cast_to_low_precision(clamp(input / scale, min, max))
408411 """
409- block_size = self .granularity .get_block_size (tensor .shape )
412+ block_size = self .granularity .get_block_size (tensor .shape , self . quantization_target )
410413 original_shape , blockwise_shape , reduced_shape = _get_quantization_shapes (
411414 tensor , block_size
412415 )
@@ -427,7 +430,7 @@ def _dequantize_float(
427430 output_dtype : torch .dtype ,
428431 ) -> torch .Tensor :
429432 """Floating-point dequantization: input * scale"""
430- block_size = self .granularity .get_block_size (tensor .shape )
433+ block_size = self .granularity .get_block_size (tensor .shape , self . quantization_target )
431434 original_shape , blockwise_shape , reduced_shape = _get_quantization_shapes (
432435 tensor , block_size
433436 )
@@ -449,7 +452,7 @@ def _fused_fake_quant_dequant(
449452
450453 Dispatches to the int or float fused STE class based on self.dtype.
451454 """
452- block_size = self .granularity .get_block_size (tensor .shape )
455+ block_size = self .granularity .get_block_size (tensor .shape , self . quantization_target )
453456 original_shape , blockwise_shape , reduced_shape = _get_quantization_shapes (
454457 tensor , block_size
455458 )
0 commit comments