-
Notifications
You must be signed in to change notification settings - Fork 536
Updates torchao pin to enable shared embedding quantization #9548
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
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 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -155,6 +155,11 @@ def build_args_parser() -> argparse.ArgumentParser: | |||||||||||||||||
type=str, | ||||||||||||||||||
help="type of embedding quantization, '<bitwidth>,<groupsize>', e.g., '8,1024'.", | ||||||||||||||||||
) | ||||||||||||||||||
parser.add_argument( | ||||||||||||||||||
"--use_shared_embedding", | ||||||||||||||||||
action="store_true", | ||||||||||||||||||
help="Whether the embedding/unembedding weights should be shared. Only available with torchao kernels.", | ||||||||||||||||||
) | ||||||||||||||||||
parser.add_argument( | ||||||||||||||||||
"--pt2e_quantize", | ||||||||||||||||||
default=None, | ||||||||||||||||||
|
@@ -684,6 +689,15 @@ def _validate_args(args): | |||||||||||||||||
if args.num_sharding > 0 and not args.qnn: | ||||||||||||||||||
raise ValueError("Model shard is only supported with qnn backend now.") | ||||||||||||||||||
|
||||||||||||||||||
if args.use_shared_embedding: | ||||||||||||||||||
if not ( | ||||||||||||||||||
args.embedding_quantize is not None | ||||||||||||||||||
and args.embedding_quantize.startswith("torchao:") | ||||||||||||||||||
Comment on lines
+692
to
+695
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.
Suggested change
nit: nested conditionals into an error |
||||||||||||||||||
): | ||||||||||||||||||
raise ValueError( | ||||||||||||||||||
"Shared embedding is only supported with torchao quantization." | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
if ( | ||||||||||||||||||
args.quantization_mode is not None | ||||||||||||||||||
and args.quantization_mode.startswith("torchao:") | ||||||||||||||||||
|
@@ -1122,6 +1136,21 @@ def _get_source_transforms( # noqa | |||||||||||||||||
|
||||||||||||||||||
transforms.append(inject_fast_hadamard_transform_native_for_spin_quant) | ||||||||||||||||||
|
||||||||||||||||||
if args.embedding_quantize: | ||||||||||||||||||
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. Why did we change the order of the source transform? 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. shared_embedding must be applied before linear. So I changed order to embedding first, and linear second. I put a code comment to this effect as well. |
||||||||||||||||||
""" | ||||||||||||||||||
When this option is selected, it finds all embedding layers and transforms | ||||||||||||||||||
into quantized embedding equivalent module. | ||||||||||||||||||
|
||||||||||||||||||
There are cases where the checkpoint is already quantized, for example | ||||||||||||||||||
on use_spin_quant is enabled. In that case, it will do the appropriate | ||||||||||||||||||
transformations based on the given checkpoint first. In those cases, | ||||||||||||||||||
this wil be a no-op. | ||||||||||||||||||
""" | ||||||||||||||||||
modelname = f"{modelname}_e" | ||||||||||||||||||
transforms.append(get_quant_embedding_transform(args, checkpoint_dtype)) | ||||||||||||||||||
|
||||||||||||||||||
# quantization_mode should be applied after embedding_quantize | ||||||||||||||||||
# to support shared_embedding | ||||||||||||||||||
if args.quantization_mode: | ||||||||||||||||||
""" | ||||||||||||||||||
When this option is selected, it finds all linear layers and transforms | ||||||||||||||||||
|
@@ -1145,19 +1174,6 @@ def _get_source_transforms( # noqa | |||||||||||||||||
) | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
if args.embedding_quantize: | ||||||||||||||||||
""" | ||||||||||||||||||
When this option is selected, it finds all embedding layers and transforms | ||||||||||||||||||
into quantized embedding equivalent module. | ||||||||||||||||||
|
||||||||||||||||||
There are cases where the checkpoint is already quantized, for example | ||||||||||||||||||
on use_spin_quant is enabled. In that case, it will do the appropriate | ||||||||||||||||||
transformations based on the given checkpoint first. In those cases, | ||||||||||||||||||
this wil be a no-op. | ||||||||||||||||||
""" | ||||||||||||||||||
modelname = f"{modelname}_e" | ||||||||||||||||||
transforms.append(get_quant_embedding_transform(args, checkpoint_dtype)) | ||||||||||||||||||
|
||||||||||||||||||
if args.expand_rope_table: | ||||||||||||||||||
transforms.append(materialze_broadcast_of_rope_freq_cis) | ||||||||||||||||||
|
||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR, but what's the plan for updating our arg selection scheme for quant?
-E "torchao:4,32,true
isn't user friendlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd never need to do that. true is the default (and existing behavior), so you could continue to use -E"torchao:4,32".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make this a bit more clear that shared is only for torchao kernels, or
torchao:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's under the torchao section of the docs.