@@ -116,7 +116,7 @@ def validate_scheme(
116
116
117
117
def initialize_quantization (self , model : torch .nn .Module ):
118
118
"""
119
- Attach quantization schemes and observers to modules in the model according to
119
+ Attach quantization schemes to modules in the model according to
120
120
the quantization config specified on this modifier
121
121
122
122
:param model: model to attach schemes and observers to
@@ -127,25 +127,25 @@ def initialize_quantization(self, model: torch.nn.Module):
127
127
config = self .resolve_quantization_config ()
128
128
apply_quantization_config (model , config )
129
129
130
- # apply observers, disable quantization until calibration
131
- model .apply (self ._initialize_observers )
130
+ # disable quantization until calibration
132
131
model .apply (disable_quantization )
133
132
134
133
def start_calibration (self , model : torch .nn .Module ):
135
134
"""
136
- Register activation calibration hooks (including kv_cache quantization) and
137
- enable quantization as we calibrate
135
+ Attach observers, register activation calibration hooks (including
136
+ kv_cache quantization) and enable quantization as we calibrate
138
137
139
138
:param model: model to prepare for calibration
140
139
"""
141
140
self ._calibration_hooks = self ._initialize_hooks (model )
141
+ model .apply (self ._initialize_observers )
142
142
model .apply (apply_calibration_status )
143
143
model .apply (enable_quantization ) # quantize at the same time as calibrate
144
144
145
145
def end_calibration (self , model : torch .nn .Module ):
146
146
"""
147
- Remove calibration hooks and set the model status to frozen. Keep quantization
148
- enabled for future operations
147
+ Remove calibration hooks and observers, and set the model status to frozen.
148
+ Keep quantization enabled for future operations
149
149
150
150
:param model: model to end calibration for
151
151
"""
0 commit comments