Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import error from quantization before PyTorch 2.3 #920

Merged
merged 1 commit into from
May 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion recipes/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class QuantizationRecipe:
multiple of groupsize.
`percdamp`: GPTQ stablization hyperparameter, recommended to be .01

8da4w:
8da4w (PyTorch 2.3+):
torchtune.utils.quantization.Int8DynActInt4WeightQuantizer
int8 per token dynamic activation with int4 weight only per axis group quantization
Args:
Expand Down
11 changes: 8 additions & 3 deletions torchtune/utils/quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
apply_weight_only_int8_quant,
Int4WeightOnlyGPTQQuantizer,
Int4WeightOnlyQuantizer,
Int8DynActInt4WeightQuantizer,
Quantizer,
)
from torchao.quantization.utils import TORCH_VERSION_AFTER_2_3

__all__ = [
"Int4WeightOnlyQuantizer",
"Int4WeightOnlyGPTQQuantizer",
"Int8WeightOnlyQuantizer",
"Int8DynActInt4WeightQuantizer",
"get_quantizer_mode",
]

Expand All @@ -36,10 +35,16 @@ def quantize(
Int4WeightOnlyQuantizer: "4w",
Int8WeightOnlyQuantizer: "8w",
Int4WeightOnlyGPTQQuantizer: "4w-gptq",
Int8DynActInt4WeightQuantizer: "8da4w",
}


if TORCH_VERSION_AFTER_2_3:
from torchao.quantization.quant_api import Int8DynActInt4WeightQuantizer

__all__.append("Int8DynActInt4WeightQuantizer")
_quantizer_to_mode[Int8DynActInt4WeightQuantizer] = "8da4w"


def get_quantizer_mode(quantizer: Optional[Callable]) -> Optional[str]:
"""Given a quantizer object, returns a string that specifies the type of quantization e.g.
4w, which means int4 weight only quantization.
Expand Down
Loading