Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the Qwen 3.5 model to Keras Hub, enabling users to leverage its advanced hybrid architecture for causal language modeling. The integration supports its unique combination of full and linear attention mechanisms, designed for high-throughput inference and multimodal capabilities. This addition expands the range of state-of-the-art models available within the Keras ecosystem. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces the Qwen3.5 model, a hybrid attention model, to KerasHub. The changes include the backbone, causal language model task, preprocessor, tokenizer, and associated conversion scripts and tests. While the overall structure aligns with the repository's standards, I've identified several issues that need to be addressed. There are two critical issues: the presets file is empty, which makes the model non-functional, and there's a bug in the ops.split usage within the GatedDeltaNet implementation that will cause a runtime error. Additionally, there's a significant performance concern with the recurrent implementation of the delta rule, which will be inefficient for training. Finally, there is a consistent violation of the repository's class naming conventions across all new model components.
| query, key, value = ops.split( | ||
| mixed_qkv, | ||
| [self.key_dim, self.key_dim * 2], | ||
| axis=-1, | ||
| ) |
There was a problem hiding this comment.
There is a bug in how ops.split is used to separate the fused QKV projection. The num_or_size_splits argument is [self.key_dim, self.key_dim * 2], which will produce two tensors. However, the code attempts to unpack the result into three variables (query, key, value), which will cause a runtime error. The correct split sizes should be [self.key_dim, self.key_dim, self.value_dim] to match the three output tensors.
| query, key, value = ops.split( | |
| mixed_qkv, | |
| [self.key_dim, self.key_dim * 2], | |
| axis=-1, | |
| ) | |
| query, key, value = ops.split( | |
| mixed_qkv, | |
| [self.key_dim, self.key_dim, self.value_dim], | |
| axis=-1, | |
| ) |
| @@ -0,0 +1,3 @@ | |||
| """Qwen3.5 model preset configurations.""" | |||
|
|
|||
| backbone_presets = {} | |||
There was a problem hiding this comment.
The backbone_presets dictionary is empty. This makes the model unusable as there are no pre-trained configurations to load. The conversion script tools/checkpoint_conversion/convert_qwen3_5_checkpoints.py should be run to generate the presets, and the resulting qwen3_5_presets.py file should be included in this pull request. Without presets, this model cannot be instantiated via from_preset().
References
- Preset files are required to define model configurations, descriptions, and weights URLs. An empty preset file makes the model unusable. (link)
| # Process chunks using a simple loop. | ||
| # For simplicity, we process the entire sequence in one pass | ||
| # using the recurrent formulation (equivalent to chunked but | ||
| # without the chunked optimization for now). |
There was a problem hiding this comment.
The implementation of _chunk_gated_delta_rule uses a recurrent loop over the sequence length. As noted in the comment, this is not optimized and will be very slow during training, especially with long sequences. For a model intended for production use, this should be implemented in a parallel fashion (e.g., using a parallel scan) to be efficient for training. The current implementation will likely lead to significant performance bottlenecks.
References
- Code should use efficient algorithms. A sequential loop over the sequence length for an attention-like mechanism is inefficient for training on modern accelerators. (link)
|
|
||
|
|
||
| @keras_hub_export("keras_hub.models.Qwen3_5Backbone") | ||
| class Qwen3_5Backbone(Backbone): |
There was a problem hiding this comment.
The class name Qwen3_5Backbone and other related classes in this PR (e.g., Qwen3_5CausalLM, Qwen3_5Attention) do not follow the repository's naming conventions. According to the style guide, class names should be in CapWords format (PascalCase) and follow the pattern <ModelName><ComponentType>. The use of an underscore in Qwen3_5 is inconsistent with other models in the repository like DebertaV3Backbone or Qwen3MoeBackbone. The name should be Qwen35Backbone. Please apply this change to all new Qwen3_5* classes introduced in this pull request.
| class Qwen3_5Backbone(Backbone): | |
| class Qwen35Backbone(Backbone): |
References
- Class names must use CapWords (PascalCase) and follow the pattern
<ModelName><ComponentType>. The underscore inQwen3_5violates this convention. (link)
Description of the change
This PR address the feature request #2612 issue.
Qwen3.5 Model:
Core Architectural Features:
Hybrid Attention Core:
Sparse Mixture-of-Experts (MoE): The flagship models utilize high-sparsity routing to maintain massive knowledge capacity with low compute costs.
Native Multimodality (Early Fusion): Unlike previous versions that used "late fusion" (attaching a separate vision encoder), Qwen3.5 uses early fusion. Text and visual tokens enter the same backbone from the start, allowing the model to process mixed content—like screenshots and code—simultaneously.
Reference
Colab Notebook
Checklist