Skip to content

fix(provider): stop Qwen 3.5/3.6 looping to max_tokens on omitted sampling - #1652

Merged
Gajesh2007 merged 2 commits into
Layr-Labs:masterfrom
javiech1:fix/qwen35-9b-sampling-defaults
Oct 28, 2026
Merged

Gajesh2007 merged 2 commits into
Layr-Labs:masterfrom
javiech1:fix/qwen35-9b-sampling-defaults

Conversation

@javiech1

@javiech1 javiech1 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Requests that omit sampling fields decode the catalog Qwen 3.5/3.6 builds greedily with no presence penalty (temperature 0, presence_penalty 0), and the model then repeats itself until max_tokens. That is the 15–40 minute "stuck" request in #1530 and in #providers (49,986 and ~64,000 completion tokens for a few cents). None of them ships a generation_config.json, so they never got the artifact defaults other families use. Omitted knobs now take their model cards' thinking-mode values (identical on all three cards): temperature 1.0, top_p 0.95, top_k 20, presence_penalty 1.5. Each card says the presence penalty is there "to reduce endless repetitions".

Linked issue

Closes #1530

Test plan

  • swift build --build-tests (provider-swift)
  • swift test --skip-build --filter "Sampling|Translation|Bridge|Qwen35|Bonsai": 251 tests in 60 suites pass, including the new qwen35CatalogBuildsUseTheirModelCardDefaults.
  • make changelog-check, make docs-impact-check BASE=origin/master, make docs-check: OK.
  • Live, M5 Max 128 GB, darkbloom start --local dev build, four concurrent requests, thinking on, the same 20 prompts per model:
max_tokens 8,192 Runaway repetition, omitted (today) with card values Hit max_tokens, omitted with card values
Qwen3.5-9B 7 / 20 0 / 20 15 12
qwen3.5-35b-a3b 8 / 20 0 / 20 11 1
qwen3.6-35b-a3b-vl-mtp-mxfp8 3 / 20 0 / 20 10 8

Decode speed is unchanged (9B, requests that ran to the cap: 61.9 tok/s greedy, 62.4 tok/s with card values).

Qwen3.5-9B looping prompts, max_tokens 32,768 Omitted sampling Model-card values
"Count from 1 to 300 in words." repeats to 32,768 (17 min) stops at 8,981
"List 100 different animals, one per line." repeats to 32,768 stops at 23,911
"Write 50 jokes about programmers." repeats to 32,768 32,768, no repetition
Red-black tree implementation repeats to 32,768 32,768, no repetition

"Runaway repetition" means the last 3,000 characters end in a 40–160-character span repeated four or more times. The detector's only card-values hit, on each model, was the song prompt, whose chorus repeats by design; it stopped on its own.

Components touched

  • provider-swift (Swift CLI)
  • docs

Protocol / interface changes

  • No protocol/interface changes

Documentation impact

  • Canonical documentation updated (docs/architecture/inference.md: sampling table and the artifact-defaults paragraph)

Changelog

  • Added changelog.d/qwen35-9b-sampling-defaults.md and ran make changelog-check.

Notes for reviewers

  • Admission is a table of the three exact catalog identities, each bound to its model_type (EngineV2SamplingDefaults.qwen35CardModelTypes), like ToolChoiceEnforcementPolicy.structuredForcedToolModelTypes. Other Qwen 3.5 builds stay legacy.
  • This sets a default presence_penalty, which no family did before. The Bonsai 9B note in inference.md deliberately leaves it to qualification requests; here the card value is what stops the loops, so it is a default.
  • The values are the card's thinking-mode set (the template default). A request that turns thinking off gets the same defaults unless it sends its own.
  • I could not see whether OpenRouter requests that reach the provider carry temperature; the provider logs do not record it. If most do, this fixes fewer real requests than the test suggests.
  • Thinking still makes some answers long: 12 / 20 still reached 8,192 tokens with the card values, but without repeating.

Before And After

flowchart LR
  subgraph Before
    B1["request omits temperature<br/>and presence_penalty"] --> B2["catalog Qwen 3.5/3.6: legacy<br/>temperature 0, presence 0"]
    B2 --> B3["greedy loop until max_tokens<br/>(up to 65,536 tokens)"]
  end
  subgraph After
    A1["request omits temperature<br/>and presence_penalty"] --> A2["EngineV2SamplingDefaults.resolve<br/>qwen35CardModelTypes match"]
    A2 --> A3["temperature 1.0, top_p 0.95,<br/>top_k 20, presence 1.5"]
    A3 --> A4["stops on its own"]
    A5["explicit request values"] --> A6["always win"]
  end
Loading

Refactor Pass

