Add qwen3vl support - #3463
Conversation
There was a problem hiding this comment.
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.
| 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 |
| def forward(self, x, position_ids): | ||
| # TODO: translate from pytorch to tvm | ||
| raise NotImplementedError |
There was a problem hiding this comment.
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.
| 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 |
| "mistral": Model( | ||
| name="mistral", | ||
| model=mistral_model.MistralForCausalLM, | ||
| model=mistral_model.MistralForCasualLM, |
There was a problem hiding this comment.
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.
| model=mistral_model.MistralForCasualLM, | |
| model=mistral_model.MistralForCausalLM, |
| ) | ||
| else: | ||
| raise ValueError( | ||
| "Invalid DeepSeek model quantization config: unrecognized quantization config: " |
There was a problem hiding this comment.
|
|
||
| return patch_pos_embeds | ||
|
|
||
| def forward(self, hidden_states: Tensor, grid_thw: Tensor, **kwargs) -> Tensor: |
There was a problem hiding this comment.
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.
| 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 |
| @@ -0,0 +1,66 @@ | |||
|
|
|||
| 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 |
| hidden_states, | ||
| (-1, self.in_channels, self.temporal_patch_size, self.patch_size, self.patch_size) | ||
| ) | ||
|
|
No description provided.