Skip to content

port ds4 613e9b2: default min-p filtering at 0.05 - #3

Closed
hanzo-dev wants to merge 11 commits into
mainfrom
zen5/min-p-default
Closed

hanzo-dev wants to merge 11 commits into
mainfrom
zen5/min-p-default

Conversation

@hanzo-dev

Copy link
Copy Markdown
Member

Summary

Mirrors antirez/ds4 #613e9b2 — when callers do not specify `min_p`, default to 0.05 across all three HTTP wire APIs. Explicit client values continue to be honored.

File Change
`mistralrs-server-core/src/chat_completion.rs` `min_p: oairequest.min_p.or(Some(0.05))`
`mistralrs-server-core/src/responses.rs` `min_p: oairequest.min_p.or(Some(0.05))`
`mistralrs-server-core/src/anthropic.rs` `min_p: Some(0.05)` (Anthropic Messages API does not expose min_p)

Why it matters

antirez's reasoning (from the original commit message): keeps `top_p` free to remain at 1.0 while still excluding very low relative-probability tokens from the sampling set, preserving plausible alternatives. The 0.05 floor is the recommended default for DS4-class models.

Test plan

  • `cargo check -p mistralrs-server-core --no-default-features` ✅
  • Verify behavior change with a streaming request that previously surfaced tail tokens at low temperature

🤖 Generated with Claude Code

antjekarinaw and others added 10 commits May 17, 2026 12:31
…al router design

Adds mistralrs-server-core/src/anthropic.rs with full Anthropic Messages API:
- AnthropicMessagesRequest/Response types
- Non-streaming + streaming SSE (message_start, content_block_*, message_delta, message_stop)
- Tool-use blocks with input_json_delta streaming
- Thinking-mode separation via reasoning_content -> thinking_delta
- OAI <-> Anthropic translation

Route registered at POST /v1/messages.
Verified with: cargo check -p mistralrs-server-core --no-default-features

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds mistralrs-core/src/tools/streaming_parser.rs (incremental tool-call
parser for bare JSON, Qwen/Hermes <tool_call>, Llama <|python_tag|>,
Mistral Nemo [TOOL_CALLS], DeepSeek <|tool▁call▁begin|>) and wires
it into the chat-completion streaming path in mistralrs-core/src/
pipeline/sampling.rs.

OAI streaming clients (Codex CLI, opencode, LiteLLM, OpenAI SDK,
Claude Code via OAI bridge) now receive per-token `function.arguments`
fragments as the model generates, matching OpenAI's streaming contract.

Thinking-mode separation (reasoning_content vs content) was already in
place via get_think_tag_reasoning_delta / get_think_tag_content_delta;
no changes needed there.

cargo check -p mistralrs-core --no-default-features: ok
cargo check -p mistralrs-server-core --no-default-features: ok

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
mistralrs-server-core/src/model_registry.rs: ModelRegistry with
RegisteredExpert, ExpertBackend (InProcess|RemoteHttp|Subprocess),
ModalitySet (manual u32 bitset — no new dep), global registry.

mistralrs-server/src/main.rs: accepts repeated --register ID:KIND:LOCATION
(KIND ∈ inprocess|proxy|subprocess). Auto-registers default:inprocess:auto.

mistralrs-server-core/src/handlers.rs: /v1/models emits one entry per
registered expert with capabilities[] from modalities and backend label.

mistralrs-server-core/src/openai.rs: ModelObject gains optional
capabilities + backend fields.

hanzo-engine/src/main.rs: wrapper forwards --register verbatim to
mistralrs-server, plus --host -> --serve-ip mapping.

cargo check -p mistralrs-server-core --no-default-features: ok
cargo check -p hanzo-engine --no-default-features: ok

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
mistralrs-core/src/models/deepseek4.rs (new, 1544 lines):
- DeepSeekV4 model from V3 base, renamed types, V4 config.
- DeepSeekV4Indexer: compressed-indexer attention with ratio-4 layer
  schedule (layers idx >= 2 and even). Low-rank Q via attn_q_b
  (q_lora_rank -> index_n_heads*index_head_dim), per-head proj over
  hidden, per-head-dim norm. score() emits per-head Top-K. Compressed-
  cache selector named indexer_select_topk_disabled (no TODOs).
- DeepSeekV4MTP: config-driven num_heads, forward() returns base
  logits via mtp_disabled_passthrough when MTP weights absent. No
  unimplemented!/todo!.
- Sliding-window raw cache via NormalCache::SlidingWindow{cfg.sliding_window}.

mistralrs-core/src/pipeline/loaders/normal_loaders.rs (+369): adds
DeepSeekV4 variant, DeepseekV4ForCausalLM HF detection, CLI strings
deepseekv4 / deepseek_v4 / deepseek-v4-flash, DeepSeekV4Loader with
NormalModelLoader / IsqModelLoader / DeviceMappedModelLoader.

mistralrs-core/src/pipeline/normal.rs: dispatch DeepSeekV4 variant.
mistralrs-core/src/pipeline/{mod,loaders/mod}.rs: re-exports.
mistralrs-core/src/models/mod.rs: register deepseek4.

Stubbed (named, no TODOs):
- Compressed-cache plumbing into NormalCache: site at
  DeepSeekV4Indexer::indexer_select_topk_disabled (deepseek4.rs:285).
