Instructions to use keras/magistral_small_2507_en with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasHub
How to use keras/magistral_small_2507_en with KerasHub:
import keras_hub # Load CausalLM model (optional: use half precision for inference) causal_lm = keras_hub.models.CausalLM.from_preset("hf://keras/magistral_small_2507_en", 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/magistral_small_2507_en") - Keras
How to use keras/magistral_small_2507_en 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/magistral_small_2507_en") - Notebooks
- Google Colab
- Kaggle
Model Overview
Model Summary
Magistral is MistralAI's family of reasoning-focused large language models, fine-tuned from Mistral Small 3.1 using supervised fine-tuning (SFT) on reasoning traces and reinforcement learning (RL). Magistral models are designed for complex, multi-step reasoning tasks including mathematics, coding, logic, and scientific analysis.
Key features:
-Architecture: Based on Mistral with explicit head_dim=128 and no sliding window attention
-**Reasoning:**Uses [THINK]/[/THINK] special tokens for chain-of-thought reasoning
-**Context:**128K token context window (recommended up to 40K for optimal performance)
- [Magistral Quickstart Notebook](coming soon..!)
- Magistral API Documentation
- Magistral Model Card
- Magistral Technical Paper
- 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.
Presets
| Preset Name | Parameters | Description |
|---|---|---|
| A | B | C |
Example Usage
Configure the Backend (Optional but recommended)
import os
# Configure Keras to use the JAX backend
os.environ["KERAS_BACKEND"] = "jax"
Load the Model & Generate Text
import keras
import keras_hub
# Load the Magistral Small 2507 model
# This will automatically download the weights from Kaggle
causal_lm = keras_hub.models.MistralCausalLM.from_preset("magistral_small_2507_en")
# Generate text
prompt = "The most important concepts to understand in machine learning are"
output = causal_lm.generate(prompt, max_length=100)
print(output)
Loading just the Backbone
# Load only the feature extractor backbone
backbone = keras_hub.models.MistralBackbone.from_preset("magistral_small_2507_en")
# Pass a batch of tokenized sequences to get hidden states
import numpy as np
dummy_tokens = np.random.randint(0, 1000, size=(2, 64))
hidden_states = backbone(dummy_tokens)
print(hidden_states.shape)
Example Usage with Hugging Face URI
Configure the Backend (Optional but recommended)
import os
# Configure Keras to use the JAX backend
os.environ["KERAS_BACKEND"] = "jax"
Load the Model & Generate Text
import keras
import keras_hub
# Load the Magistral Small 2507 model
# This will automatically download the weights from Kaggle
causal_lm = keras_hub.models.MistralCausalLM.from_preset("hf://keras/magistral_small_2507_en")
# Generate text
prompt = "The most important concepts to understand in machine learning are"
output = causal_lm.generate(prompt, max_length=100)
print(output)
Loading just the Backbone
# Load only the feature extractor backbone
backbone = keras_hub.models.MistralBackbone.from_preset("hf://keras/magistral_small_2507_en")
# Pass a batch of tokenized sequences to get hidden states
import numpy as np
dummy_tokens = np.random.randint(0, 1000, size=(2, 64))
hidden_states = backbone(dummy_tokens)
print(hidden_states.shape)
- Downloads last month
- 46