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)

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
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including keras/magistral_small_2507_en

Paper for keras/magistral_small_2507_en