Qualcomm AI Engine Direct - HF LLM Optimization Stage 1 - #22170
Open
winskuo-quic wants to merge 1 commit into
Open
Qualcomm AI Engine Direct - HF LLM Optimization Stage 1#22170winskuo-quic wants to merge 1 commit into
winskuo-quic wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22170
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 8fdf21c with merge base d750618 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
winskuo-quic
marked this pull request as ready for review
August 26, 2026 08:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
As HF use case is increasing, we aim to align accuracy and performance of HF LLM with Static LLM(static_llama.py).
Currently, there are many gaps, and we have a series of PR to fill the gaps.
For now, we will first focus on Llama3.2 1B decode mode.
What is done
examples/qualcomm/oss_scripts/llm_utils/hf_llm_quant_recipe.py. The quantization technique is mostly migrated fromexecutorch/examples/qualcomm/oss_scripts/llama/static_llm_quant_recipe.py, with some minor changes, especially the weight naming as HF-LLM and Static-LLM structure naming is different.seq_len. This increases the memory consumption and is also bad for performance. To resolve this issue, we have implementedQnnCustomStaticCacheso mode now only outputs the new pair of kv-cache.inv_freqAdditionally, since we are precomputing rope, we can also improve performance.annotate_kv_8bitin the mainline. This issue is happens during v_proj linear node. When these 2 are used together, thepermuteandview_copywill be tagged as 16bit, so it becomes conv(16bit) ->permute(16bit) -> view_copy(16bit) -> cast(8bit). This is bad and different from static llama since if we insert cast(8bit) right after conv(16bit), rest of the ops can run in 8bits, which is faster. After this change, the behavior now aligns with static llama, which is conv(16bit) -> cast(8bit) ->permute(8bit) -> view_copy(8bit).Optimization Result Compared with Llama3.2 1B_instruct (HF uses non-instruct verison)
For now, accuracy is not compared as HF flow has not yet support SQNR evaluation. Official accuracy features will be supported in Upcoming PRs. However, this PR did ensure HF output is reasonable and readable.
Sample Script
python examples/qualcomm/oss_scripts/hf_causal_lm.py --prompt "Simply put, the theory of relativity states that" --soc_model SM8750 --device $DEVICE --build_folder build-android/ --decoder_model llama3_2-1b --max_seq_len 1024Upcoming Features
Performance & Accuracy
Feature
Test plan
pytest backends/qualcomm/tests/rework/passes/test.py -k "test_fuse_consecutive_reshape"pytest backends/qualcomm/tests/rework/passes/test.py -k "test_convert_linear_to_conv2d"python backends/qualcomm/tests/test_qnn_delegate.py TestExampleLLMScript.test_hf_causal_lm --device $DEVICE--soc_model SM8750 --build_folder build-android --executorch_root . --artifact_dir ./llama3_2_1b --model_name llama3_2-1b