Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: wire in DeepSeek-V4.1-Flash-1017 (deepseek41) (#14260)

Daniel Hand1343c4a8333
diff --git a/studio/backend/core/inference/defaults.py b/studio/backend/core/inference/defaults.py
index 665895a75c4..7d24af272cf 100644
--- a/studio/backend/core/inference/defaults.py
+++ b/studio/backend/core/inference/defaults.py
@@ -12,6 +12,7 @@ DEFAULT_MODELS_GGUF = [
"unsloth/Qwen3.6-27B-MTP-GGUF",
"unsloth/Qwen3.6-35B-A3B-MTP-GGUF",
"unsloth/DeepSeek-V4-Flash-GGUF",
+ "unsloth/DeepSeek-V4.1-Flash-1017-GGUF",
"unsloth/gemma-4-E2B-it-GGUF",
"unsloth/gemma-4-E4B-it-GGUF",
"unsloth/gemma-4-31B-it-GGUF",
@@ -32,6 +33,7 @@ DEFAULT_MODELS_STANDARD = [
"unsloth/Qwen3.6-27B-MTP-GGUF",
"unsloth/Qwen3.6-35B-A3B-MTP-GGUF",
"unsloth/DeepSeek-V4-Flash-GGUF",
+ "unsloth/DeepSeek-V4.1-Flash-1017-GGUF",
"unsloth/gemma-4-E2B-it-GGUF",
"unsloth/gemma-4-E4B-it-GGUF",
"unsloth/gemma-4-31B-it-GGUF",
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index bfe401dff54..721828fe283 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -18796,6 +18796,13 @@ class LlamaCppBackend:
# it auto-fit commits the full 1M train context, OOMs the reserve, and spills to CPU.
_DSV4_CTX_COMPUTE_FLAT_BYTES = 2 * 1024**3 # ctx-independent indexer scratch
_DSV4_CTX_COMPUTE_BYTES_PER_TOK = 72000 # per token at ub=512 (~72 GiB at 1M)
+ # DeepSeek-V4.1 (deepseek41): its own sparse-attention graph, far smaller than DSV4's but
+ # not linear in context. Measured CUDA0 compute buffer, UD-IQ1_S with experts + Engram on
+ # CPU, f16 cache: ub=512 2102 / 2198 / 3094 / 11197 MiB at 16k / 64k / 256k / 1M; ub=2048
+ # 9751 / 37143 MiB at 256k / 1M. Flat + linear (rate ub-scaled) is the chord to the 1M
+ # point, so it stays above every measurement (convex curve; 1M is the trained maximum).
+ _DSV41_CTX_COMPUTE_FLAT_BYTES = 2 * 1024**3
+ _DSV41_CTX_COMPUTE_BYTES_PER_TOK = 9600 # per token at ub=512 (~11.4 GiB at 1M)
# Inkling (inkling): with the reserve fix in the bundled llama.cpp (full-cache
# reserve context reports the whole cache as position-contiguous, so the
@@ -18980,6 +18987,15 @@ class LlamaCppBackend:
self._DSV4_CTX_COMPUTE_FLAT_BYTES
+ self._DSV4_CTX_COMPUTE_BYTES_PER_TOK * n_ctx * ub_scale
)
+ if getattr(self, "_architecture", None) == "deepseek41":
+ # DSV4.1 sparse-attention buffer (see constants): flat + linear, ub-scaled. Unlike
+ # deepseek4 the rate has little headroom at 1M (~4%), so a layer split adds the
+ # extra mask copies like every other arch.
+ ub_scale = ub / self._DEFAULT_N_UBATCH
+ return int(
+ self._DSV41_CTX_COMPUTE_FLAT_BYTES
+ + (self._DSV41_CTX_COMPUTE_BYTES_PER_TOK * ub_scale + split_extra) * n_ctx
+ )
if getattr(self, "_architecture", None) == "inkling":
ub_scale = ub / self._DEFAULT_N_UBATCH
# The fused banded path requires an f32/f16/bf16 KV cache. A quantized
@@ -24211,13 +24227,14 @@ class LlamaCppBackend:
def _requires_symmetric_kv(kv_lora_rank, architecture) -> bool:
"""Whether llama.cpp rejects K != V for a model with this metadata.
- Mirrors ``is_mla() || arch == LLM_ARCH_DEEPSEEK4``: kv_lora_rank stands in
- for is_mla() (the MLA archs' converter writes it alongside the MLA head
- dims), and deepseek4 is checked by name because it sets neither.
+ Mirrors ``is_mla() || arch == LLM_ARCH_DEEPSEEK4 || arch == LLM_ARCH_DEEPSEEK41``:
+ kv_lora_rank stands in for is_mla() (the MLA archs' converter writes it
+ alongside the MLA head dims), and deepseek4 / deepseek41 are checked by name
+ because they set neither.
"""
if kv_lora_rank is not None:
return True
- return (architecture or "").strip().lower() == "deepseek4"
+ return (architecture or "").strip().lower() in ("deepseek4", "deepseek41")
def _target_kv_symmetry(self) -> bool:
"""Whether the TARGET model requires K == V."""
diff --git a/studio/backend/tests/test_compute_buffer.py b/studio/backend/tests/test_compute_buffer.py
index 62632c127b8..439f9807b65 100644
--- a/studio/backend/tests/test_compute_buffer.py
+++ b/studio/backend/tests/test_compute_buffer.py
@@ -525,6 +525,43 @@ class TestContextBufferDSV4:
assert per_tok == pytest.approx(512 * 2, rel = 1e-6)
+class TestContextBufferDSV41:
+ """DeepSeek-V4.1 (deepseek41) has its own sparse-attention graph: ~2 GiB flat, then
+ growing faster than linearly, but far below DSV4's rate. Measured CUDA0 compute
+ buffer with the pinned llama.cpp (UD-IQ1_S, experts + Engram on CPU, f16 cache)."""
+
+ MIB = 1024**2
+ # (n_ctx, n_ubatch): measured MiB
+ _MEASURED = {
+ (16384, 512): 2102.26,
+ (65536, 512): 2198.26,
+ (262144, 512): 3094.26,
+ (1048576, 512): 11197.26,
+ (262144, 2048): 9751.02,
+ (1048576, 2048): 37143.02,
+ }
+
+ @pytest.mark.parametrize("ctx_ub", list(_MEASURED))
+ def test_covers_every_measurement(self, ctx_ub):
+ n_ctx, ub = ctx_ub
+ b = _backend(embd = 5120, arch = "deepseek41")
+ mib = b._compute_buffer_ctx_bytes(n_ctx, ub, "f16") / self.MIB
+ assert mib >= self._MEASURED[ctx_ub], f"under-reserved {mib:.0f} < {self._MEASURED[ctx_ub]}"
+
+ def test_not_the_dsv4_rate(self):
+ # Reusing deepseek4's 72000 B/tok would reserve ~6.6x the measured 1M buffer and
+ # cut the context the fit grants for nothing; stay within 1.2x of measured.
+ b = _backend(embd = 5120, arch = "deepseek41")
+ mib = b._compute_buffer_ctx_bytes(1048576, 512, "f16") / self.MIB
+ assert mib <= self._MEASURED[(1048576, 512)] * 1.2
+
+ def test_layer_split_adds_mask_copies(self):
+ b = _backend(embd = 5120, arch = "deepseek41")
+ one = b._compute_buffer_ctx_bytes(262144, 512, "f16")
+ split = b._compute_buffer_ctx_bytes(262144, 512, "f16", layer_split = True)
+ assert split - one == (LlamaCppBackend._CTX_COMPUTE_SPLIT_MULT - 1) * 512 * 2 * 262144
+
+
class TestContextBufferLayerSplit:
"""The per-device f16 (KQ-mask) rate steps 4x once the model spans >1 device under
``-sm layer``: a step on "is split", not a ramp in device count. ``_MEASURED`` is
diff --git a/studio/backend/tests/test_deepseek_v41_defaults.py b/studio/backend/tests/test_deepseek_v41_defaults.py
new file mode 100644
index 00000000000..e3783d3684e
--- /dev/null
+++ b/studio/backend/tests/test_deepseek_v41_defaults.py
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""DeepSeek-V4.1-Flash-1017 (llama.cpp arch ``deepseek41``).
+
+Sampling comes from the ``deepseek-v4`` family in ``inference_defaults.json``
+(temperature 1.0, top_p 1.0), which every V4.1 id shape matches by substring.
+The template gates thinking on ``enable_thinking`` / ``thinking_mode`` and maps
+``reasoning_effort`` low / medium / high / max to a budget, so the Think menu
+offers all four. Like deepseek4, the arch has its own KV cache and no
+kv_lora_rank, so the K == V rule is matched by name.
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+import pytest
+
+_backend_root = Path(__file__).resolve().parent.parent
+if str(_backend_root) not in sys.path:
+ sys.path.insert(0, str(_backend_root))
+
+
+# Faithful slice of the DeepSeek-V4.1 GGUF template: the thinking gate and the
+# reasoning_effort budget map.
+DEEPSEEK_V41_TEMPLATE = """
+{%- if thinking_mode is not defined or thinking_mode is none -%}
+ {%- if enable_thinking is defined and enable_thinking is not none -%}
+ {%- set thinking_mode = "thinking" if enable_thinking else "chat" -%}
+ {%- else -%}
+ {%- set thinking_mode = "thinking" -%}
+ {%- endif -%}
+{%- endif -%}
+{%- if reasoning_effort is not defined or reasoning_effort is none -%}{%- set reasoning_effort = "high" -%}{%- endif -%}
+{%- set effort_map = {"low": 50, "medium": 62, "high": 75, "max": 100} -%}
+{%- if reasoning_effort is string and reasoning_effort in effort_map -%}
+ {%- set budget = effort_map[reasoning_effort] -%}
+{%- endif -%}
+{{- bos_token -}}
+{%- for message in messages -%}
+ {%- if message.role == "user" -%}{{- "<|User|>" + message.content -}}{%- endif -%}
+{%- endfor -%}
+{%- if add_generation_prompt -%}
+ {{- "<|Assistant|>" -}}{%- if thinking_mode == "thinking" -%}{{- "<think>" -}}{%- else -%}{{- "</think>" -}}{%- endif -%}
+{%- endif -%}
+"""
+
+_IDS = [
+ "unsloth/DeepSeek-V4.1-Flash-1017-GGUF",
+ "unsloth/DeepSeek-V4.1-Flash-1017-GGUF:UD-Q4_K_XL",
+ "/scan/models--unsloth--DeepSeek-V4.1-Flash-1017-GGUF/snapshots/0123abcd",
+ "/models/DeepSeek-V4.1-Flash-1017-UD-IQ1_S-00001-of-00005.gguf",
+]
+
+
[email protected]("model_id", _IDS)
+def test_sampling_defaults(model_id):
+ from utils.inference.inference_config import get_family_inference_params
+
+ params = get_family_inference_params(model_id)
+ assert params["temperature"] == 1.0
+ assert params["top_p"] == 1.0
+
+
[email protected]("model_id", _IDS[:1] + _IDS[2:3])
+def test_reasoning_effort_ladder(model_id):
+ from core.inference.llama_cpp import detect_reasoning_flags
+
+ flags = detect_reasoning_flags(DEEPSEEK_V41_TEMPLATE, model_id)
+ assert flags["supports_reasoning"] is True
+ assert flags["reasoning_style"] == "enable_thinking_effort"
+ assert flags["reasoning_effort_levels"] == ["low", "medium", "high", "max"]
+
+
+def test_requires_symmetric_kv():
+ from core.inference.llama_cpp import LlamaCppBackend
+
+ assert LlamaCppBackend._requires_symmetric_kv(None, "deepseek41") is True
+
+
+def test_listed_as_default_gguf():
+ from core.inference.defaults import DEFAULT_MODELS_GGUF, DEFAULT_MODELS_STANDARD
+
+ assert "unsloth/DeepSeek-V4.1-Flash-1017-GGUF" in DEFAULT_MODELS_GGUF
+ assert "unsloth/DeepSeek-V4.1-Flash-1017-GGUF" in DEFAULT_MODELS_STANDARD
diff --git a/studio/backend/tests/test_mla_kv_cache_symmetry.py b/studio/backend/tests/test_mla_kv_cache_symmetry.py
index 7b49db14534..f4e5f6094b4 100644
--- a/studio/backend/tests/test_mla_kv_cache_symmetry.py
+++ b/studio/backend/tests/test_mla_kv_cache_symmetry.py
@@ -210,6 +210,12 @@ class TestTheSignalStudioAlreadyHas:
assert LlamaCppBackend._requires_symmetric_kv(None, "DeepSeek4") is True
assert LlamaCppBackend._requires_symmetric_kv(None, " deepseek4 ") is True
+ def test_deepseek41_is_recognized_without_kv_lora_rank(self):
+ """DeepSeek-V4.1 (deepseek41) is a separate arch in the same condition
+ (`|| arch == LLM_ARCH_DEEPSEEK41`) and, like deepseek4, writes no kv_lora_rank."""
+ assert LlamaCppBackend._requires_symmetric_kv(None, "deepseek41") is True
+ assert LlamaCppBackend._requires_symmetric_kv(None, "DeepSeek41") is True
+
def test_a_non_mla_arch_without_a_rank_is_not_symmetric(self):
assert LlamaCppBackend._requires_symmetric_kv(None, None) is False
assert LlamaCppBackend._requires_symmetric_kv(None, "deepseek") is False