Qualcomm AI Engine Direct - [GenAI Pipeline] Multimodal LLM & LLM Preparation and Quantization - #23050
Qualcomm AI Engine Direct - [GenAI Pipeline] Multimodal LLM & LLM Preparation and Quantization#23050DannyYuyang-quic wants to merge 1 commit into
Conversation
…Quantization
Add the LLM/MLLM GenAI pipeline integration for model preparation, dataset-driven calibration, and ExecuTorch quantization.
Summary:
- Add the GenAI pipeline CLI and stage context wiring.
- Add model registry lookup helpers for configs, graph builders, source
transforms, checkpoint loaders, quantization settings, and adapters.
- Add component-aware LLM/MLLM model preparation adapters for decoder,
embedding, vision, and audio modules.
- Add dataset adapters, collators, and dataset option for
calibration, training, and evaluation.
- Add ExecuTorch quantization support for export/prepare, encoding
initialization, calibration, encoding override, conversion, and QDQ EP save.
- Add source transforms for checkpoint remapping, dtype override, embedding
scaling, RoPE layout, RMSNorm offset, and linear-to-conv2d conversion.
- Expand unit coverage for model preparation, quantization, source transforms,
datasets, and pipeline stage behavior.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23050
Note: Links to docs will display an error until the docs builds have been completed. ❌ 14 Awaiting Approval, 1 New FailureAs of commit 4e19eb9 with merge base 9520b05 ( AWAITING APPROVAL - The following workflows need approval before CI can run:
NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "release notes: qualcomm" |
|
Hi @psiddh, TL;DR:This PR makes the GenAI Pipeline runnable through The existing Together with PR B1, Compilation Foundation (#22846), the following commands LLMpython -m backends.qualcomm.genai_pipeline.cli --model gemma3-1b --soc SM8750 --calib-samples examples/qualcomm/oss_scripts/llama/assets/samples/text.json --compile-only --max-seq-len 1024Multimodal LLMVision-Language modelpython -m backends.qualcomm.genai_pipeline.cli --model internvl3_1b --soc SM8750 --calib-samples examples/qualcomm/oss_scripts/llama/assets/samples/vision.json --compile-only --max-seq-len 1024Audio-Language modelpython -m backends.qualcomm.genai_pipeline.cli --model granite_speech_3_3-2b --soc SM8750 --calib-samples examples/qualcomm/oss_scripts/llama/assets/samples/audio --compile-only --max-seq-len 1024Please have a look. Thanks! |
Summary
First PR of Phase 2 Stream A. This PR makes the GenAI Pipeline runnable for
LLM and MLLM models through the front half of the flow:
examples/and the legacyllama.pypath remain unchanged. Compilation anddevice inference remain in Stream B / PR-A2.
What's Included
CLI Entry Point:
cli.pyAdds a GenAI Pipeline CLI that resolves model, dataset, and quantization options, builds
PipelineContext, and invokes model preparation and quantization. FP16 omits quantization; QAT, embedding quantization, and attention sink are rejected for now.The rejected feature will be raised in following PR.
Registry-Backed Model lookup:
model_lookup.pyMaps a user-facing model name to the model-specific inputs consumed by the pipeline. Callers resolve one registry config, then derive from that same entry:
decoder decode/quantize graphs, optional prefill graphs, and multimodal
embedding variants.
module G2G transforms, plus the Hugging Face state-dict loader when needed.
recipe classes, and LLM or MLLM loader/quantizer adapters.
This centralizes model-family branching at the registry boundary; the model preparation and quantization stages consume only the derived component and graph keyed configuration.
LLM and Multimodal LLM model components:
model_components/Adds pipeline import surfaces for decoder, token embedding, and encoder components over existing
examplesimplementations.Module G2G Transforms:
source_transform/:Collects existing
llama.pytransformations into reusable pipeline functions:LLM and MLLM Model Loading and Preparation:
strategies/model_preparation/:ExecuTorchModelPreparationStrategyimplements the shared preparation flow:extra_options.LLMLoaderAdapterhandles text decoders;MLLMLoaderAdapterhandles multimodal models. The default adapter owns shared tokenizer and transforms logic.Dataset stack:
datasets/Adds typed dataset options, lookup, loaders, calibration adapters, and LLM/MLLM collators. It supports random fallback data, lm-eval samples, JSON messages, Hugging Face chat datasets, and multimodal messages.
generate_calibration_data()now receivesexample_inputsexplicitly because collators require the calibration-graph signature.Quantization:
strategies/quantization/:ExecuTorchQuantizationStrategyimplements native PTQ for component and graph keyed models:Decoder and token embedding use separate quantize and deploy graphs; encoders use one shared graph. Encodings are propagated before lowering.
Quantizer creation belongs to the strategy; LLM/MLLM adapters own only model-family-specific export, preparation, conversion, and calibration.
Quantization Helpers:
quant_utilities.py:Provides QNN quantizer construction, recipe application, QDQ saving, logits/KV-cache attributes, and encoding propagation. KV-cache override is enabled only when
n_cache_layersis provided.Quantization Output
QuantizationOutputConfignow returns component and graph keyedGraphBundleobjects. Each bundle carries the quantized graph module, export inputs, metadata, and optional quantized IO dtypes.Quantize-only graphs are removed after their encodings have been propagated, so downstream compilation sees only deployment graphs.
Tests
Covers CLI/config construction, source transforms, datasets and collators, loader adapters, model preparation, quantization adapters and strategy, and preparation/quantization stage integration.
PR Review Checklist
TokenizerWrapper,torch.export, PT2E, QNN quantizer construction, datasetloading, and calibration execution sit behind adapters or lookup-created
callables.
examples/is not modified andllama.pyremains the reference path. - YesRelated PRs
Phase 2 flow. PR-A1 and PR-B1 are independent and can land in either order.
PR-B2 depends on PR-B1. PR-A2 depends on PR-A1 and PR-B2, and closes Phase 2 by wiring the runner and adding the parity test that gates Phase 3 deletion of the legacy flow.
Phase 1 (merged):
Phase 2:
dataset-backed calibration, component/graph-aware quantization, and encoding
reconciliation. [This PR].
Depends on PR-B1.
test. Depends on PR-A1 and PR-B2.
Test plan
Run only tests added in this PR:
Result:
Run all genai_pipeline tests:
Result:
Run all tests with coverage:
Result:
Confirm the legacy flow is unaffected:
Result: