File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
backends/xnnpack/test/ops
examples/models/llama/source_transformation Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -395,7 +395,9 @@ def _test_groupwise_dq_linear(
395
395
quantize_ (
396
396
mod ,
397
397
Int8DynamicActivationIntxWeightConfig (
398
- weight_dtype = torch .int4 , weight_granularity = PerGroup (group_size )
398
+ # pyre-ignore[16]
399
+ weight_dtype = torch .int4 ,
400
+ weight_granularity = PerGroup (group_size ),
399
401
),
400
402
)
401
403
unwrap_tensor_subclass (mod )
Original file line number Diff line number Diff line change @@ -135,6 +135,7 @@ def quantize( # noqa C901
135
135
PerAxis (0 ) if group_size == 0 else PerGroup (group_size )
136
136
),
137
137
weight_mapping_type = MappingType .SYMMETRIC ,
138
+ # pyre-ignore[6]
138
139
intx_packing_format = "opaque_torchao_auto" ,
139
140
),
140
141
)
@@ -154,12 +155,23 @@ def quantize( # noqa C901
154
155
from torchao .quantization .granularity import PerGroup
155
156
from torchao .utils import unwrap_tensor_subclass
156
157
158
+ def filter_fn (m , fqn ):
159
+ is_linear = isinstance (m , nn .Linear )
160
+ has_shape_compatible_with_group_size = False
161
+ if is_linear :
162
+ has_shape_compatible_with_group_size = (
163
+ m .weight .shape [1 ] % group_size == 0
164
+ )
165
+ return is_linear and has_shape_compatible_with_group_size
166
+
157
167
quantize_ (
158
168
model ,
159
169
Int8DynamicActivationIntxWeightConfig (
170
+ # pyre-ignore[16]
160
171
weight_dtype = torch .int4 ,
161
172
weight_granularity = PerGroup (group_size ),
162
173
),
174
+ filter_fn = filter_fn ,
163
175
)
164
176
165
177
model = unwrap_tensor_subclass (model )
You can’t perform that action at this time.
0 commit comments