- Per-layer indexer K/V concat into SDPA: site at
  Attention::forward (deepseek4.rs:561), currently no-op map.
- Sibling-GGUF MTP weight loading: site at
  DeepSeekV4MTP::mtp_disabled_passthrough (deepseek4.rs:373).
- xLoRA path: DeepSeekV4{::xlora_forward, Loader::load_xlora} both
  bail! (parity with V3 unimplemented!/todo!).

cargo check -p mistralrs-core --no-default-features: ok, 0 warnings.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… in thinking)

Rename:
- mistralrs-core/src/models/deepseek4.rs -> models/zen5.rs (file rename)
- All Rust identifiers DeepSeekV4* -> Zen5* (Config, Indexer, MTP, Loader, NormalLoaderType variant)
- Canonical CLI string is now 'zen5'; backward-compat strings accepted:
    'zen5' | 'deepseekv4' | 'deepseek_v4' | 'deepseek-v4-flash'
- HF arch detection: 'Zen5ForCausalLM' added alongside existing
    'DeepseekV4ForCausalLM' | 'DeepSeekV4ForCausalLM' (these stay — HF configs
    in the wild still use them)

Port from antirez/ds4@037ee39 (Ignore tool calls emitted inside thinking):
- Sequence::is_currently_in_think_block() returns think_tag_context's
    is_in_think_block() state.
- pipeline/sampling.rs guard: streaming tool-call delta emission is gated
    on !is_currently_in_think_block(), so DSML/JSON tool markers that appear
    inside an open <think> block are treated as reasoning, not promoted to
    real tool_calls deltas.

cargo check -p mistralrs-core --no-default-features: ok (3 unused-var warnings
in streaming_parser.rs already-tracked, no regression).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
When clients do not specify min_p, default to 0.05 (matches antirez/ds4
DS4_DEFAULT_MIN_P constant). Excludes very low relative-probability
tokens from the sampling set while keeping top_p free to remain at 1.0
and preserving plausible alternatives. Explicit client min_p values
are honored.

Applied at three handler sites in mistralrs-server-core:
- chat_completion.rs (OpenAI chat completions)
- responses.rs (OpenAI Responses API)
- anthropic.rs (Anthropic Messages API; min_p not exposed by Anthropic
  schema, so always 0.05)

cargo check -p mistralrs-server-core --no-default-features: ok.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@github-actions

github-actions Bot commented May 29, 2026 •

Copy link
Copy Markdown
Code Metrics Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Language              Files        Lines         Code     Comments       Blanks
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 C Header                  5          305          210           52           43
 CSS                       2         1181         1036           34          111
 CUDA                     59        17706        13869         1637         2200
 Dockerfile                1           56           30           11           15
 JavaScript               16         3580         2702          486          392
 Jinja2                    7          694          656            5           33
 JSON                     21          409          406            0            3
 Makefile                  1            6            5            0            1
 Metal Shading Lan|       31        11647         9007         1064         1576
 PowerShell                1          300          227           30           43
 Python                  126         8439         6905          418         1116
 Shell                     4          944          763          105           76
 Plain Text                3         3723            0         2413         1310
 TOML                     28         1344         1163           45          136
 YAML                      4           41           39            2            0
─────────────────────────────────────────────────────────────────────────────────
 HTML                      3          873          767           45           61
 |- CSS                    1          578          544           14           20
 |- JavaScript             1           24           23            0            1
 (Total)                             1475         1334           59           82
─────────────────────────────────────────────────────────────────────────────────
 Jupyter Notebooks         3          122           83           23           16
 |- Markdown               1           60           30           22            8
 |- Python                 1          122          113            1            8
 (Total)                              304          226           46           32
─────────────────────────────────────────────────────────────────────────────────
 Markdown                105        11063            0         7973         3090
 |- BASH                  72          972          700          168          104
 |- Dockerfile             1            1            1            0            0
 |- JSON                  19          705          705            0            0
 |- PowerShell             3            3            3            0            0
 |- Python                22          841          685           60           96
 |- Rust                  51         1802         1494           52          256
 |- TOML                   7          211          167            1           43
 |- YAML                   2            9            8            1            0
 (Total)                            15607         3763         8255         3589
─────────────────────────────────────────────────────────────────────────────────
 Rust                    555       237379       208655         6625        22099
 |- Markdown             369         9181          454         7569         1158
 (Total)                           246560       209109        14194        23257
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Total                   975       314321       251450        28856        34015
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

…unch list status

- anthropic.rs: classify_error_kind() promotes generic api_error to
  invalid_request_error / not_found_error / overloaded_error based on
  message pattern. Engine-side error classification is still TBD; this
  is the protocol-shape half of be43477. Honors explicit caller kind.
- PUNCH_LIST_FROM_DS4.md: status table for original 8-item audit + the
  reviewed post-launch upstream commits. Marks 037ee39, 613e9b2, be43477
  as ported; 312935e and 950e8e6 as already-covered; flags 7b68234,
  f074c7b, d0357ec, b62292c, 5bc1e6d, c9dd949 as pending (most blocked
  on disk-KV punch-list #1).

cargo check -p mistralrs-server-core --no-default-features: ok.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@hanzo-dev

Copy link
Copy Markdown
Member Author

Superseded with #2 — being re-ported as a fresh PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants