|
172 | 172 | }
|
173 | 173 |
|
174 | 174 |
|
175 |
| -###### |
176 |
| -# TO BE DEPRECATED START |
177 |
| -###### |
178 |
| -def _in_features_greater_than_16(mod, *args): |
179 |
| - return hasattr(mod, "in_features") and mod.in_features > 16 |
180 |
| - |
181 |
| - |
182 |
| -# TODO: delete |
183 |
| -def change_linear_weights_to_int8_dqtensors(model, filter_fn=None, **kwargs): |
184 |
| - """ |
185 |
| - Converts all linear weight tensors to the `Int8DynamicallyQuantizedLinearWeight` |
186 |
| - Tensor subclass, effectively applying the same form of quantization |
187 |
| - as apply_dynamic_quant while not modifying the linear modules. |
188 |
| - """ |
189 |
| - raise ImportError( |
190 |
| - "This API is deprecated for pytorch 2.4+, please checkout quantization/README.md for most up to date APIs" |
191 |
| - ) |
192 |
| - |
193 |
| - if filter_fn is None: |
194 |
| - filter_fn = lambda *args: _is_linear(*args) and _in_features_greater_than_16( |
195 |
| - *args |
196 |
| - ) |
197 |
| - |
198 |
| - _replace_with_custom_fn_if_matches_filter( |
199 |
| - model, |
200 |
| - _get_subclass_inserter( |
201 |
| - Int8DynamicallyQuantizedLinearWeight, enable_parametrization=False, **kwargs |
202 |
| - ), |
203 |
| - filter_fn, |
204 |
| - ) |
205 |
| - |
206 |
| - |
207 |
| -# TODO: delete |
208 |
| -def change_linear_weights_to_int8_woqtensors(model, filter_fn=None, **kwargs): |
209 |
| - """ |
210 |
| - Converts all linear weight tensors to the |
211 |
| - `Int8WeightOnlyQuantizedLinearWeight` tensor subclass, |
212 |
| - effectively applying the same form of quantization |
213 |
| - as apply_weight_only_int8_quant while not modifying the linear modules. |
214 |
| - """ |
215 |
| - raise ImportError( |
216 |
| - "This API is deprecated for pytorch 2.4+, please checkout quantization/README.md for most up to date APIs" |
217 |
| - ) |
218 |
| - |
219 |
| - _replace_with_custom_fn_if_matches_filter( |
220 |
| - model, |
221 |
| - _get_subclass_inserter( |
222 |
| - Int8WeightOnlyQuantizedLinearWeight, enable_parametrization=False, **kwargs |
223 |
| - ), |
224 |
| - _is_linear if filter_fn is None else filter_fn, |
225 |
| - ) |
226 |
| - |
227 |
| - |
228 |
| -# TODO: delete |
229 |
| -def change_linear_weights_to_int4_woqtensors( |
230 |
| - model, |
231 |
| - groupsize=128, |
232 |
| - inner_k_tiles=8, |
233 |
| - filter_fn=None, |
234 |
| - zero_point_domain=ZeroPointDomain.FLOAT, |
235 |
| - preserve_zero=False, |
236 |
| -): |
237 |
| - """ |
238 |
| - Converts all linear weight tensors to the |
239 |
| - `Int4WeightOnlyQuantizedLinearWeight` tensor subclass, |
240 |
| - effectively applying the same form of quantization |
241 |
| - as apply_dynamic_quant while not modifying the linear modules. |
242 |
| - Args: |
243 |
| - `groupsize`: parameter for quantization, controls the granularity of quantization, smaller |
244 |
| - size is more fine grained, choices are [256, 128, 64, 32] |
245 |
| - `inner_k_tiles`: parameter for int4 mm kernel, choices are [8, 4, 2] |
246 |
| - `filter_fn`: function that takes a nn.Module instance and fully qualified name of the module, \ |
247 |
| - returns True if we want to run `config` on |
248 |
| - `zero_point_domain`: data type of zeros points, choices are [ZeroPointDomain.FLOAT, \ |
249 |
| - ZeroPointDomain.INT, ZeroPointDomain.NONE] |
250 |
| - `preserve_zero`: whether to preserve zero, default is False |
251 |
| - """ |
252 |
| - raise ImportError( |
253 |
| - "This API is deprecated for pytorch 2.4+, please checkout quantization/README.md for most up to date APIs" |
254 |
| - ) |
255 |
| - |
256 |
| - if filter_fn is None: |
257 |
| - filter_fn = _is_linear |
258 |
| - |
259 |
| - _replace_with_custom_fn_if_matches_filter( |
260 |
| - model, |
261 |
| - _get_subclass_inserter( |
262 |
| - Int4WeightOnlyQuantizedLinearWeight, |
263 |
| - enable_parametrization=False, |
264 |
| - groupsize=groupsize, |
265 |
| - inner_k_tiles=inner_k_tiles, |
266 |
| - zero_point_domain=zero_point_domain, |
267 |
| - preserve_zero=preserve_zero, |
268 |
| - ), |
269 |
| - filter_fn, |
270 |
| - ) |
271 |
| - |
272 |
| - |
273 |
| -######## |
274 |
| -# TO BE DEPRECATED END |
275 |
| -######## |
276 |
| - |
277 |
| - |
278 | 175 | def _replace_with_custom_fn_if_matches_filter(
|
279 | 176 | model,
|
280 | 177 | replacement_fn,
|
|
0 commit comments