Model Overview

Model Overview

Devstral 2 is a family of agentic large language models for software engineering tasks, published by Mistral AI. The models are built to use tools to explore codebases, edit multiple files, and power software engineering agents, and they report strong results on SWE-bench Verified. Devstral Small 2 is a 24 billion parameter, 40-layer, instruction-tuned decoder with grouped-query attention (32 query heads, 8 key/value heads), a 131,072-token vocabulary, and a 256k context window. It shares the Mistral3 / Ministral 3 architecture, including a Pixtral vision encoder, so it accepts images alongside text. The model is intended for AI code assistants, agentic coding, and software engineering workflows β€” chat, agentic and instruction-following tasks for SWE use cases β€” rather than general-purpose assistance. See the model card below for benchmarks, data sources, and intended use cases.

Weights are released under the Apache 2.0 License. Keras model code is released under the Apache 2 License.

Links

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

The following model checkpoints are provided by the Keras team. Full code examples for each are available below.

Checkpoints are being uploaded; the table lists the presets defined in KerasHub PR #3020.

Preset name Parameters Description
devstral_small_2_24b_instruct_2512_en 24.01B 24 billion parameter, 40-layer, instruction-tuned Devstral Small 2 model for agentic coding, with a Pixtral vision encoder for image input and a 256k context window.

Example Usage

import keras
import keras_hub
import numpy as np

Use generate() to do text generation. Devstral Small 2 is a 24B model, so load it in bfloat16.

devstral_lm = keras_hub.models.Mistral3CausalLM.from_preset(
    "devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
devstral_lm.generate("Write a Python function that checks if a number is prime.", max_length=256)

# Generate with batched prompts.
devstral_lm.generate(
    [
        "Write a Python function that checks if a number is prime.",
        "Explain what a mutex is in two sentences.",
    ],
    max_length=256,
)

This is an instruction-tuned model. Wrap the request in [INST] ... [/INST] to use the instruct format.

devstral_lm = keras_hub.models.Mistral3CausalLM.from_preset(
    "devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
prompt = "[INST]Refactor this loop into a list comprehension:\n\nresult = []\nfor x in items:\n    if x > 0:\n        result.append(x * 2)[/INST]"
devstral_lm.generate(prompt, max_length=256)

Generate text grounded in an image. The prompt has one [IMG] marker for each image, and images holds one list of images for each prompt.

devstral_lm = keras_hub.models.Mistral3CausalLM.from_preset(
    "devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
image = np.asarray(keras.utils.load_img("screenshot.png"))
devstral_lm.generate(
    {
        "prompts": "[INST][IMG]Describe the bug shown in this screenshot.[/INST]",
        "images": [[image]],
    },
    max_length=256,
)

Compile the generate() function with a custom sampler.

devstral_lm = keras_hub.models.Mistral3CausalLM.from_preset(
    "devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
devstral_lm.compile(sampler="greedy")
devstral_lm.generate("def fibonacci(n):", max_length=64)

devstral_lm.compile(sampler=keras_hub.samplers.TopKSampler(k=5, temperature=0.7))
devstral_lm.generate("def fibonacci(n):", max_length=64)

Call fit() on a single batch.

features = [
    "def add(a, b):\n    return a + b",
    "def is_even(n):\n    return n % 2 == 0",
]
devstral_lm = keras_hub.models.Mistral3CausalLM.from_preset(
    "devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
devstral_lm.fit(x=features, batch_size=2)

Load the backbone and tokenizer directly.

backbone = keras_hub.models.Mistral3Backbone.from_preset(
    "devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
tokenizer = keras_hub.tokenizers.Mistral3Tokenizer.from_preset("devstral_small_2_24b_instruct_2512_en")

token_ids = tokenizer(["def hello():\n    print('hi')"])

Example Usage with Hugging Face URI

import keras
import keras_hub
import numpy as np

Use generate() to do text generation. Devstral Small 2 is a 24B model, so load it in bfloat16.

devstral_lm = keras_hub.models.Mistral3CausalLM.from_preset(
    "hf://keras/devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
devstral_lm.generate("Write a Python function that checks if a number is prime.", max_length=256)

# Generate with batched prompts.
devstral_lm.generate(
    [
        "Write a Python function that checks if a number is prime.",
        "Explain what a mutex is in two sentences.",
    ],
    max_length=256,
)

This is an instruction-tuned model. Wrap the request in [INST] ... [/INST] to use the instruct format.

devstral_lm = keras_hub.models.Mistral3CausalLM.from_preset(
    "hf://keras/devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
prompt = "[INST]Refactor this loop into a list comprehension:\n\nresult = []\nfor x in items:\n    if x > 0:\n        result.append(x * 2)[/INST]"
devstral_lm.generate(prompt, max_length=256)

Generate text grounded in an image. The prompt has one [IMG] marker for each image, and images holds one list of images for each prompt.

devstral_lm = keras_hub.models.Mistral3CausalLM.from_preset(
    "hf://keras/devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
image = np.asarray(keras.utils.load_img("screenshot.png"))
devstral_lm.generate(
    {
        "prompts": "[INST][IMG]Describe the bug shown in this screenshot.[/INST]",
        "images": [[image]],
    },
    max_length=256,
)

Compile the generate() function with a custom sampler.

devstral_lm = keras_hub.models.Mistral3CausalLM.from_preset(
    "hf://keras/devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
devstral_lm.compile(sampler="greedy")
devstral_lm.generate("def fibonacci(n):", max_length=64)

devstral_lm.compile(sampler=keras_hub.samplers.TopKSampler(k=5, temperature=0.7))
devstral_lm.generate("def fibonacci(n):", max_length=64)

Call fit() on a single batch.

features = [
    "def add(a, b):\n    return a + b",
    "def is_even(n):\n    return n % 2 == 0",
]
devstral_lm = keras_hub.models.Mistral3CausalLM.from_preset(
    "hf://keras/devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
devstral_lm.fit(x=features, batch_size=2)

Load the backbone and tokenizer directly.

backbone = keras_hub.models.Mistral3Backbone.from_preset(
    "hf://keras/devstral_small_2_24b_instruct_2512_en",
    dtype="bfloat16",
)
tokenizer = keras_hub.tokenizers.Mistral3Tokenizer.from_preset("hf://keras/devstral_small_2_24b_instruct_2512_en")

token_ids = tokenizer(["def hello():\n    print('hi')"])
Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Collection including keras/devstral_small_2_24b_instruct_2512_en