Skip to content

Add Vulkan Quantizer to Llama export lib #6169

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

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 8 additions & 0 deletions examples/models/llama2/export_llama_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
get_pt2e_quantization_params,
get_pt2e_quantizers,
get_qnn_quantizer,
get_vulkan_quantizer,
)
from executorch.util.activation_memory_profiler import generate_memory_trace

Expand Down Expand Up @@ -147,6 +148,7 @@ def build_args_parser() -> argparse.ArgumentParser:
"coreml_8a_c4w",
"coreml_baseline_8a_c8w",
"coreml_baseline_8a_c4w",
"vulkan_8w",
],
help="Use PT2E quantization. Comma separated options. e.g. xnnpack_dynamic (for per channel 8 bit weight), xnnpack_dynamic_qc4 (for per channel 4 bit weight), embedding.",
)
Expand Down Expand Up @@ -548,6 +550,12 @@ def get_quantizer_and_quant_params(args):
assert len(quantizers) == 0, "Should not enable both xnnpack / qnn and coreml"
coreml_quantizer = get_coreml_quantizer(args.pt2e_quantize)
quantizers.append(coreml_quantizer)
if args.vulkan and args.pt2e_quantize:
assert (
len(quantizers) == 0
), "Should not enable both vulkan and other quantizers"
vulkan_quantizer = get_vulkan_quantizer(args.pt2e_quantize)
quantizers.append(vulkan_quantizer)
logging.info(f"Applying quantizers: {quantizers}")
return pt2e_quant_params, quantizers, quant_dtype

Expand Down
1 change: 1 addition & 0 deletions extension/llm/export/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ runtime.python_library(
"//executorch/backends/qualcomm/quantizer:quantizer",
"//executorch/backends/transforms:duplicate_dynamic_quant_chain",
"//executorch/backends/vulkan/partitioner:vulkan_partitioner",
"//executorch/backends/vulkan/quantizer:vulkan_quantizer",
"//executorch/backends/xnnpack/partition:xnnpack_partitioner",
"//executorch/exir:lib",
"//executorch/exir/backend:backend_details",
Expand Down
19 changes: 19 additions & 0 deletions extension/llm/export/quantizer_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,22 @@ def get_coreml_quantizer(pt2e_quantize: str):
raise ValueError(f"Unsupported Core ML quantizer specification {pt2e_quantize}")

return quantizer


def get_vulkan_quantizer(pt2e_quantize: str):
from executorch.backends.vulkan.quantizer.vulkan_quantizer import (
get_weight_quantization_config,
VulkanQuantizer,
)

if pt2e_quantize == "vulkan_8w":
config = get_weight_quantization_config(
is_per_channel=True,
weight_qmin=-128,
weight_qmax=127,
)
else:
raise ValueError(f"Unsupported Vulkan quantizer specification {pt2e_quantize}")

quantizer = VulkanQuantizer().set_global(config)
return quantizer
Loading