Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ Run `python -m pytest -q tests/test_scheduler.py tests/test_scheduler_boundary_c
Run `python -m pytest -q tests/test_cluster_pairing_session.py tests/test_cluster_pairing.py tests/test_cluster_ui_integration.py tests/ui/test_cluster_v2_wizard.py` to check joining, cancellation, and approval. Session tests recreate a manager with the same base path to verify that the original code and cancellation proof survive a restart. They also cover offline cancellation, switching peers while cleanup is pending, rejected requests versus lost responses, and storage failures. Wizard tests check that delayed responses cannot restore a cancelled join and that pending cleanup leaves new pairing controls available.

For a two-Mac smoke test, start isolated servers with separate base paths. Request a join, restart only the joining server, then cancel and retry; the coordinator must remove the original pending request. Repeat with the coordinator offline: cancellation must return `state: idle` with `cleanup_pending: true`, and joining a different reachable Mac must work. Restore the coordinator and poll the join endpoint to verify cleanup. Keep existing approval/cancel race and token-ownership tests in the run; never relax the coordinator's token check to make a stale request disappear.

# DeepSeek V4.1 offline tests

Run `python -m pytest -q tests/test_deepseek_v41.py` for the text/vision port. Synthetic weights and small recorded official outputs cover prefill/decode, DSpark, Engram and vision numerics without a checkpoint download or vendored reference implementation. See `tests/fixtures/deepseek_v41_expected.md` for provenance and reference corrections. PyTorch is optional for the independent FP8/FP4 arithmetic checks. Other cases cover BatchGenerator admission, cache restoration, DSML and VLM engine execution.

FP8 activation boundary and layout checks: `python -m pytest tests/test_deepseek_v41_activation.py -q`. These compare fused FP8 and weighted SwiGLU kernels against reference arithmetic across rounding ties, scale transitions, clipping, intermediate casts and floating-point dtypes.

MoE activation reuse and per-expert reference checks: `python -m pytest tests/test_deepseek_v41_moe.py -q`. These cover sorted prefill, decode, independent routed/shared activation policies, and repeated outputs with small quantized weights.

DeepSeek V4.1 Metal arithmetic and sparse-addressing checks: `python -m pytest tests/test_deepseek_v41_kernels.py -q` (no checkpoint required).

Packed attention rounding: `python -m pytest tests/test_deepseek_v41_attention_rounding.py -q`. An independent MLX oracle checks 64-key online maxima, FP32 denominators, BF16 PV probabilities, masking, sink placement, and growing or strided KV across the threadgroup capacity boundary. This does not execute the official CUDA kernels.

Engram storage and prefetch lifecycle: `python -m pytest tests/test_deepseek_v41_offload.py -q`. Modal state, forced-toggle behavior, and save payload: `node --test tests/deepseek_v41_offload_ui.test.cjs`. Both use synthetic fixtures and require no checkpoint download.
24 changes: 21 additions & 3 deletions omlx/adapter/output_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ class DeepSeekV4OutputParserSession:

def __init__(self, tokenizer: Any, model_path: str | None = None):
self._tokenizer = tokenizer
self._tool_start = (
getattr(tokenizer, "tool_call_start", None) or _DEEPSEEK_V4_TOOL_CALL_START
)
self._tool_end = (
getattr(tokenizer, "tool_call_end", None) or _DEEPSEEK_V4_TOOL_CALL_END
)
self._raw_text = ""
self._stopped = False
self._detokenizer = create_streaming_detokenizer(tokenizer, model_path)
Expand Down Expand Up @@ -545,13 +551,13 @@ def _finish_filtered_text(self, tool_filter: Any) -> str:
return tool_filter.finish()

def _trim_at_first_tool_block_end(self, text: str) -> tuple[str, bool]:
start_idx = text.find(_DEEPSEEK_V4_TOOL_CALL_START)
start_idx = text.find(self._tool_start)
if start_idx < 0:
return text, False
end_idx = text.find(_DEEPSEEK_V4_TOOL_CALL_END, start_idx)
end_idx = text.find(self._tool_end, start_idx)
if end_idx < 0:
return text, False
cutoff = end_idx + len(_DEEPSEEK_V4_TOOL_CALL_END)
cutoff = end_idx + len(self._tool_end)
return text[:cutoff], True

def process_token(self, token_id: int) -> OutputParserTokenResult:
Expand Down Expand Up @@ -1396,6 +1402,18 @@ def detect_output_parser(
),
)

if getattr(tokenizer, "tool_call_start", None) == "<|DSML| calls>":
from ..patches.deepseek_v41.output_parser import DeepSeekV41OutputParserSession

return OutputParserFactory(
kind="deepseek_v41",
create_session=lambda session_tokenizer: DeepSeekV41OutputParserSession(
session_tokenizer, model_path=session_model_path
),
stop_token_ids=set(),
protocol_marker_texts=("<|DSML| calls>", "</|DSML| calls>"),
)

if _is_deepseek_v4_model(model_name, tokenizer, model_config):
return OutputParserFactory(
kind="deepseek_v4",
Expand Down
3 changes: 3 additions & 0 deletions omlx/admin/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@
"modal.model_settings.qwen4_ple_ssd_offload": "SSD N-gram Offload (Qwen4 only)",
"modal.model_settings.qwen4_ple_ssd_offload_hint": "Keep the large PLE N-gram table on SSD and read only the required rows. This saves memory but can slow prefill after context changes.",
"modal.model_settings.qwen4_ple_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.deepseek_v41_engram_ssd_offload": "SSD N-gram Offload (DeepSeek V4.1)",
"modal.model_settings.deepseek_v41_engram_ssd_offload_hint": "Keep Engram tables on SSD and prefetch required rows. Saves memory; speed depends on SSD reads. Changing this setting reloads the model.",
"modal.model_settings.deepseek_v41_engram_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.thinking_budget": "Thinking Budget",
"modal.model_settings.thinking_budget_hint": "Limit thinking tokens for reasoning models. Forces end of thinking when exceeded.",
"modal.model_settings.thinking_budget_placeholder": "e.g. 4096",
Expand Down
3 changes: 3 additions & 0 deletions omlx/admin/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@
"modal.model_settings.qwen4_ple_ssd_offload": "SSD N-gram Offload (Qwen4 only)",
"modal.model_settings.qwen4_ple_ssd_offload_hint": "Keep the large PLE N-gram table on SSD and read only the required rows. This saves memory but can slow prefill after context changes.",
"modal.model_settings.qwen4_ple_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.deepseek_v41_engram_ssd_offload": "SSD N-gram Offload (DeepSeek V4.1)",
"modal.model_settings.deepseek_v41_engram_ssd_offload_hint": "Keep Engram tables on SSD and prefetch required rows. Saves memory; speed depends on SSD reads. Changing this setting reloads the model.",
"modal.model_settings.deepseek_v41_engram_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.thinking_budget": "Presupuesto de Pensamiento",
"modal.model_settings.thinking_budget_hint": "Limitar tokens de pensamiento para modelos de razonamiento. Fuerza el fin del pensamiento al excederse.",
"modal.model_settings.thinking_budget_placeholder": "ej. 4096",
Expand Down
3 changes: 3 additions & 0 deletions omlx/admin/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@
"modal.model_settings.qwen4_ple_ssd_offload": "SSD N-gram Offload (Qwen4 only)",
"modal.model_settings.qwen4_ple_ssd_offload_hint": "Keep the large PLE N-gram table on SSD and read only the required rows. This saves memory but can slow prefill after context changes.",
"modal.model_settings.qwen4_ple_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.deepseek_v41_engram_ssd_offload": "SSD N-gram Offload (DeepSeek V4.1)",
"modal.model_settings.deepseek_v41_engram_ssd_offload_hint": "Keep Engram tables on SSD and prefetch required rows. Saves memory; speed depends on SSD reads. Changing this setting reloads the model.",
"modal.model_settings.deepseek_v41_engram_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.thinking_budget": "Budget de réflexion",
"modal.model_settings.thinking_budget_hint": "Limitez les tokens de réflexion pour les modèles de raisonnement. Force la fin de la réflexion lorsque dépassé.",
"modal.model_settings.thinking_budget_placeholder": "par ex. 4096",
Expand Down
3 changes: 3 additions & 0 deletions omlx/admin/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@
"modal.model_settings.qwen4_ple_ssd_offload": "SSD N-gram Offload (Qwen4 only)",
"modal.model_settings.qwen4_ple_ssd_offload_hint": "Keep the large PLE N-gram table on SSD and read only the required rows. This saves memory but can slow prefill after context changes.",
"modal.model_settings.qwen4_ple_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.deepseek_v41_engram_ssd_offload": "SSD N-gram Offload (DeepSeek V4.1)",
"modal.model_settings.deepseek_v41_engram_ssd_offload_hint": "Keep Engram tables on SSD and prefetch required rows. Saves memory; speed depends on SSD reads. Changing this setting reloads the model.",
"modal.model_settings.deepseek_v41_engram_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.thinking_budget": "思考トークン制限",
"modal.model_settings.thinking_budget_hint": "推論モデルの思考トークン数を制限します。超過時に思考を強制終了します。",
"modal.model_settings.thinking_budget_placeholder": "例: 4096",
Expand Down
3 changes: 3 additions & 0 deletions omlx/admin/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@
"modal.model_settings.qwen4_ple_ssd_offload": "SSD N-gram 오프로딩 (Qwen4 전용)",
"modal.model_settings.qwen4_ple_ssd_offload_hint": "큰 PLE N-gram 테이블을 SSD에 두고 필요한 행만 읽습니다. 메모리를 절약하지만 컨텍스트가 바뀐 뒤 prefill이 느려질 수 있습니다.",
"modal.model_settings.qwen4_ple_ssd_offload_forced": "resident 로드가 설정된 모델 메모리 한도를 초과하므로 이 옵션이 필요합니다.",
"modal.model_settings.deepseek_v41_engram_ssd_offload": "SSD N-gram 오프로딩 (DeepSeek V4.1)",
"modal.model_settings.deepseek_v41_engram_ssd_offload_hint": "Engram 테이블을 SSD에 두고 필요한 행을 미리 읽습니다. 메모리를 절약하며 속도는 SSD 읽기 성능에 따라 달라집니다. 변경 시 모델을 다시 로드합니다.",
"modal.model_settings.deepseek_v41_engram_ssd_offload_forced": "메모리 상주 시 설정된 모델 메모리 한도를 초과하므로 필수로 활성화됩니다.",
"modal.model_settings.thinking_budget": "Thinking 토큰 제한",
"modal.model_settings.thinking_budget_hint": "추론 모델의 thinking 토큰 수를 제한합니다. 초과 시 thinking을 강제 종료합니다.",
"modal.model_settings.thinking_budget_placeholder": "예: 4096",
Expand Down
3 changes: 3 additions & 0 deletions omlx/admin/i18n/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@
"modal.model_settings.qwen4_ple_ssd_offload": "SSD N-gram Offload (Qwen4 only)",
"modal.model_settings.qwen4_ple_ssd_offload_hint": "Keep the large PLE N-gram table on SSD and read only the required rows. This saves memory but can slow prefill after context changes.",
"modal.model_settings.qwen4_ple_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.deepseek_v41_engram_ssd_offload": "SSD N-gram Offload (DeepSeek V4.1)",
"modal.model_settings.deepseek_v41_engram_ssd_offload_hint": "Keep Engram tables on SSD and prefetch required rows. Saves memory; speed depends on SSD reads. Changing this setting reloads the model.",
"modal.model_settings.deepseek_v41_engram_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.thinking_budget": "Orçamento de Raciocínio",
"modal.model_settings.thinking_budget_hint": "Limitar tokens de raciocínio para modelos de reasoning. Força o fim do raciocínio quando excedido.",
"modal.model_settings.thinking_budget_placeholder": "ex: 4096",
Expand Down
3 changes: 3 additions & 0 deletions omlx/admin/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@
"modal.model_settings.qwen4_ple_ssd_offload": "SSD N-gram Offload (Qwen4 only)",
"modal.model_settings.qwen4_ple_ssd_offload_hint": "Keep the large PLE N-gram table on SSD and read only the required rows. This saves memory but can slow prefill after context changes.",
"modal.model_settings.qwen4_ple_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.deepseek_v41_engram_ssd_offload": "SSD N-gram Offload (DeepSeek V4.1)",
"modal.model_settings.deepseek_v41_engram_ssd_offload_hint": "Keep Engram tables on SSD and prefetch required rows. Saves memory; speed depends on SSD reads. Changing this setting reloads the model.",
"modal.model_settings.deepseek_v41_engram_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.thinking_budget": "Бюджет мышления",
"modal.model_settings.thinking_budget_hint": "Ограничьте число токенов мышления для моделей рассуждения. Принудительно завершает мышление при превышении лимита.",
"modal.model_settings.thinking_budget_placeholder": "например, 4096",
Expand Down
3 changes: 3 additions & 0 deletions omlx/admin/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@
"modal.model_settings.qwen4_ple_ssd_offload": "SSD N-gram Offload (Qwen4 only)",
"modal.model_settings.qwen4_ple_ssd_offload_hint": "Keep the large PLE N-gram table on SSD and read only the required rows. This saves memory but can slow prefill after context changes.",
"modal.model_settings.qwen4_ple_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.deepseek_v41_engram_ssd_offload": "SSD N-gram Offload (DeepSeek V4.1)",
"modal.model_settings.deepseek_v41_engram_ssd_offload_hint": "Keep Engram tables on SSD and prefetch required rows. Saves memory; speed depends on SSD reads. Changing this setting reloads the model.",
"modal.model_settings.deepseek_v41_engram_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.thinking_budget": "思考 Token 限制",
"modal.model_settings.thinking_budget_hint": "限制推理模型的思考 Token 數量,超出時強制結束思考",
"modal.model_settings.thinking_budget_placeholder": "例如 4096",
Expand Down
3 changes: 3 additions & 0 deletions omlx/admin/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@
"modal.model_settings.qwen4_ple_ssd_offload": "SSD N-gram Offload (Qwen4 only)",
"modal.model_settings.qwen4_ple_ssd_offload_hint": "Keep the large PLE N-gram table on SSD and read only the required rows. This saves memory but can slow prefill after context changes.",
"modal.model_settings.qwen4_ple_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.deepseek_v41_engram_ssd_offload": "SSD N-gram Offload (DeepSeek V4.1)",
"modal.model_settings.deepseek_v41_engram_ssd_offload_hint": "Keep Engram tables on SSD and prefetch required rows. Saves memory; speed depends on SSD reads. Changing this setting reloads the model.",
"modal.model_settings.deepseek_v41_engram_ssd_offload_forced": "Required because resident loading exceeds the configured model-memory limit.",
"modal.model_settings.thinking_budget": "思考 Token 限制",
"modal.model_settings.thinking_budget_hint": "限制推理模型的思考 Token 数量,超出时强制结束思考",
"modal.model_settings.thinking_budget_placeholder": "例如 4096",
Expand Down
10 changes: 9 additions & 1 deletion omlx/admin/oq_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def _scan() -> tuple[list[dict], list[dict]]:
if not mt:
continue
tc = config.get("text_config", {})
is_v41 = config.get("model_type") == "deepseek_v41"
has_mtp = _has_mtp_heads(
config
) and _checkpoint_has_mtp_weights(path)
Expand All @@ -251,14 +252,16 @@ def _scan() -> tuple[list[dict], list[dict]]:
"size_formatted": _format_size(size),
"model_type": config.get("model_type", "")
or tc.get("model_type", ""),
"is_quantized": "quantization" in config,
"is_quantized": "quantization" in config
or "omlx_deepseek_v41" in config,
# Treat vision_config / vit_config / mm_vision_tower as VLM
# evidence (Molmo / Molmo2 use vit_config; FastVLM uses
# mm_vision_tower). Same predicate as model_discovery.
"is_vlm": _has_vision_subconfig(config),
"has_mtp_heads": has_mtp,
"hidden_size": tc.get("hidden_size")
or config.get("hidden_size")
or (tc.get("dim") if is_v41 else 0)
or 0,
}
all_models.append(info)
Expand All @@ -270,6 +273,11 @@ def _scan() -> tuple[list[dict], list[dict]]:
info_full["num_experts"] = config.get(
"num_local_experts", 0
)
if is_v41:
info_full["num_layers"] = (
info_full["num_layers"] or tc.get("n_layers", 0)
)
info_full["num_experts"] = tc.get("n_routed_experts", 0)
info_full["memory_streaming"] = estimate_memory(size)
source_models.append(info_full)
except Exception:
Expand Down
Loading