qnn_llama_runner on SA8295 outputs repetitive “sp” with Qwen3-1.7B after ExecuTorch export
🐛 Describe the bug
use main commit b4d72f1e271915e9c0e1d313753a1eec840fbdee
I have tried some settings, the setting:( when I use other setting, the convert would be failed, and the error " some op has incorrect Value 68, expected >= 73" or " [ERROR] [Qnn ExecuTorch]: fa_alloc.cc:2462::ERROR:graph requires estimated allocation of 2315388 KB, limit is 2097152 KB [ERROR] [Qnn ExecuTorch]: graph_prepare.cc:845::ERROR:error during serialize: memory usage too large",
When using default_quant_dtype = QuantDtype.use_8a8w and disabling the 16a4w_block quantization, the quantization/conversion completes successfully ` class Qwen3_1_7BQuantRecipe(StaticLLMQuantRecipe): default_quant_dtype = QuantDtype.use_8a8w def init(self, verbose: bool = False): super().init()
self.recipe = (
QuantRecipe(
self.default_quant_dtype,
False,
act_observer=MinMaxObserver,
granularity=QuantGranularity.PER_TENSOR,
verbose=verbose,
)
.add_regex(
{
r"output\.conv",
},
QuantDtype.use_16a8w,
False,
act_observer=MinMaxObserver,
granularity=QuantGranularity.PER_CHANNEL,
)
)
self.recipe.custom_quant_annotations.append(annotate_kv_8bit)
`
however, when running qnn_llama_runner with Qwen3-1.7B converted via ExecuTorch (hybrid QNN .pte) on a Qualcomm SA8295 device, the model generates a long sequence of “sp” .
<|im_start|>user what is 1+1<|im_end|> <|im_start|>assistant.addHandlertoHaveBeenCalled sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp
I hope to get your help or suggestions. Thanks very much.
Versions
commit b4d72f1e271915e9c0e1d313753a1eec840fbdee
cc @cccclai @winskuo-quic @shewu-quic @haowhsu-quic @DannyYuyang-quic @cbilgin
@cccclai @abhinaykukkadapu can you or someone from qualcomm take a look
I think using 8bit activation won't work very well, because activation is very sparse and we need 16bit. Can you try 16a8w?
Regarding the error message
I have tried some settings, the setting:( when I use other setting, the convert would be failed, and the error
" some op has incorrect Value 68, expected >= 73"
or
" [ERROR] [Qnn ExecuTorch]: fa_alloc.cc:2462::ERROR:graph requires estimated allocation of 2315388 KB, limit is 2097152 KB [ERROR] [Qnn ExecuTorch]: graph_prepare.cc:845::ERROR:error during serialize: memory usage too large",
What's SoC you're using? I think there are two issues here
- 16a4w_block is only supported for HTP arch > v73
- It seems like you're trying a much large context length or somehow it's requesting more memory than HTP can handle. Can you try enable more sharding?
Changing the issue type because it's not really a bug and add documentation here https://github.com/pytorch/executorch/pull/15965
I think using 8bit activation won't work very well, because activation is very sparse and we need 16bit. Can you try 16a8w?
Regarding the error message
I have tried some settings, the setting:( when I use other setting, the convert would be failed, and the error " some op has incorrect Value 68, expected >= 73" or " [ERROR] [Qnn ExecuTorch]: fa_alloc.cc:2462::ERROR:graph requires estimated allocation of 2315388 KB, limit is 2097152 KB [ERROR] [Qnn ExecuTorch]: graph_prepare.cc:845::ERROR:error during serialize: memory usage too large",What's SoC you're using? I think there are two issues here
- 16a4w_block is only supported for HTP arch > v73
- It seems like you're trying a much large context length or somehow it's requesting more memory than HTP can handle. Can you try enable more sharding?
I have disabled 16a4w_block. and using default_quant_dtype = QuantDtype.use_16a8w and setting num_sharding = 2 (for the error memory limit) , the quantization/conversion is ok!
' class Qwen3_1_7BQuantRecipe(StaticLLMQuantRecipe): default_quant_dtype = QuantDtype.use_16a8w
def __init__(self, verbose: bool = False):
super().__init__()
self.recipe = (
QuantRecipe(
self.default_quant_dtype,
False,
act_observer=MinMaxObserver,
granularity=QuantGranularity.PER_TENSOR,
verbose=verbose,
)
# .add_node_target(
# {
# torch.ops.aten.conv2d.default,
# },
# QuantDtype.use_16a4w_block,
# False,
# act_observer=MinMaxObserver,
# granularity=QuantGranularity.PER_BLOCK,
# extra_kwargs={"block_size": (1, 16, 1, 1)},
# )
.add_regex(
{
r"output\.conv",
},
QuantDtype.use_16a8w,
False,
act_observer=MinMaxObserver,
granularity=QuantGranularity.PER_CHANNEL,
)
)
self.recipe.custom_quant_annotations.append(annotate_kv_8bit)`
` INFO:root:*** qwen3-1_7b *** +-----------------------+-----------------------+ | Config | Value | +=======================+=======================+ | decoder_model_version | qwen3 | +-----------------------+-----------------------+ | instruct_model | True | +-----------------------+-----------------------+ | masked_softmax | True | +-----------------------+-----------------------+ | num_sharding | 2 | +-----------------------+-----------------------+ | quant_recipe | Qwen3_1_7BQuantRecipe | +-----------------------+-----------------------+ | r1 | False | +-----------------------+-----------------------+ | r2 | False | +-----------------------+-----------------------+ | r3 | False | +-----------------------+-----------------------+ | repo_id | Qwen/Qwen3-1.7B | +-----------------------+-----------------------+ | seq_mse_candidates | 0 | +-----------------------+-----------------------+ | transform_weight | False | +-----------------------+-----------------------+
` With above setting, the quantization/conversion is ok. While, when I test the pte on the device 8295, for some prompts, the output may include some repetitive statements.
`<|im_start|>user
write a paper about the Spring in Chinese.<|im_end|>
<|im_start|>assistant
First, I need to check the user's intention. They might be looking for a paper on the Spring Festival in China, which is a traditional holiday in China. The Spring Festival in China is celebrated on the 1st day of the lunar new year, and it's a time when people gather together, exchange traditional activities, and enjoy the festival. So the paper should discuss the significance, customs, and cultural aspects of the Spring Festival in China.
Now, I need to structure the paper. Maybe start with an introduction about the Spring Festival in China, then discuss its significance, then talk about the customs, then mention the cultural aspects, then conclude with the importance of the festival.
But the user might have a different intention. For example, if the user is referring to the Spring Festival in the Chinese context, then the paper should be about the significance, customs, and cultural aspects of the Spring Festival in China. So I need to write a paper on that.
But the user might have a different intention. For example, if the user is referring to the Spring Festival in the Chinese context, then the paper should be about the significance, customs, and cultural aspects of the Spring Festival in China.
So, I need to write a paper on the Spring Festival in China. Let me start with an introduction about the Spring Festival in China, then discuss its significance, then talk about the customs, then mention the cultural aspects, then conclude with the importance of the festival.
But the user might have a different intention. For example, if the user is referring to the Spring Festival in the Chinese context, then the paper should be about the significance, customs, and cultural aspects of the Spring Festival in China.
So, I need to write a paper on the Spring Festival in China. Let me start with an introduction about the Spring Festival in China, then discuss its significance, then talk about the customs, then mention the cultural aspects, then conclude with the importance of the festival. `
When I use the version Commit 763a474, the output is normal.
' class Qwen3_1_7BQuantRecipe(StaticLLMQuantRecipe): default_quant_dtype = QuantDtype.use_16a8w
def __init__(self, verbose: bool = False): super().__init__() self.recipe = ( QuantRecipe( self.default_quant_dtype, False, act_observer=MinMaxObserver, granularity=QuantGranularity.PER_TENSOR, verbose=verbose, ) # .add_node_target( # { # torch.ops.aten.conv2d.default, # }, # QuantDtype.use_16a4w_block, # False, # act_observer=MinMaxObserver, # granularity=QuantGranularity.PER_BLOCK, # extra_kwargs={"block_size": (1, 16, 1, 1)}, # ) .add_regex( { r"output\.conv", }, QuantDtype.use_16a8w, False, act_observer=MinMaxObserver, granularity=QuantGranularity.PER_CHANNEL, ) ) self.recipe.custom_quant_annotations.append(annotate_kv_8bit)`
Hi @lansexinhu,
Based on your quantization recipe above, you commented out the target annotation for torch.ops.aten.conv2d.default. As a result, all conv2d targets will default to per-tensor granularity instead of per-channel. In commit https://github.com/pytorch/executorch/commit/763a4747b0f23d31a9b568d800954de928603ebd, all conv2d was configured for 16a8w per-channel quantization by default.
If you want to align the quantization settings, you’ll need to add the following item in recipe:
add_node_target(
{
torch.ops.aten.conv2d.default,
},
QuantDtype.use_16a8w,
False,
act_observer=MinMaxObserver,
granularity=QuantGranularity.PER_CHANNEL,
)
You can also review granularity in the summary table to see whether conv2d uses per-channel quantization.
+---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+
| module_stack | op_target | quantize | act_observer | granularity | note | extra_kwargs |
+=================================+========================+===============+================+===============+========+================+
...
+---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+
| layers.0.attention | aten.transpose.int | use_16a4w/PTQ | MinMaxObserver | PER_TENSOR | | {} |
+---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+
| layers.0.attention.wq_conv | aten.conv2d.default | use_16a4w/PTQ | MinMaxObserver | PER_CHANNEL | | {} |
+---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+
| layers.0.attention.wk_conv | aten.conv2d.default | use_16a4w/PTQ | MinMaxObserver | PER_CHANNEL | | {} |
+---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+
| layers.0.attention.wv_conv | aten.conv2d.default | use_16a4w/PTQ | MinMaxObserver | PER_CHANNEL | | {} |
+---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+
...
You can also review granularity in the summary table to see whether conv2d uses per-channel quantization.
+---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+ | module_stack | op_target | quantize | act_observer | granularity | note | extra_kwargs | +=================================+========================+===============+================+===============+========+================+ ... +---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+ | layers.0.attention | aten.transpose.int | use_16a4w/PTQ | MinMaxObserver | PER_TENSOR | | {} | +---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+ | layers.0.attention.wq_conv | aten.conv2d.default | use_16a4w/PTQ | MinMaxObserver | PER_CHANNEL | | {} | +---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+ | layers.0.attention.wk_conv | aten.conv2d.default | use_16a4w/PTQ | MinMaxObserver | PER_CHANNEL | | {} | +---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+ | layers.0.attention.wv_conv | aten.conv2d.default | use_16a4w/PTQ | MinMaxObserver | PER_CHANNEL | | {} | +---------------------------------+------------------------+---------------+----------------+---------------+--------+----------------+ ...
ok. Thanks for your help. Actually, I have tried to set conv2d quantization by per-channel throught .add_regex, but some conv2d used per-tensor. I will try following item in recipe:
add_node_target( { torch.ops.aten.conv2d.default, }, QuantDtype.use_16a8w, False, act_observer=MinMaxObserver, granularity=QuantGranularity.PER_CHANNEL, )
Sounds good! add_node_target is the most explicit way to ensure all conv2d use per-channel quantization. If you need more fine-grained precision settings for specific parts of the model stack (e.g., output.conv) on top of your existing recipe, you can add regex patterns. Let me know if you run into any issues!
all conv2d layers are quantized using per-channel and16a8w, and the model output is normal. Does this imply that per-channel and16a8w is strictly required for all conv2d layers? If I’d like to reduce memory usage for Qwen3-1.7B on the SA8295 (V68), do you have any recommendations?
all conv2d layers are quantized using per-channel and16a8w, and the model output is normal. Does this imply that per-channel and16a8w is strictly required for all conv2d layers?
Yes. That’s because conv2d weights typically have large variance across channels, so per-channel quantization is critical for maintaining accuracy.
If I’d like to reduce memory usage for Qwen3-1.7B on the SA8295 (V68), do you have any recommendations?
A good starting point is mixed precision. Identify which conv2d layers are most sensitive, typically the ones with larger scales, and keep 16a8w per-channel for those to maintain stability. For layers that aren’t as sensitive, you can drop down to 16a4w per-channel to save memory.
I think this approach will gives you a balance between accuracy and memory efficiency.
We’ve applied similar mixed-precision strategies successfully on models like: llama1b llama3b, gemma3
all conv2d layers are quantized using per-channel and16a8w, and the model output is normal. Does this imply that per-channel and16a8w is strictly required for all conv2d layers?
Yes. That’s because conv2d weights typically have large variance across channels, so per-channel quantization is critical for maintaining accuracy.
If I’d like to reduce memory usage for Qwen3-1.7B on the SA8295 (V68), do you have any recommendations?
A good starting point is mixed precision. Identify which conv2d layers are most sensitive, typically the ones with larger scales, and keep
16a8w per-channelfor those to maintain stability. For layers that aren’t as sensitive, you can drop down to16a4w per-channelto save memory. I think this approach will gives you a balance between accuracy and memory efficiency.We’ve applied similar mixed-precision strategies successfully on models like: llama1b llama3b, gemma3
Okay, I'm running some experiments based on your suggestions. Thank you!
all conv2d layers are quantized using per-channel and16a8w, and the model output is normal. Does this imply that per-channel and16a8w is strictly required for all conv2d layers?
Yes. That’s because conv2d weights typically have large variance across channels, so per-channel quantization is critical for maintaining accuracy.
If I’d like to reduce memory usage for Qwen3-1.7B on the SA8295 (V68), do you have any recommendations?
A good starting point is mixed precision. Identify which conv2d layers are most sensitive, typically the ones with larger scales, and keep
16a8w per-channelfor those to maintain stability. For layers that aren’t as sensitive, you can drop down to16a4w per-channelto save memory. I think this approach will gives you a balance between accuracy and memory efficiency. We’ve applied similar mixed-precision strategies successfully on models like: llama1b llama3b, gemma3Okay, I'm running some experiments based on your suggestions. Thank you! May I ask if you encountered the following problems when loading tokenizer.json https://github.com/pytorch/executorch/issues/11311