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: cap Qwen3.8 NPU context at 8192 (#13525)

oobabooga7c18e2dbe037
diff --git a/studio/backend/core/inference/npu_backend.py b/studio/backend/core/inference/npu_backend.py
index 26d45ef107d..f98ddfbad25 100644
--- a/studio/backend/core/inference/npu_backend.py
+++ b/studio/backend/core/inference/npu_backend.py
@@ -49,6 +49,9 @@ _VALIDATED_MARKER = "npu_validated.json"
# Model modes Unsloth's chat cannot serve: embeddings and transcription have no chat endpoint,
# and a single-turn ("flash") model answers only the first message of a conversation.
_EXCLUDED_LABELS = frozenset({"embeddings", "transcription", "single-turn"})
+# Lemonade reports config.json max_position_embeddings, but FastFlowLM engines can fail above a lower
+# limit (FastFlowLM 1.0.7; recheck on pin bumps). https://fastflowlm.com/docs/models/qwen/#-model-card-qwen38-27b
+_FLM_CONTEXT_LIMITS = {"qwen3.8-mtp:27b": 8192}
_VALIDATE_PROBLEMS = (
("amd_device_found", "No AMD XDNA 2 NPU was found."),
@@ -222,6 +225,14 @@ def _positive_int(value: Any) -> Optional[int]:
return number if number > 0 else None
+def _max_context_length(checkpoint: str, reported: Any) -> Optional[int]:
+ reported = _positive_int(reported)
+ limit = _FLM_CONTEXT_LIMITS.get(checkpoint)
+ if limit is None:
+ return reported
+ return min(reported, limit) if reported else limit
+
+
class LemonadeNpuBackend:
def __init__(self, root: Optional[Path] = None) -> None:
self._root = Path(root) if root is not None else None
@@ -601,7 +612,9 @@ class LemonadeNpuBackend:
size_gb = float(size) if isinstance(size, (int, float)) else None,
downloaded = downloaded,
labels = labels,
- max_context_length = _positive_int(row.get("max_context_window")),
+ max_context_length = _max_context_length(
+ checkpoint, row.get("max_context_window")
+ ),
resume_percent = files.resume_percent() if files else None,
)
)
diff --git a/studio/backend/tests/fixtures/fake_lemond.py b/studio/backend/tests/fixtures/fake_lemond.py
index 8387fe14a1f..191d10ea9c0 100644
--- a/studio/backend/tests/fixtures/fake_lemond.py
+++ b/studio/backend/tests/fixtures/fake_lemond.py
@@ -39,6 +39,14 @@ CATALOG = [
"size": 4.5,
"max_context_window": 131072,
},
+ {
+ "id": "qwen3.8-mtp-27b-FLM",
+ "checkpoint": "qwen3.8-mtp:27b",
+ "labels": ["vision", "reasoning", "tool-calling", "chat"],
+ "size": 18.1,
+ # config.json's max_position_embeddings; FastFlowLM's engine stops at 8192.
+ "max_context_window": 262144,
+ },
{
"id": "embed-gemma-300m-FLM",
"checkpoint": "embed-gemma:300m",
diff --git a/studio/backend/tests/test_npu_backend.py b/studio/backend/tests/test_npu_backend.py
index 5490c8feca8..14c490111c3 100644
--- a/studio/backend/tests/test_npu_backend.py
+++ b/studio/backend/tests/test_npu_backend.py
@@ -149,7 +149,9 @@ def test_unsupported_npu_is_refused_before_any_download(tmp_path, monkeypatch):
def test_catalog_keeps_flm_chat_models_only(npu):
npu.enable()
ids = [model.id for model in npu.catalog()]
- assert ids == sorted(["gemma3-4b-FLM", "qwen3-0.6b-FLM", "qwen3-it-4b-FLM"])
+ assert ids == sorted(
+ ["gemma3-4b-FLM", "qwen3-0.6b-FLM", "qwen3-it-4b-FLM", "qwen3.8-mtp-27b-FLM"]
+ )
by_id = {model.id: model for model in npu.catalog()}
assert by_id["gemma3-4b-FLM"].vision and not by_id["gemma3-4b-FLM"].tools
assert by_id["qwen3-it-4b-FLM"].tools
@@ -309,6 +311,29 @@ def test_load_reports_the_context_lemond_started_with(npu, monkeypatch):
assert upstream.api_key
+def test_qwen38_is_held_to_its_engine_limit_not_its_checkpoint_metadata(npu, monkeypatch):
+ # Above 8192 FastFlowLM fails to load Qwen3.8, yet lemond reports ready and the first reply fails.
+ monkeypatch.setenv("FAKE_LEMOND_DOWNLOADED", '["qwen3.8-mtp-27b-FLM"]')
+ npu.enable()
+ by_id = {model.id: model for model in npu.catalog()}
+ assert by_id["qwen3.8-mtp-27b-FLM"].max_context_length == 8192
+ assert by_id["qwen3-0.6b-FLM"].max_context_length == 40960
+
+ npu.load("qwen3.8-mtp-27b-FLM", 16384)
+ load = [r["body"] for r in _requests(npu) if r["path"] == "/v1/load"][-1]
+ assert load["ctx_size"] == 8192
+ assert npu.loaded_context_length == 8192
+ assert npu.resident().requested_context_length == 16384
+
+
+ "reported, expected", [(262144, 8192), (4096, 4096), (None, 8192), (0, 8192)]
+)
+def test_a_runtime_limit_caps_whatever_lemond_reports(reported, expected):
+ assert nb._max_context_length("qwen3.8-mtp:27b", reported) == expected
+ assert nb._max_context_length("qwen3:0.6b", reported) == (reported or None)
+
+
def test_the_resident_reports_what_its_load_asked_for(npu):
npu.enable()
list(npu.download("qwen3-0.6b-FLM"))
diff --git a/studio/frontend/src/features/hub/hub-page.tsx b/studio/frontend/src/features/hub/hub-page.tsx
index 7a46403b000..a6843a870b8 100644
--- a/studio/frontend/src/features/hub/hub-page.tsx
+++ b/studio/frontend/src/features/hub/hub-page.tsx
@@ -1567,6 +1567,7 @@ export function ModelsPage() {
isLora: false,
isDownloaded: true,
isVision: model.supports_vision,
+ contextLength: model.max_context_length,
},
}),
[openRunSettingsInChat],