Skip to content

Commit 689575b

Browse files
HolyFalafelXuehaoSun
authored andcommitted
[SW-199696] Added PatchedLinearBase (#192)
* Added PatchedLinearBase * Fixed PatchedLinear forward_qdq * Changed quant strategy - scale to fix ci * Renamed QuantStrategy to QuantWrapper * Removed instance member from QuantWrapper * [SW-224403] Added ticket and throwing error when using row_parallel_linear_allreduce_quantization * Changed QuantWrapper to a simple method that stores scale * [SW-224538] Added ticket to TODO comment for init_linear * Pushed requires_grad to the tensor creation * Update neural_compressor/torch/algorithms/fp8_quant/_quant_common/helper_modules.py * Update neural_compressor/torch/algorithms/fp8_quant/_quant_common/helper_modules.py * Moved copy_scale functions inside PatchedLinearBase * Update helper_modules.py * Update helper_modules.py * Update neural_compressor/torch/algorithms/fp8_quant/_quant_common/helper_modules.py * Update helper_modules.py * Update helper_modules.py * Update helper_modules.py copy scale * Update neural_compressor/torch/algorithms/fp8_quant/_quant_common/helper_modules.py
1 parent a6f8f6d commit 689575b

File tree

4 files changed

+109
-247
lines changed

4 files changed

+109
-247
lines changed

neural_compressor/torch/algorithms/fp8_quant/_core/quant_dequant.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ def forward(self, x):
130130
scale = self.input_scales_creator.calc_scales(x, QuantTensorType.DYNAMIC)
131131
scale_inv = self.input_scales_creator.calc_invert_scales()
132132

133-
scale = create_scale_tensor(scale, self.scale_format)
134-
scale_inv = create_scale_tensor(scale_inv, self.scale_format)
135-
136133
ret = self.cast_to_op(x, scale_inv, False, False, self.lp_dtype)
137134

138135
return ret, scale

neural_compressor/torch/algorithms/fp8_quant/_core/scale_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def create_scale_tensor(orig_tensor, scale_format):
3939
return orig_tensor.to("cpu").to(torch.float)
4040
if scale_format == ScaleFormat.CONST:
4141
if isinstance(orig_tensor, torch.Tensor):
42-
return torch.nn.Parameter(orig_tensor)
42+
return torch.nn.Parameter(orig_tensor, requires_grad=False)
4343
elif isinstance(orig_tensor, list):
44-
return [torch.nn.Parameter(x) for x in orig_tensor]
44+
return [torch.nn.Parameter(x, requires_grad=False) for x in orig_tensor]
4545
elif scale_format == ScaleFormat.SCALAR:
4646
if isinstance(orig_tensor, (torch.Tensor, float)):
4747
return scale_to_scalar(orig_tensor)

0 commit comments

Comments
 (0)