File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 23
23
from __future__ import annotations
24
24
25
25
import json
26
+ import types
26
27
27
28
# from functools import reduce
28
29
# from math import gcd
32
33
import torch .nn as nn
33
34
import torch .nn .functional as F
34
35
36
+ from torchao .quantization .quant_api import _linear_extra_repr
37
+
35
38
# AttributeError: '_OpNamespace' 'quantized_decomposed' object has no attribute 'quantize_per_channel_group'
36
39
from torch .ao .quantization .fx ._decomposed import quantized_decomposed_lib # noqa
37
40
from torchao .dtypes import PackedLinearInt8DynamicActivationIntxWeightLayout , QDQLayout
@@ -111,6 +114,16 @@ def quantize_model(
111
114
if isinstance (quantize_options , str ):
112
115
quantize_options = json .loads (quantize_options )
113
116
117
+ def _attach_extra_repr (module ):
118
+ for name , child in module .named_children ():
119
+ if isinstance (child , nn .Linear ):
120
+ if not hasattr (child , 'extra_repr' ):
121
+ child .extra_repr = types .MethodType (_linear_extra_repr , child )
122
+ else :
123
+ _attach_extra_repr (child )
124
+
125
+ _attach_extra_repr (model )
126
+
114
127
for quantizer , q_kwargs in quantize_options .items ():
115
128
if quantizer not in quantizer_class_dict :
116
129
raise RuntimeError (f"unknown quantizer { quantizer } specified" )
You can’t perform that action at this time.
0 commit comments