Reviewed the diff for reuse and scope: the card values are one constant next to .legacy shared by the three builds, resolve checks the identity table before the artifact-file gate, and the translation adds one fallback. Nothing else to remove or merge. Focused suites above re-run green after the review.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

javiech1 and others added 2 commits October 28, 2026 16:50
Requests that omit sampling fields decoded Qwen3.5-9B greedily with no
presence penalty, and the model repeated itself until max_tokens (Layr-Labs#1530).
The catalog build ships no generation_config.json, so omitted knobs now
take its model card's thinking-mode values: temperature 1.0, top_p 0.95,
top_k 20, presence_penalty 1.5. Explicit request values still win; every
other model keeps its defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
qwen3.5-35b-a3b and qwen3.6-35b-a3b-vl-mtp-mxfp8 loop the same way on
omitted sampling and their model cards recommend the same thinking-mode
values. A table of exact catalog builds, each bound to its model_type,
replaces the single 9B check and shares qwen35CardDefaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 28, 2026

Copy link
Copy Markdown

@javiech1 is attempting to deploy a commit to the EigenLabs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head d382b2655dde against base 8effff7f7067.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
normal spending limit reached; remaining coverage deferred

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Human review required: CI did not complete the security review. A maintainer must review the saved findings and remaining scope. A green advisory job is not security clearance; do not manually rerun the paid scan.

Failure diagnostics: REVIEW_BUDGET_STOPPED

Coverage: 17/33 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.4934 reported, $0.0000 reserved with unknown cost; 6 paid request(s), 0 reused batch(es), 64925 provider cache-hit tokens.

Saved findings and earlier report · Historical findings are not confirmed resolved.

@javiech1

Copy link
Copy Markdown
Contributor Author

Production data point from my own provider (M5 Max, BloomGauge earnings history, 18–28 Oct): of 680 paid Qwen3.5-9B requests, 10 (1.5%) produced at least 8,000 output tokens. Those 10 account for 54% of all the 9B output tokens I served and paid $0.03 in total. For comparison, Gemma 4 26B: 97 of 230,024 requests, 6% of its tokens.

@Gajesh2007
Gajesh2007 merged commit 7d47709 into Layr-Labs:master Oct 28, 2026
4 of 9 checks passed
davidtai added a commit that referenced this pull request Oct 28, 2026
The merge adds #1566, #1591, #1602, #1605, #1606, #1607, #1612, #1621,
#1622, #1623, #1625, #1629, #1630, #1631, #1632 (provider 0.10.4),
#1633, #1644, #1652 and #1653 to this branch.

Conflicts and resolutions:
- CoordinatorClient+Connection.swift: #1606 moves the transport setup
  out of connectAndRun into the static function connectionParameters(for:),
  and puts the connectAndRun header below it. This branch adds the
  session parameter to the same header. The merge keeps the layout of
  master. The moved header has the signature of this branch:
  connectAndRun(_ session: CoordinatorSessionRecorder). Git merged the
  other changes without a conflict: the bounded handshake of master
  (CoordinatorConnectionHandshake.start) and the session recorder of
  this branch (markOpened after register, the session parameter of
  sessionLoop and receiveLoop, and the close-code read).
- docs/provider/cli-reference.md: the runtime constants table. The merge
  keeps the three reconnect rows and the ping/pong row of this branch.
  It adds the handshake deadline row of master after the ping/pong row,
  where master has it.
- docs/provider/troubleshooting.md: only the "Last updated" stamp had a
  conflict (2026-10-26 on this branch, 2026-10-27 on master). The merge
  keeps one stamp, 2026-10-27. Git merged the rows: the backoff citation
  of this branch and the new rows of master.

Each decision has one owner after the merge:
- CoordinatorReconnectPolicy chooses the wait before the next connection
  attempt, after each end of a session or of an attempt.
- CoordinatorConnectionHandshake (#1606) cancels a handshake that does
  not complete in 30 s. runLoop catches the timeout error. That attempt
  did not send register, so the policy gives the next backoff range, as
  on master.
- UnauthorizedConnectionRecovery (#1607, #1633) decides when to start a
  re-registration of a connection that the coordinator refuses. Its
  retry backoff counts re-registrations, not connection attempts, and an
  authorized verdict sets that count to zero. The re-registration closes
  the session. Then the policy chooses the wait, as for each other end.

Checks: against master, the merge has only the changes of this branch,
in its 15 files. The troubleshooting stamp is the one exception: it has
the date of master. Against this branch, the merge has only the changes
of master, in 651 files. The one exception is the connectAndRun header,
which has the session parameter. The gitlinks do not change: libs/mlx
31f550af, libs/mlx-swift 4926d3d9, libs/mlx-swift-lm aee6ebb6.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

[bug] Qwen3.5-9B request runs for about 15 minutes with high GPU usage and $0 pay/history

2 participants