Instructions to use keras/qwen3_6_moe_35b_a3b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasHub
How to use keras/qwen3_6_moe_35b_a3b with KerasHub:
import keras_hub # Load CausalLM model (optional: use half precision for inference) causal_lm = keras_hub.models.CausalLM.from_preset("hf://keras/qwen3_6_moe_35b_a3b", dtype="bfloat16") causal_lm.compile(sampler="greedy") # (optional) specify a sampler # Generate text causal_lm.generate("Keras: deep learning for", max_length=64)import keras_hub # Create a Backbone model unspecialized for any task backbone = keras_hub.models.Backbone.from_preset("hf://keras/qwen3_6_moe_35b_a3b") - Keras
How to use keras/qwen3_6_moe_35b_a3b with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://keras/qwen3_6_moe_35b_a3b") - Notebooks
- Google Colab
- Kaggle
- Model Summary
- Key Features:
- Model Details
- Architecture Details (Qwen3.6-35B-A3B)
- More Details
- Installation
- Preset Table
- Example Usage
- Custom Sampling Strategies
- Fine-tuning with LoRA
- Custom Backbone Configuration
- Example Usage with Hugging Face URI
- Custom Sampling Strategies
- Fine-tuning with LoRA
- Custom Backbone Configuration
Model Overview
Model Summary
Qwen3.6 MoE is a highly efficient multimodal language model family developed by the Qwen Team (Alibaba Cloud). It extends the standard Qwen3.6 dense architecture by introducing a Sparse Mixture-of-Experts (MoE) design and a hybrid attention mechanism.
By utilizing a routed expert system along with a shared expert, the model maintains vast total capacity while keeping the activated parameter count relatively low for each token, dramatically improving inference efficiency. The architecture features hybrid attention layers that alternate between standard grouped-query attention and recurrent linear attention. Additionally, Qwen3.6 MoE models are natively multimodal, supporting interleaved image and video inputs.
Key Features:
- Sparse Mixture-of-Experts (MoE) architecture with shared and routed experts
- Hybrid attention (Grouped-Query Attention + Linear Attention)
- Native multimodal support (Image and Video understanding)
- High efficiency: 35B total parameters with only 3B activated per token
Model Details
- Model Family: Qwen3.6 MoE
- Architecture: Sparse Mixture-of-Experts (MoE) with Hybrid Attention
- Developer: Qwen Team (Alibaba Cloud)
- Source: Qwen Team Hugging Face
- Task Type: Causal Language Modeling / Vision-Language Understanding
- Multimodal: Yes (Text, Image, Video)
Architecture Details (Qwen3.6-35B-A3B)
- Total Parameters: ~35 Billion
- Activated Parameters: ~3 Billion
- Expert Routing: Top-k routed experts + 1 shared expert
- Attention Mechanism: Hybrid (Grouped-Query Attention and GatedDeltaNet Linear Attention)
- Vision Encoder: Native multimodal vision backbone
- Max Sequence Length: 32,768 (context window size varies by specific checkpoint)
More Details
- [Qwen3.6 MoE Quickstart Notebook](coming soon..!)
- [Qwen3.6 MoE API Documentation](coming soon..!)
- Qwen3.6 MoE Model Card
- KerasHub Beginner Guide
- KerasHub Model Publishing Guide
Installation
Keras and KerasHub can be installed with:
pip install -U -q keras-hub
pip install -U -q keras
Jax, TensorFlow, and Torch come preinstalled in Kaggle Notebooks. For instructions on installing them in another environment see the Keras Getting Started page.
Preset Table
| Preset | Architecture | Total Params | Active Params | Description |
|---|---|---|---|---|
qwen3_6_moe_35b_a3b |
Qwen3.6 MoE | ~35B | ~3B | Qwen3.6 MoE instruction-tuned chat model. |
Example Usage
import keras
import keras_hub
import numpy as np
# Load pre-trained Qwen3 model
qwen3_lm = keras_hub.models.Qwen3_5MoeCausalLM.from_preset( "qwen3_6_moe_35b_a3b")
# Generate text from prompt
response = qwen3_lm.generate("I want to learn about", max_length=50)
print(response)
# Batch generation with multiple prompts
prompts = ["The future of AI is", "Machine learning helps us"]
responses = qwen3_lm.generate(prompts, max_length=30)
for prompt, response in zip(prompts, responses):
print(f"Prompt: {prompt}")
print(f"Response: {response}\n")
Custom Sampling Strategies
# Greedy sampling (default)
qwen3_lm.compile(sampler="greedy")
response = qwen3_lm.generate("Explain quantum computing", max_length=100)
# Top-k sampling
qwen3_lm.compile(sampler="top_k")
response = qwen3_lm.generate("Write a story about", max_length=80)
# Beam search
qwen3_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=4))
response = qwen3_lm.generate("The best way to learn programming is", max_length=60)
Fine-tuning with LoRA
# Enable LoRA for efficient fine-tuning
qwen3_lm.backbone.enable_lora(rank=8)
# Prepare training data
training_texts = [
"The quick brown fox jumped over the lazy dog.",
"Machine learning is a subset of artificial intelligence.",
"Python is a popular programming language for data science.",
"Deep learning models require large amounts of training data.",
"Natural language processing helps computers understand human language."
]
# Compile for training
qwen3_lm.compile(
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
optimizer=keras.optimizers.Adam(1e-4),
metrics=["accuracy"]
)
# Fine-tune the model
qwen3_lm.fit(x=training_texts, batch_size=2, epochs=3)
# Generate with fine-tuned model
response = qwen3_lm.generate("The importance of", max_length=50)
print(response)
Custom Backbone Configuration
# Create custom Qwen3_5 MoE backbone
backbone = keras_hub.models.Qwen3_5MoeBackbone(
vocabulary_size=151936,
num_layers=12, # Smaller model for faster training
num_query_heads=16,
num_key_value_heads=8,
head_dim=128,
hidden_dim=1024,
intermediate_dim=2048,
layer_norm_epsilon=1e-6,
dropout=0.1,
dtype="float32"
)
# Create tokenizer first
tokenizer = keras_hub.models.Qwen3_5MoeTokenizer.from_preset("qwen3_6_moe_35b_a3b")
# Create preprocessor with tokenizer
preprocessor = keras_hub.models.Qwen3_5MoeCausalLMPreprocessor(
tokenizer=tokenizer,
sequence_length=512
)
# Create custom causal LM
custom_qwen3 = keras_hub.models.Qwen3_5MoeCausalLM(
backbone=backbone,
preprocessor=preprocessor
)
# Compile and train
custom_qwen3.compile(
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
optimizer=keras.optimizers.Adam(1e-4)
)
# Training data
texts = ["Hello world", "How are you", "Machine learning"]
custom_qwen3.fit(x=texts, batch_size=2, epochs=1)
Example Usage with Hugging Face URI
import keras
import keras_hub
import numpy as np
# Load pre-trained Qwen3 model
qwen3_lm = keras_hub.models.Qwen3_5MoeCausalLM.from_preset( "hf://keras/qwen3_6_moe_35b_a3b")
# Generate text from prompt
response = qwen3_lm.generate("I want to learn about", max_length=50)
print(response)
# Batch generation with multiple prompts
prompts = ["The future of AI is", "Machine learning helps us"]
responses = qwen3_lm.generate(prompts, max_length=30)
for prompt, response in zip(prompts, responses):
print(f"Prompt: {prompt}")
print(f"Response: {response}\n")
Custom Sampling Strategies
# Greedy sampling (default)
qwen3_lm.compile(sampler="greedy")
response = qwen3_lm.generate("Explain quantum computing", max_length=100)
# Top-k sampling
qwen3_lm.compile(sampler="top_k")
response = qwen3_lm.generate("Write a story about", max_length=80)
# Beam search
qwen3_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=4))
response = qwen3_lm.generate("The best way to learn programming is", max_length=60)
Fine-tuning with LoRA
# Enable LoRA for efficient fine-tuning
qwen3_lm.backbone.enable_lora(rank=8)
# Prepare training data
training_texts = [
"The quick brown fox jumped over the lazy dog.",
"Machine learning is a subset of artificial intelligence.",
"Python is a popular programming language for data science.",
"Deep learning models require large amounts of training data.",
"Natural language processing helps computers understand human language."
]
# Compile for training
qwen3_lm.compile(
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
optimizer=keras.optimizers.Adam(1e-4),
metrics=["accuracy"]
)
# Fine-tune the model
qwen3_lm.fit(x=training_texts, batch_size=2, epochs=3)
# Generate with fine-tuned model
response = qwen3_lm.generate("The importance of", max_length=50)
print(response)
Custom Backbone Configuration
# Create custom Qwen3_5 MoE backbone
backbone = keras_hub.models.Qwen3_5MoeBackbone(
vocabulary_size=151936,
num_layers=12, # Smaller model for faster training
num_query_heads=16,
num_key_value_heads=8,
head_dim=128,
hidden_dim=1024,
intermediate_dim=2048,
layer_norm_epsilon=1e-6,
dropout=0.1,
dtype="float32"
)
# Create tokenizer first
tokenizer = keras_hub.models.Qwen3_5MoeTokenizer.from_preset("hf://keras/qwen3_6_moe_35b_a3b")
# Create preprocessor with tokenizer
preprocessor = keras_hub.models.Qwen3_5MoeCausalLMPreprocessor(
tokenizer=tokenizer,
sequence_length=512
)
# Create custom causal LM
custom_qwen3 = keras_hub.models.Qwen3_5MoeCausalLM(
backbone=backbone,
preprocessor=preprocessor
)
# Compile and train
custom_qwen3.compile(
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
optimizer=keras.optimizers.Adam(1e-4)
)
# Training data
texts = ["Hello world", "How are you", "Machine learning"]
custom_qwen3.fit(x=texts, batch_size=2, epochs=1)
- Downloads last month
- 409