Skip to content

fix(server): thread dry_sequence_breakers through the greedy branch - #1124

Merged
inureyes merged 3 commits into
mainfrom
fix/issue-1102-greedy-dry-sequence-breakers
Aug 13, 2026
Merged

inureyes merged 3 commits into
mainfrom
fix/issue-1102-greedy-dry-sequence-breakers

Conversation

@inureyes

@inureyes inureyes commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

Summary

The greedy branch of build_sampling_config (src/execution/sampling.rs) forwarded four of the five DRY fields and let dry_sequence_breakers fall through to SamplingConfig::greedy(), which sets an empty vector. DRY is not gated on temperature, so a server request with temperature: 0 and a positive dry_multiplier ran the penalty with no breakers at all.

Related issues

Closes #1102

Type of change

  • fix (bug fix)
  • docs (the technical report and the CHANGELOG.md entry that accompany it)

Why it mattered

The breakers are the DRY backward match's termination condition (config.dry_sequence_breakers.contains(&window[p1]) in src/lib/mlxcel-core/src/sampling.rs:846), not a sampling knob. That test precedes the token-equality test in the loop, so removing breakers can only lengthen the match or leave it unchanged: match_len runs past the intended boundary and dry_multiplier * dry_base.powi(match_len - dry_allowed_length) comes out at or above what the request asked for, strictly above whenever the tokens beyond the boundary also match. At temperature: 0 the argmax can then land on a different token, silently, with the request having been accepted as valid.

