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: support NVIDIA Nemotron 3.5 Bolt and Super GGUFs (#13899)
Daniel Han4494fa58c956
diff --git a/studio/backend/assets/configs/inference_defaults.json b/studio/backend/assets/configs/inference_defaults.jsonindex 798cbf9d0db..7b868b60100 100644--- a/studio/backend/assets/configs/inference_defaults.json+++ b/studio/backend/assets/configs/inference_defaults.json@@ -306,6 +306,13 @@"min_p": 0.01,"repetition_penalty": 1.0},+ "nemotron-3.5": {+ "temperature": 1.0,+ "top_p": 0.95,+ "top_k": -1,+ "min_p": 0.01,+ "repetition_penalty": 1.0+ },"nemotron": {"temperature": 1.0,"top_p": 1.0,@@ -441,7 +448,7 @@"devstral", "pixtral","deepseek-v4", "deepseek-r1", "deepseek-v3", "deepseek-ocr","glm-5", "glm-4",- "nemotron",+ "nemotron-3.5", "nemotron","minimax-m2.7", "minimax-m2.5", "minimax","gpt-oss", "granite-4","kimi-k3", "kimi-k2", "kimi",diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex 46ff32ff13f..4fd3785f95a 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -3312,7 +3312,7 @@ def _is_mtp_model_name(model_identifier: Optional[str], gguf_path: Optional[str]# Mirrors hub.utils.gguf._DRAFTER_KINDS / _DRAFTER_DIR_KINDS.-_DRAFTER_KINDS = ("mtp", "dspark", "dflash", "eagle3")+_DRAFTER_KINDS = ("mtp", "dspark", "dflash", "eagle3", "lilicorr")_DRAFTER_DIR_KINDS = ("mtp", "dspark")# Human label per resolved spec mode, for launch logging and the UI notice.@@ -3422,7 +3422,7 @@ def _is_root_dflash_drafter_path(path: str) -> bool:_BIG_ENDIAN_GGUF_FILENAME_RE = re.compile(r"(^|[-_])be(?:[._-]|$)", re.IGNORECASE)_GGUF_KNOWN_QUANT_RE = re.compile(r"(UD-)?"- r"(MXFP[0-9]+(?:_[A-Z0-9]+)*"+ r"((?:MX|NV)FP[0-9]+(?:_[A-Z0-9]+)*"r"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?"r"|P?TQ[0-9]+_[0-9]+"r"|Q[0-9]+_K_[A-Z]+"@@ -7450,6 +7450,9 @@ _LAZY_READ_TENSORS: dict[str, tuple[str, ...]] = {"qwen4exp": ("per_layer_token_embd.weight",),}_LAZY_READ_AUTO_MIN_BYTES = 4 * 1024**3+# Embedded NextN/MTP heads llama.cpp skips at load unless --spec-type draft-mtp, measured:+# Nemotron 3.5 Super loads 2987 MiB less with MTP off (b11642 + ggml-org#30520).+_NEXTN_SKIPPED_WITHOUT_MTP_ARCHS = frozenset({"nemotron_h_moe"})# --tensor-read-lazy predates ggml-org/llama.cpp#27969; a build reads only its own spelling._LAZY_MODE_SPELLINGS: dict[str, tuple[frozenset[str], str]] = {"--lazy-mode": (frozenset({"-lzm", "--lazy-mode"}), "LLAMA_ARG_LAZY_MODE"),@@ -8568,6 +8571,8 @@ class LlamaCppBackend:self._expert_feed_forward_length: Optional[int] = Noneself._expert_shared_feed_forward_length: Optional[int] = Noneself._expert_shared_count: Optional[int] = None+ # Nemotron 3.5: routed experts run in this latent width, not n_embd.+ self._moe_latent_size: Optional[int] = None# Gemma 3n / Gemma 4 per-layer input embedding width.self._embedding_length_per_layer_input: Optional[int] = Noneself._vocab_size: Optional[int] = None@@ -11053,10 +11058,13 @@ class LlamaCppBackend:return total@staticmethod- def _gguf_scan_tensor_bytes(path: str) -> "tuple[Optional[str], dict[str, int], int]":+ def _gguf_scan_tensor_bytes(+ path: str, also: Optional[Callable[[str], bool]] = None+ ) -> "tuple[Optional[str], dict[str, int], int]":"""(architecture, lazy-read candidate bytes by name, routed expert bytes) from oneGGUF header. Streamed: ``GGUFReader`` materialises the vocabulary under the load- lock. A quant type gguf predates is sized from the next tensor's offset."""+ lock. A quant type gguf predates is sized from the next tensor's offset. Names+ ``also`` accepts are kept by name too, routed experts included."""from gguf.constants import GGML_QUANT_SIZESfrom core.inference.offload_layout import _BLOCK_RE, _MOE_EXPERT_RE@@ -11092,11 +11100,12 @@ class LlamaCppBackend:ggml_type = struct.unpack("<I", f.read(4))[0]offset = struct.unpack("<Q", f.read(8))[0]offsets.append(offset)- block_match = _BLOCK_RE.match(raw_name.decode("utf-8", "replace"))+ name = raw_name.decode("utf-8", "replace")+ block_match = _BLOCK_RE.match(name)is_expert = bool(block_match and _MOE_EXPERT_RE.match(block_match.group(2)))- if not is_expert and raw_name not in wanted:+ kept = also is not None and also(name)+ if not is_expert and raw_name not in wanted and not kept:continue- name = raw_name.decode("utf-8", "replace")block = GGML_QUANT_SIZES.get(ggml_type)if block is None:unsized.append((name, offset))@@ -11104,7 +11113,7 @@ class LlamaCppBackend:size = math.prod(dims) // block[0] * block[1]if is_expert:experts += size- else:+ if not is_expert or kept:named[name] = sizeif unsized:data_start = -(-f.tell() // alignment) * alignment@@ -11114,9 +11123,10 @@ class LlamaCppBackend:later = ordered[bisect.bisect_right(ordered, offset) :]size = max(0, (later[0] if later else data_end) - offset)block_match = _BLOCK_RE.match(name)- if block_match and _MOE_EXPERT_RE.match(block_match.group(2)):+ is_expert = bool(block_match and _MOE_EXPERT_RE.match(block_match.group(2)))+ if is_expert:experts += size- else:+ if not is_expert or (also is not None and also(name)):named[name] = sizereturn architecture, named, experts@@ -11155,6 +11165,38 @@ class LlamaCppBackend:self._gguf_tensor_scan_cache = (key, result)return result+ def _unloaded_nextn_bytes(self, model_path: Optional[str]) -> int:+ """Bytes of the embedded NextN/MTP blocks llama.cpp leaves unloaded without+ ``--spec-type draft-mtp`` (nextn_flags marks them TENSOR_SKIP unless load_mtp).+ Only for architectures measured to skip them; 0 when unknown or unreadable."""+ from core.inference.offload_layout import _BLOCK_RE, split_shard_paths++ nextn = int(getattr(self, "_nextn_predict_layers", None) or 0)+ n_blocks = int(getattr(self, "_n_layers", None) or 0)+ if (+ not model_path+ or nextn <= 0+ or n_blocks <= nextn+ or getattr(self, "_architecture", None) not in _NEXTN_SKIPPED_WITHOUT_MTP_ARCHS+ ):+ return 0+ first = n_blocks - nextn++ def in_head(name: str) -> bool:+ match = _BLOCK_RE.match(name)+ return bool(match) and int(match.group(1)) >= first++ try:+ return sum(+ size+ for p in (split_shard_paths(model_path) or [model_path])+ for name, size in self._gguf_scan_tensor_bytes(p, also = in_head)[1].items()+ if in_head(name)+ )+ except Exception as e: # missing shard or truncated header: discount nothing+ logger.debug("NextN block scan failed for %s (%s)", model_path, e)+ return 0+def _lazy_read_host_bytes(self,model_path: Optional[str],@@ -18345,13 +18387,16 @@ class LlamaCppBackend:return verify_rowsub = max(1, int(self._DEFAULT_N_UBATCH if n_ubatch is None else n_ubatch))width = self._compute_activation_width()- if drafter_path:- db = self._draft_backend_for(drafter_path)+ db = self._draft_backend_for(drafter_path) if drafter_path else None+ if db is not None:draft_width = getattr(db, "_compute_activation_width", lambda: 0)()if draft_width > 0:width = draft_width + 2 * (getattr(self, "_embedding_length", None) or 0)activations = int(width * ub * 4 * self._COMPUTE_BUFFER_SAFETY)- return verify_rows + max(0, ub * 2 * n_ctx + activations - self._MTP_DRAFT_COMPUTE_BYTES)+ spec = verify_rows + max(0, ub * 2 * n_ctx + activations - self._MTP_DRAFT_COMPUTE_BYTES)+ if getattr(db, "_architecture", None) == "dflash":+ spec = max(spec, self._DFLASH_DRAFT_COMPUTE_BYTES)+ return specdef _spec_verify_rows_bytes(self, n_parallel: int, spec_draft_n_max: int) -> int:"""Target output rows for verified draft tokens, wherever the drafter runs."""@@ -18437,6 +18482,11 @@ class LlamaCppBackend:# at which "does it fit" means "does every layer stay on the GPU"._MMPROJ_FIT_FLOOR_CTX = 8192_MTP_DRAFT_COMPUTE_BYTES = 224 * 1024 * 1024 # MTP draft decode graph beyond its KV+ # A DFlash/DSpark draft context re-reserves a flat block graph once the drafter initialises,+ # independent of n_ctx. Measured on llama.cpp b11642, draft graph + target verify graph:+ # Nemotron 3.5 Bolt DSpark (block 8) 528.5 + 44 MiB, LiLiCorr (block 8, SWA 1024) 307 + 60 MiB.+ # The _MTP_DRAFT_COMPUTE_BYTES floor is charged beside this, so the floor is the excess over it.+ _DFLASH_DRAFT_COMPUTE_BYTES = 349 * 1024 * 1024# Draft depth to budget when the extras own the spec block and the probe cannot# read the build's own default off its --help. Shipped values are 3# (common_params_speculative_draft::n_max) and 16; take the deeper, since the@@ -18497,7 +18547,9 @@ class LlamaCppBackend:shared = dim("_expert_shared_feed_forward_length") or (n_ff_exp * dim("_expert_shared_count"))- widths.append(n_used * (2 * n_embd + 3 * n_ff_exp) + 3 * shared)+ # Nemotron 3.5 routes experts through a moe_latent_size projection.+ n_embd_exp = dim("_moe_latent_size") or n_embd+ widths.append(n_used * (2 * n_embd_exp + 3 * n_ff_exp) + 3 * shared)inner = dim("_ssm_inner_size")if inner > 0:conv_in = inner + 2 * (dim("_ssm_group_count") or 1) * dim("_ssm_state_size")@@ -19491,6 +19543,7 @@ class LlamaCppBackend:self._expert_feed_forward_length = Noneself._expert_shared_feed_forward_length = Noneself._expert_shared_count = None+ self._moe_latent_size = Noneself._embedding_length_per_layer_input = Noneself._vocab_size = Noneself._kv_key_length = None@@ -19616,6 +19669,7 @@ class LlamaCppBackend:f"{arch}.expert_feed_forward_length": "expert_feed_forward_length",f"{arch}.expert_shared_feed_forward_length": "expert_shared_feed_forward_length",f"{arch}.expert_shared_count": "expert_shared_count",+ f"{arch}.moe_latent_size": "moe_latent_size",f"{arch}.embedding_length_per_layer_input": "embedding_length_per_layer_input",f"{arch}.attention.key_length": "kv_key_length",f"{arch}.attention.value_length": "kv_value_length",@@ -19684,6 +19738,9 @@ class LlamaCppBackend:self._feed_forward_length = max(self._feed_forward_length_by_layer)+ elif attr in ("expert_used_count", "expert_feed_forward_length") and val_a:+ # Per-layer on Nemotron 3.5 Bolt; the widest layer sizes the graph.+ setattr(self, f"_{attr}", max(int(x) for x in val_a))else:self._gguf_skip_value(f, vtype)else:@@ -26688,6 +26745,12 @@ class LlamaCppBackend:_user_mtp_via_extrasor (_auto_studio_mtp and _mtp_effective not in ("dspark", "dflash")))+ # Without draft-mtp the embedded head is never loaded, so its blocks+ # leave the weights the fit prices (about 3 GB on Nemotron 3.5 Super).+ if not _engaged_is_mtp:+ _nextn_unloaded = self._unloaded_nextn_bytes(model_path)+ gguf_size -= _nextn_unloaded+ model_size -= _nextn_unloaded# The recurrent rollback copies are a WIDER set than that copy# (_TARGET_ROLLBACK_SPEC_TYPES): DSpark and DFlash pay them too,# and draft-simple is the one engaged draft mode that does not,diff --git a/studio/backend/core/inference/offload_layout.py b/studio/backend/core/inference/offload_layout.pyindex 4a099fb0c09..f6cdd42fd06 100644--- a/studio/backend/core/inference/offload_layout.py+++ b/studio/backend/core/inference/offload_layout.py@@ -18,6 +18,8 @@ import oslogger = logging.getLogger(__name__)+# Hybrid Mamba-2 archs storing head_count_kv (and on Bolt expert_used_count) per layer.+_NEMOTRON_H_ARCHS = frozenset({"nemotron_h", "nemotron_h_moe"})_BLOCK_RE = re.compile(r"^blk\.(\d+)\.(.+)$")# Sparse MoE experts: only expert_used_count of expert_count read per token, so host traffic is a small fraction of@@ -215,7 +217,18 @@ def _layout_from_readers(readers) -> ModelLayout:if not n_kv_head or not key_len or not val_len:return ModelLayout()- kv_per_token = int(n_attention) * int(n_kv_head) * (int(key_len) + int(val_len)) * 2+ nemotron_h = arch in _NEMOTRON_H_ARCHS+ if nemotron_h and isinstance(n_kv_head, (list, tuple)):+ # Per-layer head_count_kv: 0 marks a layer without an attention cache. The recurrent (Mamba) layers are the ones+ # with neither attention nor an FFN; the rest are dense or MoE FFN blocks.+ heads = [int(h) for h in list(n_kv_head)[:n_layers]]+ ffn = _field(reader, f"{arch}.feed_forward_length")+ ffn = [int(f) for f in list(ffn)[:n_layers]] if isinstance(ffn, (list, tuple)) else [0] * len(heads)+ n_attention = sum(1 for h in heads if h > 0)+ n_recurrent = sum(1 for h, f in zip(heads, ffn) if h == 0 and f == 0)+ kv_per_token = sum(heads) * (int(key_len) + int(val_len)) * 2+ else:+ kv_per_token = int(n_attention) * int(n_kv_head) * (int(key_len) + int(val_len)) * 2# Charging every layer the full context above is the safe direction for the TOTAL; what it cannot say is which# layers hold the big caches.@@ -234,7 +247,10 @@ def _layout_from_readers(readers) -> ModelLayout:recurrent = n_recurrent * (n_embd_r + n_embd_s) * 4n_expert = int(_field(reader, f"{arch}.expert_count") or 0)- n_expert_used = int(_field(reader, f"{arch}.expert_used_count") or 0)+ n_expert_used = _field(reader, f"{arch}.expert_used_count") or 0+ if nemotron_h and isinstance(n_expert_used, (list, tuple)):+ n_expert_used = max((int(n) for n in n_expert_used), default = 0) # per layer on Nemotron 3.5 Bolt+ n_expert_used = int(n_expert_used)is_moe = bool(n_expert)spill: dict[int, int] = {}diff --git a/studio/backend/hub/services/models/gguf_variants.py b/studio/backend/hub/services/models/gguf_variants.pyindex b9c8ba94208..5809d108dec 100644--- a/studio/backend/hub/services/models/gguf_variants.py+++ b/studio/backend/hub/services/models/gguf_variants.py@@ -867,7 +867,7 @@ _CACHE_SPLIT_RE = re.compile(r"-(\d{3,})-of-(\d{3,})(?=\.gguf$)", re.IGNORECASE)# Only enumerates candidates for the resolver to adjudicate; drift costs a candidate, not a verdict._KNOWN_QUANT_RE = re.compile(r"(UD-)?"- r"(MXFP[0-9]+(?:_[A-Z0-9]+)*"+ r"((?:MX|NV)FP[0-9]+(?:_[A-Z0-9]+)*"r"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?"r"|P?TQ[0-9]+_[0-9]+"r"|Q[0-9]+_K_[A-Z]+"diff --git a/studio/backend/hub/utils/gguf.py b/studio/backend/hub/utils/gguf.pyindex 7f1bdd57459..4fc263a30f9 100644--- a/studio/backend/hub/utils/gguf.py+++ b/studio/backend/hub/utils/gguf.py@@ -76,7 +76,7 @@ GGUF_QUANT_PREFERENCE = [_GGUF_SPLIT_SUFFIX_RE = re.compile(r"-\d{3,}-of-(\d{3,})", re.IGNORECASE)_GGUF_QUANT_RE = re.compile(r"(UD-)?"- r"(MXFP[0-9]+(?:_[A-Z0-9]+)*"+ r"((?:MX|NV)FP[0-9]+(?:_[A-Z0-9]+)*"r"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?"r"|P?TQ[0-9]+_[0-9]+"r"|Q[0-9]+_K_[A-Z]+"@@ -103,7 +103,7 @@ def is_imatrix_filename(path: str) -> bool:# dspark and dflash are the same DeepSeek V4 Flash drafter: the folder it ships in and the architecture it reports.-_DRAFTER_KINDS = ("mtp", "dspark", "dflash", "eagle3")+_DRAFTER_KINDS = ("mtp", "dspark", "dflash", "eagle3", "lilicorr")# Directories only: mtp/ and dspark/ are always a publisher's companion folder, while dflash/ is a family name a user picks for real weights._DRAFTER_DIR_KINDS = ("mtp", "dspark")@@ -116,7 +116,7 @@ _DSPARK_BEFORE_QUANT_RE = re.compile(def is_mtp_drafter_path(path: str) -> bool:- """True for a separate-file drafter, a companion to the main model rather than a selectable quant: the repo-root ``mtp-*.gguf`` (the Q8_0 copy unsloth ships for llama.cpp ``-hf`` auto-discovery), the ``MTP/`` subdir copies (Gemma 4), the ``dspark/`` drafters (DeepSeek V4 Flash), the ``<model>-dspark-<quant>.gguf`` drafters (prism-ml Bonsai) and the ``eagle3-*.gguf`` draft heads (ggml-org gpt-oss). Repos that bake the head into the main GGUF (Qwen) have no such file, so this is False for them. Must be excluded from main-model selection everywhere mmproj is. Matched by basename prefix, by an exact parent dir for ``_DRAFTER_DIR_KINDS``, or by ``_DSPARK_BEFORE_QUANT_RE``; never a bare substring, since the kind names double as family names, so ``Qwen3.6-27B-MTP-Q4_K_M.gguf`` and ``Qwen3.6-35B-A3B-DFlash-Q4_K_M.gguf`` ARE the model. CANONICAL COPY. Two mirrors must change in lockstep: utils/models/model_config.py ``_is_mtp_drafter`` (utils cannot import hub) and core/inference/llama_cpp.py ``_is_companion_gguf_path`` (core avoids hub imports; bundles the mmproj check)."""+ """True for a separate-file drafter, a companion to the main model rather than a selectable quant: the repo-root ``mtp-*.gguf`` (the Q8_0 copy unsloth ships for llama.cpp ``-hf`` auto-discovery), the ``MTP/`` subdir copies (Gemma 4), the ``dspark/`` drafters (DeepSeek V4 Flash), the ``<model>-dspark-<quant>.gguf`` drafters (prism-ml Bonsai) the ``eagle3-*.gguf`` draft heads (ggml-org gpt-oss) and the ``lilicorr-*.gguf`` drafters (NVIDIA Nemotron 3.5). Repos that bake the head into the main GGUF (Qwen) have no such file, so this is False for them. Must be excluded from main-model selection everywhere mmproj is. Matched by basename prefix, by an exact parent dir for ``_DRAFTER_DIR_KINDS``, or by ``_DSPARK_BEFORE_QUANT_RE``; never a bare substring, since the kind names double as family names, so ``Qwen3.6-27B-MTP-Q4_K_M.gguf`` and ``Qwen3.6-35B-A3B-DFlash-Q4_K_M.gguf`` ARE the model. CANONICAL COPY. Two mirrors must change in lockstep: utils/models/model_config.py ``_is_mtp_drafter`` (utils cannot import hub) and core/inference/llama_cpp.py ``_is_companion_gguf_path`` (core avoids hub imports; bundles the mmproj check)."""p = path.replace("\\", "/").lower()if not p.endswith(".gguf"):return Falsediff --git a/studio/backend/tests/test_nemotron35_bolt_super.py b/studio/backend/tests/test_nemotron35_bolt_super.pynew file mode 100644index 00000000000..48d97cd4cfa--- /dev/null+++ b/studio/backend/tests/test_nemotron35_bolt_super.py@@ -0,0 +1,169 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""NVIDIA Nemotron 3.5 Bolt and Super GGUF repos load the right files and sampling.++Both repos ship files the quant parser did not know about:++- Super has an ``NVFP4/`` quant folder. ``NVFP4`` was not a quant token (only MXFP was),+ so the ``NVFP4`` variant resolved to ``LiLiCorr/lilicorr-...-NVFP4.gguf``, a 1.3 GB+ drafter, and loaded it as the main model.+- Super's ``LiLiCorr/`` drafter was listed as a selectable quant. Super uses its embedded+ MTP head; the LiLiCorr drafter is never launched, so it must not appear as a variant.+- A ``dspark-...-NVFP4.gguf`` / ``dflash-...-NVFP4.gguf`` sidecar kept ``-nvfp4`` in its pairing+ stem, so a local folder load attached no drafter. Bolt ships its LiLiCorr drafter as+ ``dflash-...-NVFP4.gguf``.++Sampling follows NVIDIA's recommendation for both: temperature 1.0, top_p 0.95.+"""++from __future__ import annotations++import sys+from pathlib import Path+from types import SimpleNamespace++import pytest++_backend_root = Path(__file__).resolve().parent.parent+_tests_dir = Path(__file__).resolve().parent+for _p in (_backend_root, _tests_dir):+ if str(_p) not in sys.path:+ sys.path.insert(0, str(_p))+++SUPER_REPO = "unsloth/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-GGUF"+SUPER = "NVIDIA-Nemotron-3.5-Super-VL-120B-A12B"+_SUPER_SPLITS = {+ "NVFP4": 3, "Q8_0": 4, "UD-IQ1_M": 2, "UD-IQ2_M": 3, "UD-IQ2_XXS": 3, "UD-IQ3_XXS": 3,+ "UD-Q2_K_XL": 3, "UD-Q3_K_XL": 3, "UD-Q4_K_XL": 3, "UD-Q5_K_XL": 4, "UD-Q6_K_XL": 4,+}+SUPER_FILES = [".gitattributes", "README.md", "mmproj-BF16.gguf",+ f"LiLiCorr/lilicorr-{SUPER}-NVFP4.gguf"] + [+ f"{q}/{SUPER}-{q}-{i:05d}-of-{n:05d}.gguf"+ for q, n in _SUPER_SPLITS.items() for i in range(1, n + 1)+]++BOLT_REPO = "unsloth/NVIDIA-Nemotron-3.5-Bolt-74B-A9B-GGUF"+BOLT = "NVIDIA-Nemotron-3.5-Bolt-74B-A9B"+# NVIDIA's QAD IQ2_XXS, its LiLiCorr drafter (GGUF arch dflash, named for llama.cpp's dflash- sibling lookup) and mmproj.+BOLT_FILES = [".gitattributes", "README.md", "mmproj-BF16.gguf", f"{BOLT}-IQ2_XXS.gguf",+ f"dflash-{BOLT}-NVFP4.gguf"]+++def _model_info(files):+ return SimpleNamespace(+ siblings = [SimpleNamespace(rfilename = f, size = 1 << 30) for f in files],+ gguf = None,+ sha = "0" * 40,+ )+++def test_super_nvfp4_variant_resolves_to_the_weights_not_the_drafter(monkeypatch):+ from core.inference import llama_cpp++ monkeypatch.setattr(+ llama_cpp, "call_hub_with_anonymous_retry", lambda fn, token, repo: list(SUPER_FILES)+ )+ first, extra = llama_cpp._resolve_variant_gguf_files(SUPER_REPO, "NVFP4")+ assert first == f"NVFP4/{SUPER}-NVFP4-00001-of-00003.gguf"+ assert extra == [f"NVFP4/{SUPER}-NVFP4-0000{i}-of-00003.gguf" for i in (2, 3)]++[email protected]("quant", sorted(_SUPER_SPLITS))+def test_every_super_quant_resolves_to_its_own_folder(monkeypatch, quant):+ from core.inference import llama_cpp++ monkeypatch.setattr(+ llama_cpp, "call_hub_with_anonymous_retry", lambda fn, token, repo: list(SUPER_FILES)+ )+ first, extra = llama_cpp._resolve_variant_gguf_files(SUPER_REPO, quant)+ assert first == f"{quant}/{SUPER}-{quant}-00001-of-{_SUPER_SPLITS[quant]:05d}.gguf"+ assert len(extra) == _SUPER_SPLITS[quant] - 1+++def test_lilicorr_is_a_drafter_not_a_variant():+ """All three mirrors of the drafter predicate must agree, or one path lists it."""+ from core.inference import llama_cpp+ from hub.utils import gguf as hub_gguf+ from utils.models import model_config++ path = f"LiLiCorr/lilicorr-{SUPER}-NVFP4.gguf"+ assert llama_cpp._drafter_path_kind(path) == "lilicorr"+ assert hub_gguf.is_mtp_drafter_path(path)+ assert model_config._is_mtp_drafter(path)+++def test_super_variant_menu_lists_exactly_the_real_quants(monkeypatch):+ from utils.models import model_config++ monkeypatch.setattr(+ model_config, "_hub_model_info_slow_link",+ lambda repo, token, files_metadata = True: _model_info(SUPER_FILES),+ )+ variants, has_vision = model_config.list_gguf_variants(SUPER_REPO)+ assert has_vision+ assert sorted(v.quant for v in variants) == sorted(_SUPER_SPLITS)+++def test_bolt_variant_menu_is_the_single_iq2_xxs(monkeypatch):+ from utils.models import model_config++ monkeypatch.setattr(+ model_config, "_hub_model_info_slow_link",+ lambda repo, token, files_metadata = True: _model_info(BOLT_FILES),+ )+ variants, has_vision = model_config.list_gguf_variants(BOLT_REPO)+ assert has_vision+ assert [v.quant for v in variants] == ["IQ2_XXS"]+++def test_bolt_local_folder_finds_its_dflash_sidecar(tmp_path):+ """detect_dflash_file trusts the header, not the prefix: the sidecar declares dflash."""+ from test_kv_cache_estimation import _make_gguf_bytes+ from utils.models.drafters.dflash import detect_dflash_file++ for name in BOLT_FILES:+ arch = "dflash" if name.startswith("dflash-") else "nemotron_h_moe"+ (tmp_path / name).write_bytes(_make_gguf_bytes(arch, {"general.architecture": arch}))+ found = detect_dflash_file(str(tmp_path / f"{BOLT}-IQ2_XXS.gguf"))+ assert found is not None and Path(found).name == f"dflash-{BOLT}-NVFP4.gguf"+++def test_nvfp4_suffixed_dspark_sidecar_pairs_with_its_weights(tmp_path):+ """The quant token is stripped from the drafter's pairing stem, NVFP4 included."""+ from utils.models.model_config import detect_dspark_file++ for name in (f"{BOLT}-UD-IQ2_XXS.gguf", f"dspark-{BOLT}-NVFP4.gguf"):+ (tmp_path / name).write_bytes(b"GGUF")+ found = detect_dspark_file(str(tmp_path / f"{BOLT}-UD-IQ2_XXS.gguf"))+ assert found is not None and Path(found).name == f"dspark-{BOLT}-NVFP4.gguf"+++EXPECTED_SAMPLING = {"temperature": 1.0, "top_p": 0.95}++NEMOTRON35_IDS = [+ SUPER_REPO,+ f"{SUPER_REPO}:UD-Q4_K_XL",+ BOLT_REPO,+ f"{BOLT_REPO}:IQ2_XXS",+ "nvidia/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-BF16",+ "unsloth/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4",+ "/home/u/.cache/huggingface/hub/models--unsloth--NVIDIA-Nemotron-3.5-Bolt-74B-A9B-GGUF/snapshots/deadbeef",+ f"/data/models/{BOLT}-GGUF/{BOLT}-IQ2_XXS.gguf",+]++[email protected]("model_id", NEMOTRON35_IDS)+def test_nemotron35_sampling_defaults(model_id):+ from utils.inference.inference_config import load_inference_config++ config = load_inference_config(model_id)+ for key, want in EXPECTED_SAMPLING.items():+ assert config[key] == want, f"{model_id}: {key} was {config[key]}, expected {want}"+++def test_older_nemotrons_keep_their_sampling():+ from utils.inference.inference_config import load_inference_config++ assert load_inference_config("unsloth/Nemotron-3-Nano-30B-A3B-GGUF")["top_p"] == 1.0diff --git a/studio/backend/tests/test_nemotron35_planner.py b/studio/backend/tests/test_nemotron35_planner.pynew file mode 100644index 00000000000..5322fa169de--- /dev/null+++ b/studio/backend/tests/test_nemotron35_planner.py@@ -0,0 +1,291 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Memory planning for NVIDIA Nemotron 3.5 Bolt and Super (arch nemotron_h_moe).++Measured on llama.cpp b11642 + ggml-org#30520 against Studio's estimates:++- The offload layout raised on the per-layer ``head_count_kv`` array and, past that,+ would have charged all 88 layers a KV cache and no Mamba state.+- The embedded NextN head (2987 MiB on Super UD-IQ2_XXS) is never loaded without+ ``--spec-type draft-mtp``, but the context fit priced it anyway.+- The routed experts run in ``moe_latent_size`` (1024), not n_embd (4096), so Super's+ compute width was over-priced; Bolt's per-layer ``expert_used_count`` was read as+ missing, which dropped the expert term and left Bolt's compute 6 MiB short.+- The DSpark draft context re-reserves a flat 528.5 MiB block graph that the drafter+ compute estimate missed, leaving Bolt + DSpark 177-332 MiB short.++Every other architecture must price exactly as before.+"""++from __future__ import annotations++import sys+from pathlib import Path++import numpy as np+import pytest++_backend_root = Path(__file__).resolve().parent.parent+if str(_backend_root) not in sys.path:+ sys.path.insert(0, str(_backend_root))++MIB = 1024 * 1024+++class _StubField:+ def __init__(self, value):+ self._value = value++ def contents(self):+ return self._value+++class _StubTensor:+ def __init__(self, name, n_bytes):+ self.name = name+ self.n_bytes = n_bytes+++class _StubReader:+ def __init__(self, fields, tensors):+ self.fields = {k: _StubField(v) for k, v in fields.items()}+ self.tensors = tensors+++# 8 layers in Nemotron-H order: Mamba (no attention, no FFN), MoE FFN, attention.+_HEADS = [0, 0, 2, 0, 0, 2, 0, 0]+_FFN = [0, 1536, 0, 0, 2048, 0, 0, 2304]+_SSM = {"inner_size": 8192, "state_size": 128, "group_count": 8, "conv_kernel": 4}+++def _nemotron_fields(arch = "nemotron_h_moe", heads = _HEADS, used = (0, 9, 0, 0, 9, 0, 0, 9), **extra):+ fields = {+ "general.architecture": arch,+ f"{arch}.block_count": len(heads),+ f"{arch}.attention.head_count_kv": list(heads),+ f"{arch}.attention.head_count": 32,+ f"{arch}.embedding_length": 4096,+ f"{arch}.attention.key_length": 128,+ f"{arch}.attention.value_length": 128,+ f"{arch}.feed_forward_length": list(_FFN),+ f"{arch}.expert_count": 496,+ f"{arch}.expert_used_count": list(used),+ f"{arch}.context_length": 262144,+ }+ fields.update({f"{arch}.ssm.{k}": v for k, v in _SSM.items()})+ fields.update(extra)+ return fields+++def _tensors(n_layers):+ return [_StubTensor(f"blk.{i}.ffn_up_exps.weight", MIB) for i in range(n_layers)] + [+ _StubTensor("token_embd.weight", 4 * MIB),+ _StubTensor("output.weight", 4 * MIB),+ ]+++def _recurrent_bytes(n_recurrent):+ s = _SSM+ n_embd_r = (s["conv_kernel"] - 1) * (s["inner_size"] + 2 * s["group_count"] * s["state_size"])+ return n_recurrent * (n_embd_r + s["state_size"] * s["inner_size"]) * 4+++def test_nemotron_layout_charges_kv_only_to_attention_layers():+ from core.inference.offload_layout import _layout_from_reader++ layout = _layout_from_reader(_StubReader(_nemotron_fields(), _tensors(8)))+ assert layout.complete+ assert layout.n_attention_layers == 2+ assert layout.kv_bytes_per_token_f16 == (2 + 2) * (128 + 128) * 2+ # Layers 0, 3, 6 carry neither attention nor an FFN: the Mamba layers.+ assert layout.recurrent_bytes == _recurrent_bytes(3)+ assert layout.n_expert_used == 9+++def test_nemotron_layout_leaves_the_nextn_block_out_of_the_trunk():+ from core.inference.offload_layout import _layout_from_reader++ fields = _nemotron_fields(heads = _HEADS + [2], **{"nemotron_h_moe.nextn_predict_layers": 1})+ layout = _layout_from_reader(_StubReader(fields, _tensors(9)))+ assert layout.complete+ assert layout.n_attention_layers == 2+++def test_per_layer_kv_heads_on_other_archs_still_abstain():+ """Only Nemotron-H's array is interpreted; any other arch still raises here, which+ layout_from_gguf turns into an abstention, exactly as before."""+ from core.inference.offload_layout import _layout_from_reader++ fields = _nemotron_fields(arch = "jamba")+ with pytest.raises(TypeError):+ _layout_from_reader(_StubReader(fields, _tensors(8)))+++def test_scalar_hybrid_layout_is_unchanged():+ from core.inference.offload_layout import _layout_from_reader++ fields = {+ "general.architecture": "qwen35moe",+ "qwen35moe.block_count": 48,+ "qwen35moe.full_attention_interval": 4,+ "qwen35moe.attention.head_count_kv": 2,+ "qwen35moe.attention.head_count": 16,+ "qwen35moe.embedding_length": 2048,+ "qwen35moe.attention.key_length": 256,+ "qwen35moe.attention.value_length": 256,+ "qwen35moe.expert_count": 256,+ "qwen35moe.expert_used_count": 8,+ "qwen35moe.ssm.inner_size": 4096,+ "qwen35moe.ssm.state_size": 128,+ "qwen35moe.ssm.group_count": 16,+ "qwen35moe.ssm.conv_kernel": 4,+ }+ layout = _layout_from_reader(_StubReader(fields, _tensors(48)))+ assert layout.complete+ assert layout.n_attention_layers == 12+ assert layout.kv_bytes_per_token_f16 == 12 * 2 * (256 + 256) * 2+ assert layout.n_expert_used == 8+ n_embd_r = 3 * (4096 + 2 * 16 * 128)+ assert layout.recurrent_bytes == 36 * (n_embd_r + 128 * 4096) * 4+++def _backend(**dims):+ from core.inference.llama_cpp import LlamaCppBackend++ b = LlamaCppBackend.__new__(LlamaCppBackend)+ for name, value in dims.items():+ setattr(b, f"_{name}", value)+ return b+++def test_latent_moe_width_uses_the_latent_size():+ common = dict(embedding_length = 4096, expert_used_count = 22, expert_feed_forward_length = 2688,+ expert_shared_feed_forward_length = 5376, n_experts = 512)+ latent = _backend(moe_latent_size = 1024, **common)._compute_activation_width()+ assert latent == 22 * (2 * 1024 + 3 * 2688) + 3 * 5376+ # No latent key: the formula every other MoE arch gets, unchanged.+ plain = _backend(**common)._compute_activation_width()+ assert plain == 22 * (2 * 4096 + 3 * 2688) + 3 * 5376+++def _write_gguf(path, arch, kv, tensors):+ from gguf import GGUFWriter++ writer = GGUFWriter(str(path), arch)+ for key, value in kv.items():+ if isinstance(value, list):+ writer.add_array(key, value)+ else:+ writer.add_uint32(key, value)+ for name, n in tensors:+ writer.add_tensor(name, np.zeros(n, dtype = np.float32))+ writer.write_header_to_file()+ writer.write_kv_data_to_file()+ writer.write_tensors_to_file()+ writer.close()+++def test_per_layer_expert_dims_and_latent_size_are_read(tmp_path):+ from core.inference.llama_cpp import LlamaCppBackend++ path = tmp_path / "bolt.gguf"+ a = "nemotron_h_moe"+ _write_gguf(path, a, {+ f"{a}.block_count": 4,+ f"{a}.embedding_length": 64,+ f"{a}.expert_count": 8,+ f"{a}.expert_used_count": [0, 9, 0, 9],+ f"{a}.expert_feed_forward_length": [0, 1536, 0, 2560],+ f"{a}.moe_latent_size": 16,+ }, [("blk.0.attn_norm.weight", 64)])+ b = LlamaCppBackend(manages_processes = False)+ b._read_gguf_metadata(str(path))+ assert b._expert_used_count == 9+ assert b._expert_feed_forward_length == 2560+ assert b._moe_latent_size == 16+++def _nextn_gguf(tmp_path, arch, nextn):+ path = tmp_path / f"{arch}.gguf"+ kv = {f"{arch}.block_count": 3, f"{arch}.embedding_length": 64}+ if nextn:+ kv[f"{arch}.nextn_predict_layers"] = nextn+ _write_gguf(path, arch, kv, [+ ("token_embd.weight", 256),+ ("blk.0.attn_norm.weight", 64),+ ("blk.1.ffn_up_exps.weight", 512),+ ("blk.2.nextn.eh_proj.weight", 1024),+ ("blk.2.ffn_up_exps.weight", 2048),+ ])+ return str(path)+++def test_unloaded_nextn_bytes_are_the_head_block_only(tmp_path):+ from core.inference.llama_cpp import LlamaCppBackend++ path = _nextn_gguf(tmp_path, "nemotron_h_moe", 1)+ b = LlamaCppBackend(manages_processes = False)+ b._read_gguf_metadata(path)+ assert b._unloaded_nextn_bytes(path) == 4 * (1024 + 2048)++[email protected]("arch, nextn", [("qwen35moe", 1), ("glm4moe", 1), ("nemotron_h_moe", 0)])+def test_unloaded_nextn_bytes_are_zero_elsewhere(tmp_path, arch, nextn):+ from core.inference.llama_cpp import LlamaCppBackend++ path = _nextn_gguf(tmp_path, arch, nextn)+ b = LlamaCppBackend(manages_processes = False)+ b._read_gguf_metadata(path)+ assert b._unloaded_nextn_bytes(path) == 0+++def test_tensor_scan_is_unchanged_without_also(tmp_path):+ from core.inference.llama_cpp import LlamaCppBackend++ path = _nextn_gguf(tmp_path, "nemotron_h_moe", 1)+ arch, named, experts = LlamaCppBackend._gguf_scan_tensor_bytes(path)+ assert arch == "nemotron_h_moe"+ assert named == {}+ assert experts == 4 * (512 + 2048)+++class _Draft:+ def __init__(self, architecture):+ self._architecture = architecture++ def _compute_activation_width(self):+ return 0++[email protected]("architecture, floored", [("dflash", True), ("qwen35", False)])+def test_dflash_draft_compute_is_floored(architecture, floored):+ b = _backend(embedding_length = 4096, vocab_size = 131072)+ b._draft_backend_for = lambda path: _Draft(architecture)+ got = b._mtp_draft_compute_bytes(32768, drafter_path = "dspark.gguf", spec_draft_n_max = 3)+ b._draft_backend_for = lambda path: None+ unfloored = b._mtp_draft_compute_bytes(32768, drafter_path = "dspark.gguf", spec_draft_n_max = 3)+ if floored:+ assert got == max(unfloored, b._DFLASH_DRAFT_COMPUTE_BYTES)+ else:+ assert got == unfloored+++# Draft graph + target verify graph a DFlash drafter adds, measured on llama.cpp b11642 (MiB).+_DFLASH_MEASURED_COMPUTE_MIB = {+ "Bolt DSpark, block 8": 528.5 + 44.0,+ "Bolt LiLiCorr, block 8, SWA 1024": 307.0 + 60.1,+}++[email protected]("drafter", sorted(_DFLASH_MEASURED_COMPUTE_MIB))+def test_dflash_compute_reserve_covers_the_measurement_without_double_counting(drafter):+ """The separate _MTP_DRAFT_COMPUTE_BYTES floor rides beside the DFlash floor, so the two+ together must cover the measurement, but charging the full measurement again on top of it+ (572 MiB) priced Bolt + LiLiCorr 224 MiB over what llama.cpp allocates."""+ from core.inference.llama_cpp import LlamaCppBackend++ reserve = (LlamaCppBackend._MTP_DRAFT_COMPUTE_BYTES + LlamaCppBackend._DFLASH_DRAFT_COMPUTE_BYTES) / MIB+ measured = _DFLASH_MEASURED_COMPUTE_MIB[drafter]+ assert reserve >= measured+ assert reserve - max(_DFLASH_MEASURED_COMPUTE_MIB.values()) < 8diff --git a/studio/backend/utils/models/model_config.py b/studio/backend/utils/models/model_config.pyindex 948926e2302..3160264a7b2 100644--- a/studio/backend/utils/models/model_config.py+++ b/studio/backend/utils/models/model_config.py@@ -1907,7 +1907,7 @@ def _is_imatrix_path(path: str) -> bool:# Mirrors hub.utils.gguf._DRAFTER_KINDS. dflash/ holds real weights, so it is a drafter by prefix only.-_DRAFTER_KINDS = ("mtp", "dspark", "dflash", "eagle3")+_DRAFTER_KINDS = ("mtp", "dspark", "dflash", "eagle3", "lilicorr")_DRAFTER_DIR_KINDS = ("mtp", "dspark")@@ -1915,8 +1915,9 @@ def _is_mtp_drafter(path: str) -> bool:"""True for a separate-file drafter, a companion to the main model ratherthan a selectable quant: the repo-root ``mtp-*.gguf``, the ``MTP/`` subdircopies (Gemma 4), the ``dspark/`` drafters (DeepSeek V4 Flash), the- ``<model>-dspark-<quant>.gguf`` drafters (prism-ml Bonsai) or the- ``eagle3-*.gguf`` draft heads (ggml-org gpt-oss).+ ``<model>-dspark-<quant>.gguf`` drafters (prism-ml Bonsai), the+ ``eagle3-*.gguf`` draft heads (ggml-org gpt-oss) or the ``lilicorr-*.gguf``+ drafters (NVIDIA Nemotron 3.5).Mirrors hub.utils.gguf.is_mtp_drafter_path (utils cannot import hub). Must beexcluded everywhere mmproj is, or the drafter leaks into variant menus (a@@ -2781,7 +2782,7 @@ def _extract_quant_label(filename: str) -> str:stem = re.sub(r"-\d{3,}-of-\d{3,}", "", basename.rsplit(".", 1)[0])quant_re = (r"(UD-)?" # Optional UD- prefix (Ultra Discrete)- r"(MXFP[0-9]+(?:_[A-Z0-9]+)*" # MXFP variants: MXFP4, MXFP4_MOE+ r"((?:MX|NV)FP[0-9]+(?:_[A-Z0-9]+)*" # MXFP variants: MXFP4, MXFP4_MOEr"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?" # IQ variants: IQ4_XS, IQ4_NL, IQ1_Sr"|P?TQ[0-9]+_[0-9]+" # Ternary quant: TQ1_0, TQ2_0r"|Q[0-9]+_K_[A-Z]+" # K-quant: Q4_K_M, Q3_K_S@@ -2813,7 +2814,7 @@ def _extract_quant_label(filename: str) -> str:_BIG_ENDIAN_GGUF_FILENAME_RE = re.compile(r"(^|[-_])be(?:[._-]|$)", re.IGNORECASE)_GGUF_KNOWN_QUANT_RE = re.compile(r"(UD-)?"- r"(MXFP[0-9]+(?:_[A-Z0-9]+)*"+ r"((?:MX|NV)FP[0-9]+(?:_[A-Z0-9]+)*"r"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?"r"|P?TQ[0-9]+_[0-9]+"r"|Q[0-9]+_K_[A-Z]+"diff --git a/studio/frontend/src/features/model-picker/model-config/model-identity.ts b/studio/frontend/src/features/model-picker/model-config/model-identity.tsindex 2d8510d7543..02e250d4f17 100644--- a/studio/frontend/src/features/model-picker/model-config/model-identity.ts+++ b/studio/frontend/src/features/model-picker/model-config/model-identity.ts@@ -113,7 +113,7 @@ export function ggufVariantFromStorageKey(key: string): string | null {const BPW_SUFFIX = /-[0-9]+(?:\.[0-9]+)?bpw$/i;// One source for the anchored test and the scan below. Mirrors _GGUF_QUANT_RE in gguf.py.const QUANT_TOKEN_SOURCE =- "(UD-)?(MXFP[0-9]+(?:_[A-Z0-9]+)*|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?|P?TQ[0-9]+_[0-9]+|Q[0-9]+_K_[A-Z]+|P?Q[0-9]+_(?:[0-9]+(?:_G[0-9]+)?|G[0-9]+)|Q[0-9]+_K|BF16|F16|F32)";+ "(UD-)?((?:MX|NV)FP[0-9]+(?:_[A-Z0-9]+)*|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?|P?TQ[0-9]+_[0-9]+|Q[0-9]+_K_[A-Z]+|P?Q[0-9]+_(?:[0-9]+(?:_G[0-9]+)?|G[0-9]+)|Q[0-9]+_K|BF16|F16|F32)";const KNOWN_QUANT = new RegExp(`^${QUANT_TOKEN_SOURCE}$`, "i");const QUANT_TOKEN = new RegExp(QUANT_TOKEN_SOURCE, "gi");const MAX_QUANT_SUFFIX_LEN = 64;