Skip to content
Merged

pyre-fix #14241

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backends/xnnpack/test/ops/test_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ def _test_groupwise_dq_linear(
quantize_(
mod,
Int8DynamicActivationIntxWeightConfig(
weight_dtype=torch.int4, weight_granularity=PerGroup(group_size)
# pyre-ignore[16]
weight_dtype=torch.int4,
weight_granularity=PerGroup(group_size),
),
)
unwrap_tensor_subclass(mod)
Expand Down
12 changes: 12 additions & 0 deletions examples/models/llama/source_transformation/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def quantize( # noqa C901
PerAxis(0) if group_size == 0 else PerGroup(group_size)
),
weight_mapping_type=MappingType.SYMMETRIC,
# pyre-ignore[6]
intx_packing_format="opaque_torchao_auto",
),
)
Expand All @@ -154,12 +155,23 @@ def quantize( # noqa C901
from torchao.quantization.granularity import PerGroup
from torchao.utils import unwrap_tensor_subclass

def filter_fn(m, fqn):
is_linear = isinstance(m, nn.Linear)
has_shape_compatible_with_group_size = False
if is_linear:
has_shape_compatible_with_group_size = (
m.weight.shape[1] % group_size == 0
)
return is_linear and has_shape_compatible_with_group_size

quantize_(
model,
Int8DynamicActivationIntxWeightConfig(
# pyre-ignore[16]
weight_dtype=torch.int4,
weight_granularity=PerGroup(group_size),
),
filter_fn=filter_fn,
)

model = unwrap_tensor_subclass(model)
Expand Down
Loading