Skip to content

[Refactor] sampling: Build watermark rows per step - #52158

Merged
hnyls2002 merged 1 commit into
mainfrom
lsyin/watermark-step-rows
Nov 22, 2026
Merged

hnyls2002 merged 1 commit into
mainfrom
lsyin/watermark-step-rows

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Watermark rows (SynthIDRows, GumbelRows) were built once per SamplingBatchInfo and then carried through every filter_batch and merge_batch. Each row is a pure function of its request's sampling params, so the scheduler was maintaining per-batch state that it could rebuild from the step's requests. #52035 did the same for penalties: the scheduler builds each step's penalty state at launch, and nothing is filtered or merged.

Modifications

  • Scheduler.run_batch builds the step's watermark rows from batch.reqs with build_watermark_rows, next to StepPenalties.build, and sets them on batch.sampling_info.watermark. Every reader (seed_payload in ForwardBatch.init_new, bind_sample, bind_verify, the logits processor, and the spec verify paths) runs inside the forward that run_batch launches.
  • Removed:
    • the build in SamplingBatchInfo.from_schedule_batch;
    • the watermark lines in filter_batch / merge_batch;
    • merge_watermark_rows;
    • filter / concat / prepend_off from the WatermarkRows protocol and from SynthIDRows / GumbelRows;
    • Gumbel's _off_rows.
  • The row builders copy to the device with async_h2d, so the per-step build does not block on the copy.
  • README: the batch layout now describes per-step rows.

Behavior changes

  • A Gumbel batch merged from a batch without watermark candidates used to fill that side with off rows (key 0, window 1, disabled). Those rows now carry each request's own key, window, and enabled, as a batch that was never merged already did. Every kernel and torch path gates on enabled and top_k > 1 together, so no output changes.
  • With watermarking on, rows are rebuilt every step instead of on filter or merge. This costs one Python pass over the step's requests plus non-blocking copies. Servers without watermarking only pay one feature check.

Accuracy Tests

  • The filter/merge watermark unit tests are removed with the code they covered. The rows are built where the e2e watermark tests (test_watermark.py, test_synthid_watermark.py) already exercise them.
  • The SynthID adapter tests, the watermark kernel tests, and the unit tests in sampling, spec, scheduler and disaggregation pass, except failures that also fail on main.

Checklist

  • Unit tests updated.

CI States

Latest PR Test (Base): ⊘ Skipped -- add the run-ci label to run CI tests.
Latest PR Test (Extra): ⊘ Skipped -- add the run-ci label to run CI tests.
Latest PR Test (AMD ROCm 10): ⊘ Skipped -- add the run-ci label to run CI tests.

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Nov 21, 2026
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_watermark.py test_synthid_watermark.py test_watermark_selector.py test_watermark_state.py registered/kernels/ops/sampling/test_synthid.py test_synthid_adapter.py test_sampling_batch_info.py test_eagle_post_verify_graphs.py test_overlap_uocr_decode.py

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-5090 (5 tests): ✅ View workflow run

cd test/ && python3 registered/e2e/openai_server/test_watermark.py  # extra-a
cd test/ && python3 registered/e2e/openai_server/test_synthid_watermark.py  # extra-a
cd test/ && python3 registered/kernels/ops/sampling/test_watermark_selector.py  # base-b-kernel-unit
cd test/ && python3 registered/kernels/ops/sampling/test_watermark_state.py  # base-b-kernel-unit
cd test/ && python3 registered/unit/spec/test_eagle_post_verify_graphs.py  # base-b

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/sampling/test_synthid.py  # base-b-kernel-unit

🚀 ubuntu-latest (3 tests): ✅ View workflow run

cd test/ && python3 registered/unit/sampling/test_synthid_adapter.py  # base-a
cd test/ && python3 registered/unit/sampling/test_sampling_batch_info.py  # base-a
cd test/ && python3 registered/unit/managers/test_overlap_uocr_decode.py  # base-a

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/run-cpu-ci

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Running base-a-test-cpu on 4821cf08f821: ❌ View workflow run

@hnyls2002
hnyls2002 merged commit 7df7c09 into main Nov 22, 2026
152 of 153 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/watermark-step-rows branch November 22, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant