Skip to content

Add CCL support to Gemma4, Qwen3.5 (moe), and qwn3_vl models - #1188

Open
vjanfaza wants to merge 3 commits into
quic:mainfrom
vjanfaza:CCL-Master
Open

Add CCL support to Gemma4, Qwen3.5 (moe), and qwn3_vl models#1188
vjanfaza wants to merge 3 commits into
quic:mainfrom
vjanfaza:CCL-Master

Conversation

@vjanfaza

@vjanfaza vjanfaza commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Enable the compute-context-length (CCL) feature for the Gemma4 and Qwen3.5 image-text-to-text model families and fix CCL specialization gating so it also works for disaggregated (separate prefill/decode) serving.

Gemma4 (modeling_gemma4.py):

  • Thread comp_ctx_lengths through the text model, decoder layer, and attention so the exported ONNX actually consumes it: slice the attention mask to the CCL width and pass "CCL" into cache_kwargs (mirrors Gemma3).
  • Fix the dummy comp_ctx_lengths input dtype (int8 -> int64) so the traced ONNX input matches the int64 runtime buffer.
  • Split the "prefill and decode" specialization gate into an OR so CCL is honored when only one of the prefill/decode lists is provided.

Qwen3.5 (modeling_qwen3_5.py, modeling_qwen3_5_moe.py):

  • Fix the dummy comp_ctx_lengths input dtype (int8 -> int64).
  • Add the missing comp_ctx_lengths pass-through on the MoE full-model forwards (QEffQwen3_5MoeModel, QEffQwen3_5MoeForConditionalGeneration) to match the non-MoE variant.
  • Allow decode-only CCL specialization (gate -> OR, guard prefill loop).

Qwen3.5-VL (modeling_qwen3_vl.py, modeling_qwen3_vl_moe.py):

  • Allow decode-only CCL specialization and guard both prefill/decode loops with or [] to avoid a TypeError when one list is None (disaggregated serving).

Examples (gemma4_example.py, gemma4_utils.py):

  • Carry comp_ctx_lengths_prefill/decode through build_compile_kwargs and document CCL activation in the example.

Important points to consider:

  • In this support, for gemma4 and qwen3_5 models the use_onnx_subfunctions should be False to have CCL feature actually work for these models otherwise it will be compiled but CCL won't be effective. Related ongoing work is in progress to solve the source of this issue.
  • I've already raised the following Jira ticket for this issue. Please track the changes there:
    https://jira-dc.qualcomm.com/jira/browse/QRANIUMSW-63142

Enable the compute-context-length (CCL) feature for the Gemma4 and Qwen3.5
image-text-to-text model families and fix CCL specialization gating so it
also works for disaggregated (separate prefill/decode) serving.

Gemma4 (modeling_gemma4.py):
- Thread comp_ctx_lengths through the text model, decoder layer, and
  attention so the exported ONNX actually consumes it: slice the attention
  mask to the CCL width and pass "CCL" into cache_kwargs (mirrors Gemma3).
- Fix the dummy comp_ctx_lengths input dtype (int8 -> int64) so the traced
  ONNX input matches the int64 runtime buffer.
- Split the "prefill and decode" specialization gate into an OR so CCL is
  honored when only one of the prefill/decode lists is provided.

Qwen3.5 (modeling_qwen3_5.py, modeling_qwen3_5_moe.py):
- Fix the dummy comp_ctx_lengths input dtype (int8 -> int64).
- Add the missing comp_ctx_lengths pass-through on the MoE full-model
  forwards (QEffQwen3_5MoeModel, QEffQwen3_5MoeForConditionalGeneration)
  to match the non-MoE variant.
- Allow decode-only CCL specialization (gate -> OR, guard prefill loop).

Qwen3.5-VL (modeling_qwen3_vl.py, modeling_qwen3_vl_moe.py):
- Allow decode-only CCL specialization and guard both prefill/decode loops
  with `or []` to avoid a TypeError when one list is None (disaggregated
  serving).

Examples (gemma4_example.py, gemma4_utils.py):
- Carry comp_ctx_lengths_prefill/decode through build_compile_kwargs and
  document CCL activation in the example.

Signed-off-by: Vahid Janfaza <vjanfaza@qti.qualcomm.com>
@vjanfaza vjanfaza changed the title Add CCL support to Gemma4 and Qwen3.5 models Add CCL support to Gemma4, Qwen3.5 (moe), and qwn3_vl models Jul 17, 2026
@quic-hemagnih

Copy link
Copy Markdown
Contributor

Can you please update the example script for one of the QWEN3 or QWEN3.5 model for CCL. Also do post the results in the comments after execution via QEfficient.

@quic-hemagnih quic-hemagnih left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you post the execution results via QEFF, and update one of the QWEN3/3.5 example script

Document how to activate the compute-context-length (CCL) feature in the
image-text-to-text example scripts: pass qaic_config={"ccl_enabled": True}
at from_pretrained and comp_ctx_lengths_prefill / comp_ctx_lengths_decode
to compile().

- gemma4_example.py: update the CCL sample lists.
- qwen3_5/qwen3_5.py, qwen3_5_moe/qwen3_5_moe.py: enable CCL and pass the
  CCL lists into both the text-only and vision+text compile() calls.
- qwen3_vl_moe/qwen3_vl_moe.py: enable CCL and pass the CCL lists into
  both compile() calls.
- qwen3vl/qwen3_vl.py: add commented CCL activation as a reference.

Signed-off-by: Vahid Janfaza <vjanfaza@qti.qualcomm.com>
@vjanfaza

Copy link
Copy Markdown
Contributor Author

Can you post the execution results via QEFF, and update one of the QWEN3/3.5 example script

I added CCL related changes but they are commented by default

Refresh the commented-out compute-context-length (CCL) sample lists in the
image-text-to-text example scripts. CCL stays deactivated by default (the
qaic_config ccl_enabled block and comp_ctx_lengths_* compile args remain
commented out); users uncomment them to enable CCL. Note that CCL requires
use_onnx_subfunctions=False.

Files: gemma4_example.py, qwen3_5/qwen3_5.py, qwen3_5_moe/qwen3_5_moe.py,
qwen3_vl_moe/qwen3_vl_moe.py, qwen3vl/qwen3_vl.py

Signed-off-by: Vahid Janfaza <vjanfaza@qti.qualcomm.com>
@vjanfaza

Copy link
Copy Markdown
Contributor Author

Can you post the execution results via QEFF, and update one of the QWEN3/3.5 example script

I have created the following confluence page:
https://qualcomm-confluence.atlassian.net/wiki/spaces/QRAN/pages/3378664571/Benchmarking-Gemma4-Qwen3.5+moe+-Qwen3-vl+moe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants