Skip to content
Closed
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2da0f28
Studio: add DFlash speculative decoding support
oobabooga Jun 29, 2026
579444b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2026
fe1a5d0
Merge branch 'main' into dflash-spec-decoding
oobabooga Jul 3, 2026
bb5b202
Fix the tensor-parallel probe test's stale spec-drop fallback anchor
oobabooga Jul 8, 2026
49be96a
Merge branch 'main' into dflash-spec-decoding
oobabooga Jul 8, 2026
132b61c
Retry extra-args DFlash without spec, skip HF DFlash reload dedup
oobabooga Jul 8, 2026
d2b20b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 8, 2026
e5ac360
Detect *-DFlash* drafter names, honor DFlash n-max reload and update …
oobabooga Jul 8, 2026
4327b9d
Extend the route n-max reload compare to draft-mtp, matching the back…
oobabooga Jul 8, 2026
3b46f72
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 8, 2026
bf9b6cc
Prefer the smaller quantized DFlash drafter over the bf16 converter o…
oobabooga Jul 8, 2026
ecb7c9e
Suppress DFlash for vision loads and give fork-drafter failures DFlas…
oobabooga Jul 8, 2026
9f4de1f
Scan the companion root in the MTP and DFlash reload dedup checks
oobabooga Jul 8, 2026
efd88ba
Auto-fetch the DFlash drafter for -hf loads and Hub download plans
oobabooga Jul 8, 2026
df0e1f5
Reserve VRAM for an auto-detected DFlash drafter in the fit budget
oobabooga Jul 8, 2026
5168587
Size the actually-emitted drafter in the reserve, not whichever sibli…
oobabooga Jul 8, 2026
44206e5
Fall through to MTP when a dflash sibling is present but the binary l…
oobabooga Jul 8, 2026
98f7b92
Skip DFlash -hf fetch for vision loads and count it in the training V…
oobabooga Jul 8, 2026
b52ecaa
Treat fp16 DFlash as full precision and run the HF reload dedup now t…
oobabooga Jul 8, 2026
06c6651
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 8, 2026
8a87c25
Reserve user extra-args DFlash and retry a failed DFlash drafter on r…
oobabooga Jul 8, 2026
1458495
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 8, 2026
1252f86
Filter quant-tag drafter pairing, skip DFlash in vision VRAM guard, r…
oobabooga Jul 8, 2026
7c349a0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 8, 2026
dc435b9
Retry after binary_no_dflash and mirror the DFlash fallback bypass in…
oobabooga Jul 8, 2026
1da199b
Pair -hf DFlash by model name, gate the VRAM reserve on binary suppor…
oobabooga Jul 8, 2026
6fd03a4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 8, 2026
4125e2a
Don't charge the MTP target-KV copy when DFlash wins Auto in the fit …
oobabooga Jul 8, 2026
0913cfd
Merge remote-tracking branch 'origin/main' into dflash-spec-decoding
oobabooga Jul 17, 2026
3525258
Trim redundant tail on the native DFlash drafter drop comment
oobabooga Jul 17, 2026
98b8933
Fix DFlash review follow-ups
oobabooga Jul 17, 2026
fe84789
Trim DFlash implementation comments
oobabooga Jul 17, 2026
684eeee
Fix DFlash remote companion handling
oobabooga Jul 17, 2026
46c1a5e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2026
88baef6
Align DFlash retries and VRAM guards
oobabooga Jul 17, 2026
5480517
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2026
1e49766
Consolidate DFlash regression tests
oobabooga Jul 17, 2026
fec2210
Align DFlash retry and validation state
oobabooga Jul 17, 2026
6a2d9aa
Converge DFlash reload and sizing guards
oobabooga Jul 17, 2026
f8870c1
Handle manual DFlash sizing and quant names
oobabooga Jul 17, 2026
bb853e2
Converge DFlash fallback and sizing invariants
oobabooga Jul 17, 2026
0eaa2fb
Align DFlash companion handling with MTP
oobabooga Jul 17, 2026
8329bfa
Merge branch 'main' into dflash-spec-decoding
oobabooga Jul 17, 2026
731dae7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2026
11cfe00
Converge DFlash binary fallback
oobabooga Jul 17, 2026
8622281
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2026
73ce91a
Fix DFlash precision selection
oobabooga Jul 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
450 changes: 375 additions & 75 deletions studio/backend/core/inference/llama_cpp.py

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions studio/backend/hub/utils/gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ def is_mmproj_filename(filename: str) -> bool:
return "mmproj" in filename.lower()


