-
Notifications
You must be signed in to change notification settings - Fork 25
Quant fallback to 8w per token + other quant improvements for multimodal #154
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
|
|
||
| import json | ||
| import logging | ||
| import os.path | ||
|
|
||
| import torchao | ||
|
|
@@ -201,15 +202,24 @@ def load_multimodal_text_to_text_model(model_name_or_path: str, **kwargs): | |
| qembedding_group_size = kwargs.get("qembedding_group_size", None) | ||
|
|
||
| # Quantize decoder linear weights. | ||
| if qlinear_config: | ||
| logging.info("Quantizing decoder linears...") | ||
| quantize_decoder_kwargs = { | ||
| "eager_model": getattr(eager_model, decoder_name), | ||
| "qlinear_config": qlinear_config, | ||
| } | ||
| quantize_lm_head_kwargs = { | ||
| "eager_model": eager_model.lm_head, | ||
| "qlinear_config": qlinear_config, | ||
| } | ||
|
Comment on lines
+211
to
+214
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you guard this by whether eager_model has There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, curious though is there a model without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah voxtral doesn't have |
||
| if qlinear_group_size is not None: | ||
| quantize_decoder_kwargs["qlinear_group_size"] = qlinear_group_size | ||
| quantize_model_(**quantize_decoder_kwargs) | ||
| quantize_model_(**quantize_lm_head_kwargs) | ||
|
|
||
| # Quantize encoder linear weights. | ||
| if qlinear_encoder_config: | ||
| logging.info("Quantizing encoder linears...") | ||
| quantize_encoder_kwargs = { | ||
| "eager_model": getattr(eager_model, encoder_name), | ||
| "qlinear_config": qlinear_encoder_config, | ||
|
|
@@ -218,19 +228,17 @@ def load_multimodal_text_to_text_model(model_name_or_path: str, **kwargs): | |
| quantize_encoder_kwargs["qlinear_group_size"] = qlinear_encoder_group_size | ||
| quantize_model_(**quantize_encoder_kwargs) | ||
|
|
||
| # TODO: quantize other parts of the model, e.g. MultimodalProjector? | ||
|
|
||
| # Quantize decoder embeddings. | ||
| if qembedding_config: | ||
| logging.info("Quantizing decoder embeddings...") | ||
| quantize_decoder_embedding_kwargs = { | ||
| "eager_model": getattr(eager_model, decoder_name), | ||
| "eager_model": eager_model, | ||
| "qembedding_config": qembedding_config, | ||
| } | ||
| if qembedding_group_size is not None: | ||
| quantize_decoder_embedding_kwargs["qembedding_group_size"] = qembedding_group_size | ||
| quantize_model_(**quantize_decoder_embedding_kwargs) | ||
|
|
||
| # TODO: quantize encoder embeddings. | ||
|
|
||
| return MultiModalTextToTextExportableModule( | ||
| model=eager_model, | ||
| modality="audio" if audio_encoder_name else "vision", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.