|
8 | 8 | import itertools |
9 | 9 | import re |
10 | 10 | import time |
| 11 | +import warnings |
11 | 12 | from functools import reduce |
12 | 13 | from importlib.metadata import version |
13 | 14 | from math import gcd |
14 | | -from typing import Any, Callable, Optional |
| 15 | +from typing import Any, Callable, Optional, Type |
15 | 16 |
|
16 | 17 | import torch |
17 | 18 | import torch.nn.utils.parametrize as parametrize |
@@ -367,6 +368,25 @@ def torch_version_at_least(min_version): |
367 | 368 | return parse_version(torch.__version__) >= parse_version(min_version) |
368 | 369 |
|
369 | 370 |
|
| 371 | +class _ConfigDeprecationWrapper: |
| 372 | + """ |
| 373 | + A deprecation wrapper that directs users from a deprecated "config function" |
| 374 | + (e.g. `int4_weight_only`) to the replacement config class. |
| 375 | + """ |
| 376 | + |
| 377 | + def __init__(self, deprecated_name: str, config_cls: Type): |
| 378 | + self.deprecated_name = deprecated_name |
| 379 | + self.config_cls = config_cls |
| 380 | + |
| 381 | + def __call__(self, *args, **kwargs): |
| 382 | + warnings.warn( |
| 383 | + f"`{self.deprecated_name}` is deprecated and will be removed in a future release. " |
| 384 | + f"Please use `{self.config_cls.__name__}` instead. Example usage:\n" |
| 385 | + f" quantize_(model, {self.config_cls.__name__}(...))" |
| 386 | + ) |
| 387 | + return self.config_cls(*args, **kwargs) |
| 388 | + |
| 389 | + |
370 | 390 | """ |
371 | 391 | Helper function for implementing aten op or torch function dispatch |
372 | 392 | and dispatching to these implementations. |
|
0 commit comments