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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: hybrid MLA cache sizing, fenced HTML rendering, Kimi-K3 defaults (#7616)
Daniel Han37a77ceb897b
diff --git a/studio/backend/assets/configs/model_defaults/other/unsloth_Kimi-K3.yaml b/studio/backend/assets/configs/model_defaults/other/unsloth_Kimi-K3.yamlnew file mode 100644index 00000000000..cdc8bda3da0--- /dev/null+++ b/studio/backend/assets/configs/model_defaults/other/unsloth_Kimi-K3.yaml@@ -0,0 +1,8 @@+# Model defaults for unsloth/Kimi-K3+# Also applies to: moonshotai/Kimi-K3, unsloth/Kimi-K3-GGUF+# Inference values are Moonshot's recommended sampling settings.++inference:+ temperature: 1.0+ top_p: 0.95+ min_p: 0.0diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex d3b5bf05760..b28db854d92 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -2337,6 +2337,8 @@ class LlamaCppBackend:self._kv_value_length_swa: Optional[int] = Noneself._ssm_inner_size: Optional[int] = Noneself._ssm_state_size: Optional[int] = None+ self._ssm_conv_kernel: Optional[int] = None+ self._kda_head_dim: Optional[int] = None# Last N layers reuse earlier layers' KV and don't allocate their own# cache (Gemma 3n / Gemma 4: <arch>.attention.shared_kv_layers).self._shared_kv_layers: Optional[int] = None@@ -4351,6 +4353,30 @@ class LlamaCppBackend:return self._n_kv_heads_by_layer[layer_idx]return fallback+ def _recurrent_state_bytes(self, n_parallel: int = 1) -> int:+ """VRAM for the conv + recurrent state of linear-attention layers.++ Hybrids pair an MLA/attention cache with llama_memory_recurrent, which+ allocates per recurrent layer and per sequence, always f32, offloaded+ beside the KV cache. Unlike KV this does not scale with context, so it+ is the whole reservation at short contexts and the bisection in+ _fit_context_to_vram cannot shrink it away.++ Sizes follow llama_hparams::n_embd_r/n_embd_s. Kimi KDA only: Mamba+ needs ssm.group_count, which is not parsed, so those models keep the+ previous behaviour rather than get a wrong number.+ """+ if not self._n_kv_heads_by_layer or not self._n_layers or not self._kda_head_dim:+ return 0+ n_recurrent = sum(1 for i in range(self._n_layers) if self._kv_heads_for_layer(i, 1) == 0)+ if n_recurrent == 0:+ return 0+ head_dim, n_head = self._kda_head_dim, self._n_heads or 1+ d_conv = self._ssm_conv_kernel or 4+ n_embd_r = 3 * max(0, d_conv - 1) * n_head * head_dim+ n_embd_s = head_dim * head_dim * n_head+ return int(n_recurrent * (n_embd_r + n_embd_s) * 4 * max(1, n_parallel))+def _legacy_head_dim(self) -> int:"""Head-dim fallback for GGUFs without explicit key/value dims. Reachedonly via the legacy branch of _can_estimate_kv(), so _embedding_length@@ -4446,7 +4472,21 @@ class LlamaCppBackend:n_kv_mla = self._n_kv_heads or 1rope_dim = self._key_length_mla or 64key_len = self._kv_key_length or (self._kv_lora_rank + rope_dim)- return int(n_layers_kv * total_cells * n_kv_mla * key_len * bpe_k)+ # Hybrid MLA (Kimi-K3): head_count_kv is a per-layer array whose KDA+ # linear-attention layers are 0 and hold a constant-size state instead+ # of a growing cache. Only the non-zero layers allocate KV, so counting+ # every block overstates it by the hybrid ratio (93 blocks vs 24 real+ # ones is 3.9x, or 78 GiB of phantom cache at 1M context) and shrinks+ # the auto-fit context for no reason. Uniform MLA keeps n_layers_kv.+ n_mla_layers = n_layers_kv+ if self._n_kv_heads_by_layer:+ attn = sum(+ 1 for i in range(n_layers_kv) if self._kv_heads_for_layer(i, n_kv_mla) > 0+ )+ n_mla_layers = max(1, attn)+ return int(+ n_mla_layers * total_cells * n_kv_mla * key_len * bpe_k+ ) + self._recurrent_state_bytes(n_parallel)key_len = self._kv_key_lengthval_len = self._kv_value_length@@ -5211,6 +5251,8 @@ class LlamaCppBackend:self._kv_value_length_swa = Noneself._ssm_inner_size = Noneself._ssm_state_size = None+ self._ssm_conv_kernel = None+ self._kda_head_dim = Noneself._shared_kv_layers = Noneself._nextn_predict_layers = Noneself._architecture = None@@ -5301,6 +5343,8 @@ class LlamaCppBackend:f"{arch}.attention.shared_kv_layers": "shared_kv_layers",f"{arch}.ssm.inner_size": "ssm_inner_size",f"{arch}.ssm.state_size": "ssm_state_size",+ f"{arch}.ssm.conv_kernel": "ssm_conv_kernel",+ f"{arch}.kda.head_dim": "kda_head_dim",f"{arch}.nextn_predict_layers": "nextn_predict_layers",}elif key == "tokenizer.chat_template":@@ -10012,6 +10056,8 @@ class LlamaCppBackend:self._kv_value_length_swa = Noneself._ssm_inner_size = Noneself._ssm_state_size = None+ self._ssm_conv_kernel = None+ self._kda_head_dim = Noneself._shared_kv_layers = Noneself._nextn_predict_layers = None# Clean up temp chat template file.diff --git a/studio/backend/tests/test_kv_cache_estimation.py b/studio/backend/tests/test_kv_cache_estimation.pyindex 3cf86cf0ca6..84a979ee416 100644--- a/studio/backend/tests/test_kv_cache_estimation.py+++ b/studio/backend/tests/test_kv_cache_estimation.py@@ -840,6 +840,47 @@ class TestMLAEstimation:expected = 61 * _runtime_kv_cells(1000) * 1 * (512 + 64) * 2 # 576assert result == expected+ def test_mla_hybrid_counts_only_attention_layers(self):+ """Kimi-K3: KDA layers are 0 in head_count_kv and hold no growing cache."""+ pattern = [1 if (i % 4) == 3 else 0 for i in range(93)]+ pattern[92] = 1+ b = self._mla_backend(_n_layers = 93, _n_kv_heads_by_layer = pattern)+ n_attn = sum(1 for v in pattern if v)+ assert n_attn == 24+ expected = n_attn * _runtime_kv_cells(1000) * 1 * 576 * 2+ assert b._estimate_kv_cache_bytes(1000, "f16") == expected++ def test_mla_uniform_unaffected_by_hybrid_path(self):+ """An all-attention per-layer array must match the plain layer count."""+ b = self._mla_backend(_n_kv_heads_by_layer = [1] * 61)+ expected = 61 * _runtime_kv_cells(1000) * 1 * 576 * 2+ assert b._estimate_kv_cache_bytes(1000, "f16") == expected++ def test_hybrid_adds_recurrent_state(self):+ """KDA conv+state is f32, per sequence, and does not scale with context."""+ pattern = [1 if (i % 4) == 3 else 0 for i in range(93)]+ pattern[92] = 1+ b = self._mla_backend(+ _n_layers = 93,+ _n_kv_heads_by_layer = pattern,+ _n_heads = 96,+ _kda_head_dim = 128,+ _ssm_conv_kernel = 4,+ )+ # 69 recurrent layers * (3*3*96*128 + 128*128*96) * 4 B+ rs = 69 * (110592 + 1572864) * 4+ assert b._recurrent_state_bytes() == rs+ kv = 24 * _runtime_kv_cells(1000) * 1 * 576 * 2+ assert b._estimate_kv_cache_bytes(1000, "f16") == kv + rs+ # per sequence, so --parallel multiplies it+ assert b._recurrent_state_bytes(4) == rs * 4++ def test_recurrent_state_zero_without_kda_dims(self):+ """Uniform MLA and un-parsed Mamba keep the previous behaviour."""+ assert self._mla_backend()._recurrent_state_bytes() == 0+ b = self._mla_backend(_n_layers = 93, _n_kv_heads_by_layer = [1] * 93)+ assert b._recurrent_state_bytes() == 0+def test_mla_defaults_n_kv_to_1_when_heads_absent(self):"""MLA uses n_kv=1 even if n_kv_heads is None (not n_heads)."""b = self._mla_backend(_n_kv_heads = None) # n_heads=128 still setdiff --git a/studio/backend/utils/models/model_config.py b/studio/backend/utils/models/model_config.pyindex 6270d9e03f1..81f5b21ec90 100644--- a/studio/backend/utils/models/model_config.py+++ b/studio/backend/utils/models/model_config.py@@ -461,6 +461,13 @@ MODEL_NAME_MAPPING = {"unsloth/whisper-large-v3","openai/whisper-large-v3",],+ # GGUF repo listed too: Kimi-K3 ships GGUF-only, so the -GGUF id is what+ # reaches the lookup.+ "unsloth_Kimi-K3.yaml": [+ "unsloth/kimi-k3",+ "unsloth/kimi-k3-gguf",+ "moonshotai/kimi-k3",+ ],}# Reverse lookup: model_name -> canonical_filenamediff --git a/studio/frontend/src/components/assistant-ui/message-html-artifacts.tsx b/studio/frontend/src/components/assistant-ui/message-html-artifacts.tsxindex 4301c5b62cd..5a18c390538 100644--- a/studio/frontend/src/components/assistant-ui/message-html-artifacts.tsx+++ b/studio/frontend/src/components/assistant-ui/message-html-artifacts.tsx@@ -45,13 +45,15 @@ export const MessageHtmlArtifacts: FC = () => {const loadedIsDiffusion = useChatRuntimeStore((state) => state.loadedIsDiffusion,);- const cardsEnabled = artifactsEnabled || collapseHtmlArtifacts;// Full docs already shown by the in-place collapse; excluded for diffusion,- // which keeps its code inline instead.- const collapsesFullDocs = cardsEnabled && !loadedIsDiffusion;+ // which keeps its code inline instead. This picks which path renders a full+ // document, not whether fenced HTML renders at all: the Canvas control is+ // gone and both flags default off, so gating the cards on them renders none.+ const collapsesFullDocs =+ (artifactsEnabled || collapseHtmlArtifacts) && !loadedIsDiffusion;const fences = useMemo(() => {- if (isRunning || hasRenderHtmlTool || !cardsEnabled) {+ if (isRunning || hasRenderHtmlTool) {return [];}return textBlob@@ -62,7 +64,7 @@ export const MessageHtmlArtifacts: FC = () => {// Skip only the plain fences the in-place collapse actually handles.!(fence.isFullDocument && fence.isPlainFence && collapsesFullDocs),);- }, [isRunning, hasRenderHtmlTool, cardsEnabled, textBlob, collapsesFullDocs]);+ }, [isRunning, hasRenderHtmlTool, textBlob, collapsesFullDocs]);if (fences.length === 0) {return null;