Skip to content

Add qwen3vl support - #3463

Open
yatish04 wants to merge 1 commit into
mlc-ai:mainfrom
yatish04:qwen3-vl
Open

Add qwen3vl support#3463
yatish04 wants to merge 1 commit into
mlc-ai:mainfrom
yatish04:qwen3-vl

Conversation

@yatish04

Copy link
Copy Markdown

No description provided.

@yatish04 yatish04 changed the title update qwen3vl code Add qwen3vl support Mar 26, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces support for the Qwen3-VL model, including its configuration, conversation template, and architecture, while refactoring the model registry to use explicit quantization mappings. The reviewer noted that the implementation is currently incomplete, as several critical methods in the Qwen3-VL model and text-processing components are stubs or raise NotImplementedError. Key feedback includes correcting multiple "CasualLM" typos, fixing the gorilla module name, updating incorrect model references in error messages, and addressing issues with commented-out code, type hints, and indentation.

Comment on lines +184 to +204
def forward(
self,
input_ids: Tensor = None,
attention_mask: Optional[Tensor] = None,
position_ids: Optional[Tensor] = None,
past_key_values: Optional["Cache"] = None,
inputs_embeds: Optional[Tensor] = None,
pixel_values: Optional[Tensor] = None,
pixel_values_videos: Optional[Tensor] = None,
image_grid_thw: Optional[Tensor] = None,
video_grid_thw: Optional[Tensor] = None,
cache_position: Optional[Tensor] = None,
**kwargs,
):
r"""
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
The temporal, height and width of feature shape of each image in LLM.
video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
The temporal, height and width of feature shape of each video in LLM.
"""
raise NotImplementedError

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.

critical

The forward method of Qwen3VLModel raises NotImplementedError and contains a large block of commented-out PyTorch code. This is a critical part of the model implementation that is missing. Please implement the forward pass for the Qwen3VLModel in TVM/Relax.

Comment on lines +59 to +61
def forward(self, x, position_ids):
# TODO: translate from pytorch to tvm
raise NotImplementedError

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.

critical

The forward method in LlamaRotaryEmbedding raises NotImplementedError. Multiple other methods in this file (Qwen3VLTextRotaryEmbedding.forward, Qwen3VLTextAttention.forward, Qwen3VLTextDecoderLayer.forward, Qwen3VLTextModel.forward) are also unimplemented skeletons. This makes the text-processing part of the model non-functional.

This is a critical issue. Please implement the logic for these methods.

Comment on lines +300 to +306
def prefill(self, input_embed: Tensor, paged_kv_cache: PagedKVCache):
b, s, d = input_embed.shape
return op.zeros((b, s, self.config.text_config.vocab_size), dtype="float32"), paged_kv_cache

def decode(self, input_embed: Tensor, paged_kv_cache: PagedKVCache):
b, s, d = input_embed.shape
return op.zeros((b, s, self.config.text_config.vocab_size), dtype="float32"), paged_kv_cache

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.

critical

The prefill and decode methods in Qwen3VLForConditionalGeneration are stubs that return tensors of zeros. This makes the model non-functional as it will not produce any meaningful output. Please implement the correct logic for these methods.

"mistral": Model(
name="mistral",
model=mistral_model.MistralForCausalLM,
model=mistral_model.MistralForCasualLM,

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.

high

There's a typo in the class name. It should be MistralForCausalLM, not MistralForCasualLM. This "Casual" typo appears for several other models in this file:

  • mixtral (line 209)
  • rwkv5 (line 480)
  • orion (line 494)
  • llava (line 507)
  • rwkv6 (line 522)
  • eagle (line 548)

Please correct all occurrences.

Suggested change
model=mistral_model.MistralForCasualLM,
model=mistral_model.MistralForCausalLM,

)
else:
raise ValueError(
"Invalid DeepSeek model quantization config: unrecognized quantization config: "

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.

medium

The error message refers to "DeepSeek model". It should be "Qwen3-VL model" to avoid confusion.

Suggested change
"Invalid DeepSeek model quantization config: unrecognized quantization config: "
"Invalid Qwen3-VL model quantization config: unrecognized quantization config: "


return patch_pos_embeds

def forward(self, hidden_states: Tensor, grid_thw: Tensor, **kwargs) -> Tensor:

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.

medium

The return type hint is -> Tensor, but the function can return a list of tensors. Please update the type hint to -> "Union[Tensor, List[Tensor]]" and import Union and List from typing if not already present. Using a string for the type hint can avoid import issues.

Suggested change
def forward(self, hidden_states: Tensor, grid_thw: Tensor, **kwargs) -> Tensor:
def forward(self, hidden_states: Tensor, grid_thw: Tensor, **kwargs) -> "Union[Tensor, List[Tensor]]":

accepts_loss_kwargs = False

def __init__(self, config):
super().__init__(config) No newline at end of file

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.

medium

The file ends without a newline character. Please add one for consistency.

@@ -0,0 +1,66 @@

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.

medium

This file starts with a blank line, which is a minor style issue. Please remove it.

k_embed = (k * cos) + (rotate_half(k) * sin)
q_embed = q_embed.to(orig_q_dtype)
k_embed = k_embed.to(orig_k_dtype)
return q_embed, k_embed No newline at end of file

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.

medium

The file ends without a newline character. Please add one for consistency.

hidden_states,
(-1, self.in_channels, self.temporal_patch_size, self.patch_size, self.patch_size)
)

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.

medium

This line has an extra level of indentation.

Suggested change
hidden_states = self.proj(hidden_states)

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.

1 participant