[quantization] Introduce wrapper for Qwen3VLVisionBlock#500
Merged
dayo09 merged 1 commit intoSamsung:mainfrom Mar 5, 2026
Merged
[quantization] Introduce wrapper for Qwen3VLVisionBlock#500dayo09 merged 1 commit intoSamsung:mainfrom
dayo09 merged 1 commit intoSamsung:mainfrom
Conversation
Contributor
Author
Reference CodeBelow is the source code of # transformers/models/qwen3_vl/modeling_qwen3_vl.py
class Qwen3VLVisionBlock(GradientCheckpointingLayer):
def __init__(self, config, attn_implementation: str = "sdpa") -> None:
super().__init__()
self.norm1 = nn.LayerNorm(config.hidden_size, eps=1e-6)
self.norm2 = nn.LayerNorm(config.hidden_size, eps=1e-6)
self.attn = Qwen3VLVisionAttention(config=config)
self.mlp = Qwen3VLVisionMLP(config=config)
def forward(
self,
hidden_states: torch.Tensor,
cu_seqlens: torch.Tensor,
rotary_pos_emb: torch.Tensor | None = None,
position_embeddings: tuple[torch.Tensor, torch.Tensor] | None = None,
**kwargs,
) -> torch.Tensor:
hidden_states = hidden_states + self.attn(
self.norm1(hidden_states),
cu_seqlens=cu_seqlens,
rotary_pos_emb=rotary_pos_emb,
position_embeddings=position_embeddings,
**kwargs,
)
hidden_states = hidden_states + self.mlp(self.norm2(hidden_states))
return hidden_states |
This change introduces QuantQwen3VLVisionBlock wrapper to support post-training quantization of Qwen3VLVisionBlock module. TICO-DCO-1.0-Signed-off-by: d.savchenkov <d.savchenkov@partner.samsung.com>
ff088fc to
4607679
Compare
dayo09
approved these changes
Mar 5, 2026
Contributor
dayo09
left a comment
There was a problem hiding this comment.
LGTM :-D
FYI, we will need to split heads of VLM vision attention blocks likewise we did in llama attention blocks.
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.
This change introduces
QuantQwen3VLVisionBlockwrapper to support post-training quantization ofQwen3VLVisionBlockmodule.Why?
Qwen3VLVisionBlockmodule is used in the image encoder part of Qwen model.Trying to quantize
Qwen3VLVisionBlockvia PTQ generates exceptionPTQQuantizer: no quantization wrapper for Qwen3VLVisionBlock.What
This change introduces:
QuantQwen3VLVisionBlock(tico/quantization/wrapq/wrappers/qwen_vl/quant_vision_block.py).class TestQuantQwen3VLVisionBlock(test/quantization/wrapq/wrappers/qwen_vl/test_quant_vision_block.py) - skipped iftransformerspackage is not installed._CORE_MODULES(tico/quantization/wrapq/wrappers/registry.py).Qwen3VLVisionBlockquantization and conversion to Circle (tico/quantization/wrapq/examples/qwen/quantize_vision_block.py).Unit Tests
Below unit tests run is presented along with coverage information (irrelevant files replaced with ellipsis ...):
Example Script