# Match either documented DFlash naming form without matching embedded words.
_DFLASH_DRAFTER_RE = re.compile(r"(?:^|[-_.])dflash(?:[-_.]|$)", re.IGNORECASE)


def is_mtp_drafter_path(path: str) -> bool:
"""True for a separate-file MTP drafter (speculative head), a companion to
the main model rather than a selectable quant.

Covers the repo-root ``mtp-*.gguf`` (the Q8_0 copy unsloth ships for
llama.cpp ``-hf`` auto-discovery) and the ``MTP/`` subdir copies (Gemma 4).
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.

CANONICAL COPY. Layering keeps two mirrors that 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).
"""
"""Return whether a GGUF is an MTP or DFlash companion, not a main model."""
p = path.lower()
if not p.endswith(".gguf"):
return False
name = p.rsplit("/", 1)[-1]
return name.startswith("mtp-") or "/mtp/" in f"/{p}"
return name.startswith("mtp-") or "/mtp/" in f"/{p}" or bool(_DFLASH_DRAFTER_RE.search(name))
Comment thread
oobabooga marked this conversation as resolved.
Resolved
Comment thread
oobabooga marked this conversation as resolved.
Resolved


def is_dflash_drafter_path(path: str) -> bool:
"""True for a DFlash drafter specifically (``dflash`` as a delimited token),
excluding the MTP drafters is_mtp_drafter_path also covers."""
p = path.lower()
if not p.endswith(".gguf"):
return False
return bool(_DFLASH_DRAFTER_RE.search(p.rsplit("/", 1)[-1]))


def is_gguf_filename(filename: str) -> bool:
Expand Down
43 changes: 42 additions & 1 deletion studio/backend/hub/utils/gguf_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@
from hub.utils.gguf import (
extract_quant_label,
is_big_endian_gguf_path,
is_dflash_drafter_path,
is_gguf_filename,
is_mmproj_filename,
is_mtp_drafter_path,
)
from utils.models.model_config import _dflash_pairs_weight

# Prefer quantized DFlash builds over these converter outputs.
_FULL_PRECISION_GGUF_TOKENS = ("bf16", "f16", "f32", "fp16")


def _is_full_precision_gguf(path: str) -> bool:
name = path.rsplit("/", 1)[-1].lower()
return any(token in name for token in _FULL_PRECISION_GGUF_TOKENS)


@dataclass(frozen = True)
Expand Down Expand Up @@ -119,6 +129,25 @@ def preferred_mtp_sibling(siblings: Sequence) -> Optional[object]:
return candidates[0] if candidates else None


def preferred_dflash_sibling(
siblings: Sequence, weight_name: Optional[str] = None
) -> Optional[object]:
"""Pick a DFlash sibling, preferring quantized over full-precision builds."""
candidates = [
s
for s in siblings
if (name := _gguf_rfilename(s))
and is_dflash_drafter_path(name.rsplit("/", 1)[-1])
and _dflash_pairs_weight(name.rsplit("/", 1)[-1], weight_name)
]
Comment thread
oobabooga marked this conversation as resolved.
Resolved
if not candidates:
return None
return sorted(
candidates,
key = lambda s: (_is_full_precision_gguf(getattr(s, "rfilename")), getattr(s, "rfilename")),
)[0]


def build_gguf_variant_plans(siblings: Sequence) -> dict[str, GgufVariantPlan]:
main: dict[str, list] = {}
all_mmproj = mmproj_siblings(siblings)
Expand Down Expand Up @@ -152,12 +181,24 @@ def build_gguf_variant_plans(siblings: Sequence) -> dict[str, GgufVariantPlan]:

plans: dict[str, GgufVariantPlan] = {}
for quant, target_main_siblings in main.items():
target_weight = _gguf_rfilename(target_main_siblings[0])
Comment thread
oobabooga marked this conversation as resolved.
Resolved
target_weight_name = target_weight.rsplit("/", 1)[-1] if target_weight else None
dflash_sibling = (
None if all_mmproj else preferred_dflash_sibling(siblings, target_weight_name)
)
dflash_expected = (
expected_file_from_sibling(dflash_sibling) if dflash_sibling is not None else None
)
main_expected = tuple(
file
for sibling in target_main_siblings
if (file := expected_file_from_sibling(sibling)) is not None
)
expected_files = (*main_expected, *companions_expected)
expected_files = (
*main_expected,
*companions_expected,
*((dflash_expected,) if dflash_expected is not None else ()),
)
plans[quant] = plan_from_expected_files(
quant,
expected_files,
Expand Down
40 changes: 24 additions & 16 deletions studio/backend/models/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def normalize_blank_chat_template_override(cls, value: Optional[str]) -> Optiona
None,
description = (
"Speculative decoding mode for GGUF models. Canonical values: "
"'auto' (platform-aware: MTP on MTP GGUFs, ngram-mod fallback "
"for sub-3B), 'mtp' (force draft-mtp only on both GPU and CPU), "
"'auto' (platform-aware: DFlash when a matching drafter is present, "
"otherwise MTP on MTP GGUFs or ngram-mod for sub-3B), "
"'mtp' (force draft-mtp only on both GPU and CPU), "
"'ngram' (force ngram-mod only), 'mtp+ngram' (force "
"ngram-mod+draft-mtp chain on both platforms), 'off' (disabled). "
"Legacy values 'default' (-> auto), 'draft-mtp' (-> mtp), "
Expand All @@ -84,11 +85,9 @@ def normalize_blank_chat_template_override(cls, value: Optional[str]) -> Optiona
ge = 1,
le = 16,
description = (
"Max draft tokens per step for MTP speculative decoding "
"(--spec-draft-n-max). Defaults to 2 on GPU and 3 on CPU/Mac "
"when unset (upstream-bench sweet spot for dense Qwen3.6 MTP "
"quants). Only applied when speculative_type resolves to "
"'mtp' or 'mtp+ngram'."
"Max draft tokens per step for model-draft speculative decoding "
"(--spec-draft-n-max). Defaults to 4 for auto-detected DFlash, "
"or 2 on GPU and 3 on CPU/Mac for MTP."
),
)
tensor_parallel: bool = Field(
Expand Down Expand Up @@ -133,6 +132,12 @@ class ValidateModelRequest(BaseModel):
max_seq_length: int = Field(0, ge = 0, le = 1048576)
load_in_4bit: bool = Field(True)
gpu_ids: Optional[List[int]] = Field(None)
speculative_type: Optional[str] = Field(
None, description = "Intended GGUF speculative mode for VRAM sizing"
)
llama_extra_args: Optional[List[str]] = Field(
None, description = "Intended llama-server arguments for VRAM sizing"
)
include_context_length: bool = Field(
False,
description = "Also read the native context length from the local GGUF header. "
Expand Down Expand Up @@ -325,7 +330,7 @@ class LoadResponse(BaseModel):
spec_draft_n_max: Optional[int] = Field(
None,
description = (
"Active --spec-draft-n-max for MTP speculative decoding, or "
"Active --spec-draft-n-max for model-draft speculative decoding, or "
"None when the platform default is in effect."
),
)
Expand Down Expand Up @@ -453,7 +458,7 @@ class InferenceStatusResponse(BaseModel):
spec_draft_n_max: Optional[int] = Field(
None,
description = (
"Active --spec-draft-n-max for MTP speculative decoding, or "
"Active --spec-draft-n-max for model-draft speculative decoding, or "
"None when the platform default is in effect."
),
)
Expand All @@ -471,17 +476,20 @@ class InferenceStatusResponse(BaseModel):
spec_fallback_reason: Optional[str] = Field(
None,
description = (
"Why MTP was disabled on the loaded model despite being requested "
"(auto on an MTP model, or forced mtp / mtp+ngram). "
"'binary_no_mtp' / 'binary_outdated' -> a newer prebuilt would "
"re-enable it (show the update affordance); 'runtime_error' -> the "
"current build could not run it; 'drafter_not_found' -> the model's "
"separate MTP drafter could not be resolved; 'mla_mtp_disabled' -> "
"Why model-draft speculative decoding was disabled on the loaded model. "
"'binary_no_mtp' / 'binary_no_dflash' / 'binary_outdated' -> a newer "
"prebuilt would re-enable it (show the update affordance); "
"'runtime_error' -> the "
"current build could not run it; 'dflash_drafter_incompatible' -> the "
"DFlash drafter is a fork build the upstream binary cannot load "
"(replace the drafter, not the binary); 'dflash_runtime_error' -> "
"DFlash could not start on this build; 'drafter_not_found' -> the "
"model's separate MTP drafter could not be resolved; 'mla_mtp_disabled' -> "
"an Auto-mode policy downgrade: the model is MLA (GLM-5.2 et al.) "
"whose llama.cpp MTP path runs slower than no speculation, so Auto "
"used ngram-mod or spec-off instead -- updating won't help; choose "
"MTP in Settings (or set UNSLOTH_MLA_MTP_ENABLED=1) to force it. "
"None when MTP engaged or was not requested."
"None when speculative decoding engaged or no fallback occurred."
),
)
llama_cpp_prebuilt_stale: bool = Field(
Expand Down
Loading
Loading