The path is server-only and reachable from both request shapes (src/server/types/request.rs:601 and :978), so {"temperature": 0, "dry_multiplier": 0.8, "dry_sequence_breakers": [198]} was a supported request whose breakers did nothing. The CLI cannot reach it: resolved_cli_sampling_params hardcodes Vec::new() and exposes no flag (documented in #1118).

What changed

src/execution/sampling.rs: the greedy branch now forwards dry_sequence_breakers: params.dry_sequence_breakers alongside the four DRY fields it already carried. The added comment records why the field belongs here rather than in SamplingConfig::greedy(): it is a match-termination condition, and leaving it empty inflates the penalty rather than disabling anything. This mirrors the reasoning the neighbouring XTC comment already states for the same branch. SamplingConfig::greedy() still supplies top_k: 1 and top_p: 1.0, so greedy determinism is untouched, and a request with dry_multiplier: 0.0 sees no behavior change at all because DRY is not applied. After the change the greedy branch forwards every field of ResolvedSamplingParams except temperature, top_k and top_p, which are exactly the three that define greedy, so the class of defect (a silent per-field omission in the branch's struct literal) is closed rather than just this instance of it.

src/execution/sampling_tests.rs: build_sampling_config_uses_greedy_defaults_when_temperature_is_zero asserted the empty vector while asserting none of the four DRY fields the branch did forward, so it stated half the contract with no comment saying why. It now asserts all five DRY fields with a comment recording that DRY runs independently of temperature. A named regression test, build_sampling_config_keeps_dry_sequence_breakers_at_zero_temperature, covers the reported request directly and re-asserts top_k / top_p so a future change cannot fix the breakers by weakening greedy.

src/server/request_options_tests.rs: build_server_generate_options_applies_request_overrides is the end-to-end shape of the bug report (temperature: Some(0.0), dry_multiplier: Some(0.9), dry_sequence_breakers: Some(vec![1, 2])) and asserted Vec::<i32>::new(). It failed on the fix, which is the second independent confirmation that the defect was real rather than a test-only artifact; it now asserts the requested breakers.

CHANGELOG.md: an ## [Unreleased] / ### Fixed entry, because this changes generated tokens for existing callers at temperature <= 0 with DRY enabled. The v0.5.0 "Changed" section documents two narrower sampler token-stream changes the same way.

TECHNICAL_REPORTS/1124-greedy-dry-sequence-breakers-20260814.{en,ko}.md: the report for this PR, committed with the fix per the TECHNICAL_REPORTS/.keep-reports marker.

Test plan

  • cargo fmt --all -- --check clean
  • cargo clippy --profile test-fast --features cuda --lib --tests -- -D warnings clean (exit 0). The template's --workspace --all-targets form was not run: this host builds MLX from source and that invocation does not finish inside the available window. The scoped run covers both edited test modules and the edited production module.
  • cargo test --profile test-fast --features cuda --lib execution::sampling (3 passed)
  • cargo test --profile test-fast --features cuda --lib server::request_options (35 passed)
  • cargo test --profile test-fast --features cuda --test cli_help_consistency (17 passed, unchanged by this PR, run as a CLI-surface regression check)
  • Verified before the fix that build_server_generate_options_applies_request_overrides reproduces the defect independently (left: [1, 2], right: [])
  • cargo test --workspace --profile test-fast and cargo deny check not run here; the change adds no type, signature, or dependency, and both structs already carried the field, so nothing outside the two edited test modules can fail to compile because of it.
  • No real-checkpoint validation. The defect and the fix are both at the configuration-assembly boundary; a generation-level assertion would be seed- and checkpoint-dependent and would not pin the contract that was broken.

`build_sampling_config` branches on `temperature <= 0.0`. The sampled branch forwards all five DRY fields; the greedy branch forwarded four and let `dry_sequence_breakers` fall through to `SamplingConfig::greedy()`, which sets an empty vector. DRY is not gated on temperature: `mlxcel_core::sampling` applies it whenever `dry_multiplier > 0.0`, and the breakers are the backward match's termination condition. With an empty vector the match never stops at a boundary token, `match_len` grows past the requested window, and `dry_multiplier * dry_base.powi(match_len - dry_allowed_length)` comes out larger than the request asked for. At temperature 0 the argmax can then land on a different token.

The server accepts `dry_sequence_breakers` per request on both request shapes, so `{"temperature": 0, "dry_multiplier": 0.8, "dry_sequence_breakers": [198]}` was a supported request whose breakers did nothing. The CLI cannot reach this path: `resolved_cli_sampling_params` hardcodes an empty vector and has no flag to set it.

The greedy branch now forwards the field alongside the other four, with a comment recording that the breakers are a match-termination condition rather than a sampling knob. `SamplingConfig::greedy()` still supplies `top_k: 1` and `top_p: 1.0`, so greedy determinism is unchanged; DRY is a logits pre-processing step.

Two tests pinned the defect. `build_sampling_config_uses_greedy_defaults_when_temperature_is_zero` asserted the empty vector without asserting the four DRY fields the branch did forward, so it stated half the contract; it now asserts all five and says why. `build_server_generate_options_applies_request_overrides` is the end-to-end shape of the bug report (`temperature: 0`, `dry_multiplier: 0.9`, breakers `[1, 2]`) and asserted an empty result; it now asserts the requested breakers. A named regression test covers the reported request directly.

Validated with `cargo test --profile test-fast --features cuda --lib execution::sampling` and `--lib server::request_options`, both green, plus `cargo fmt --all --check`.

Closes #1102
@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority status:review Under review labels Aug 13, 2026
Review follow-up for PR #1124. The fix changes generated tokens for any existing caller sending `temperature <= 0` with `dry_multiplier > 0` and a non-empty `dry_sequence_breakers`, which is the class of change the v0.5.0 "Changed" section already documents twice for narrower sampler work. A new `## [Unreleased]` / `### Fixed` entry records it, including the two shapes that are byte-identical to before (`dry_multiplier` left at its `0.0` default, or no breakers set) so a reader can tell whether their deployment is affected.

The technical report claimed the penalty "comes out exponentially larger than requested". That overstates it. The breaker test precedes the token-equality test in the match loop, so removing breakers can only lengthen the match or leave it unchanged: the penalty is never smaller than requested, and strictly larger only when the tokens beyond the boundary also match. Both the English and Korean reports now say that. The code comment was already hedged correctly and is unchanged.

Refs #1102
@inureyes inureyes added status:done Completed and removed status:review Under review labels Aug 13, 2026
@inureyes
inureyes merged commit 8aa409d into main Aug 13, 2026
7 checks passed
@inureyes
inureyes deleted the fix/issue-1102-greedy-dry-sequence-breakers branch August 13, 2026 16:13
@inureyes inureyes self-assigned this Aug 27, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…ablup#1124)

## Summary

The greedy branch of `build_sampling_config` (`src/execution/sampling.rs`) forwarded four of the five DRY fields and let `dry_sequence_breakers` fall through to `SamplingConfig::greedy()`, which sets an empty vector. DRY is not gated on temperature, so a server request with `temperature: 0` and a positive `dry_multiplier` ran the penalty with no breakers at all.

## Related issues

Closes lablup#1102

## Type of change

- [x] `fix` (bug fix)
- [x] `docs` (the technical report and the `CHANGELOG.md` entry that accompany it)

## Why it mattered

The breakers are the DRY backward match's termination condition (`config.dry_sequence_breakers.contains(&window[p1])` in `src/lib/mlxcel-core/src/sampling.rs:846`), not a sampling knob. That test precedes the token-equality test in the loop, so removing breakers can only lengthen the match or leave it unchanged: `match_len` runs past the intended boundary and `dry_multiplier * dry_base.powi(match_len - dry_allowed_length)` comes out at or above what the request asked for, strictly above whenever the tokens beyond the boundary also match. At `temperature: 0` the argmax can then land on a different token, silently, with the request having been accepted as valid.

The path is server-only and reachable from both request shapes (`src/server/types/request.rs:601` and `:978`), so `{"temperature": 0, "dry_multiplier": 0.8, "dry_sequence_breakers": [198]}` was a supported request whose breakers did nothing. The CLI cannot reach it: `resolved_cli_sampling_params` hardcodes `Vec::new()` and exposes no flag (documented in lablup#1118).

## What changed

**`src/execution/sampling.rs`**: the greedy branch now forwards `dry_sequence_breakers: params.dry_sequence_breakers` alongside the four DRY fields it already carried. The added comment records why the field belongs here rather than in `SamplingConfig::greedy()`: it is a match-termination condition, and leaving it empty inflates the penalty rather than disabling anything. This mirrors the reasoning the neighbouring XTC comment already states for the same branch. `SamplingConfig::greedy()` still supplies `top_k: 1` and `top_p: 1.0`, so greedy determinism is untouched, and a request with `dry_multiplier: 0.0` sees no behavior change at all because DRY is not applied. After the change the greedy branch forwards every field of `ResolvedSamplingParams` except `temperature`, `top_k` and `top_p`, which are exactly the three that define greedy, so the class of defect (a silent per-field omission in the branch's struct literal) is closed rather than just this instance of it.

**`src/execution/sampling_tests.rs`**: `build_sampling_config_uses_greedy_defaults_when_temperature_is_zero` asserted the empty vector while asserting none of the four DRY fields the branch did forward, so it stated half the contract with no comment saying why. It now asserts all five DRY fields with a comment recording that DRY runs independently of temperature. A named regression test, `build_sampling_config_keeps_dry_sequence_breakers_at_zero_temperature`, covers the reported request directly and re-asserts `top_k` / `top_p` so a future change cannot fix the breakers by weakening greedy.

**`src/server/request_options_tests.rs`**: `build_server_generate_options_applies_request_overrides` is the end-to-end shape of the bug report (`temperature: Some(0.0)`, `dry_multiplier: Some(0.9)`, `dry_sequence_breakers: Some(vec![1, 2])`) and asserted `Vec::<i32>::new()`. It failed on the fix, which is the second independent confirmation that the defect was real rather than a test-only artifact; it now asserts the requested breakers.

**`CHANGELOG.md`**: an `## [Unreleased]` / `### Fixed` entry, because this changes generated tokens for existing callers at `temperature <= 0` with DRY enabled. The v0.5.0 "Changed" section documents two narrower sampler token-stream changes the same way.

**`TECHNICAL_REPORTS/1124-greedy-dry-sequence-breakers-20260814.{en,ko}.md`**: the report for this PR, committed with the fix per the `TECHNICAL_REPORTS/.keep-reports` marker.

## Test plan

- [x] `cargo fmt --all -- --check` clean
- [x] `cargo clippy --profile test-fast --features cuda --lib --tests -- -D warnings` clean (exit 0). The template's `--workspace --all-targets` form was not run: this host builds MLX from source and that invocation does not finish inside the available window. The scoped run covers both edited test modules and the edited production module.
- [x] `cargo test --profile test-fast --features cuda --lib execution::sampling` (3 passed)
- [x] `cargo test --profile test-fast --features cuda --lib server::request_options` (35 passed)
- [x] `cargo test --profile test-fast --features cuda --test cli_help_consistency` (17 passed, unchanged by this PR, run as a CLI-surface regression check)
- [x] Verified before the fix that `build_server_generate_options_applies_request_overrides` reproduces the defect independently (`left: [1, 2]`, `right: []`)
- [ ] `cargo test --workspace --profile test-fast` and `cargo deny check` not run here; the change adds no type, signature, or dependency, and both structs already carried the field, so nothing outside the two edited test modules can fail to compile because of it.
- [ ] No real-checkpoint validation. The defect and the fix are both at the configuration-assembly boundary; a generation-level assertion would be seed- and checkpoint-dependent and would not pin the contract that was broken.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(server): greedy sampling branch drops per-request dry_sequence_breakers when temperature <= 0

1 participant