Skip to content

[rl] generator: receive SGLang scheduler outputs through output_sink - #6018

Draft
acisseJZhong wants to merge 3 commits into
pytorch:mainfrom
acisseJZhong:sglang-output-sink
Draft

acisseJZhong wants to merge 3 commits into
pytorch:mainfrom
acisseJZhong:sglang-output-sink

Conversation

@acisseJZhong

Copy link
Copy Markdown
Contributor

Depends on sgl-project/sglang#49667 (draft).

Summary (human-written)

Why

SGLangEngine runs SGLang's Scheduler in-process, with no tokenizer or detokenizer process. To get the scheduler's results and aborts, it replaces two private attributes after construction (output_streamer.send_to_detokenizer and ipc_channels.send_to_tokenizer). This was the TODO for sgl-project/sglang#48473. The patching depends on SGLang's private attribute layout, and it misses any component that captured a sender during Scheduler.__init__.

sgl-project/sglang#49667 adds a constructor argument for this case.

Example.

# before
self._scheduler = Scheduler(server_args, PortArgs.init_new(server_args))
self._output_collector = _OutputCollector()
self._scheduler.output_streamer.send_to_detokenizer = self._output_collector
self._scheduler.ipc_channels = dataclasses.replace(
    self._scheduler.ipc_channels, send_to_tokenizer=self._output_collector
)

# after
self._output_collector = _OutputCollector()
self._scheduler = Scheduler(
    server_args,
    PortArgs.init_new(server_args),
    output_sink=self._output_collector.receive,
)

What changed

  • torchtitan/rl/generator/sglang/engine.py: passes output_sink= and drops the patching and its TODO. _OutputCollector.send_output(output, recv_obj) becomes receive(output); its logic is unchanged.
  • scripts/install_rl_env.sh: pins SGLang to e3bd24b53c, which is the currently pinned 851642ade7 plus the sglang#49667 patch, on a fork. This change is temporary: once #49667 lands, it switches to the upstream commit (see the TODO in the script).

Numerics

No computation change: the collector receives the same output objects as before.

Testing

Ran tests/rl/unit_tests/gpu/test_sglang_bitwise_parity.py with the same per-class launches as the SGLang generator tests CI step, on 8x H100. I ran it both on this branch and on main (bb34c75), each with the patched SGLang installed. SGLang's output_sink defaults to None, so main still takes the old patching path.

Class Ranks main this PR
Varlen (Qwen3-0.6B) 2 7 passed / 7 passed same
MoEEP 2 5 passed, 1 skipped (each rank) same
SlidingWindow 2 6 passed (each rank) same
MLA 2 rank A: 3 bitwise failures; rank B: 5 passed same
KDA 1 3 bitwise failures, 3 passed same
GDN 2 6 errors (recurrent_gdn() ... 'kernel_options') same
DistMoE 2 6 skipped same

The MLA, KDA, GDN and DistMoE results are failures or skips in my environment, and they reproduce on main. Two causes:

  • The GPUs are H100; the engine is verified only on Blackwell, where CI runs.
  • My local attention-gym version does not match (GDN).

These need the B200 CI run of this PR to confirm.

Environment workarounds, all local only:

  • SGLANG_ENABLE_JIT_DEEPGEMM=0: there is no NVCC 12.9 on the host.
  • LD_PRELOAD of libcublas.so.13: the vLLM wheel fails to import otherwise, also on main.

Known issues / follow-ups

Pass the output collector to SGLang's new Scheduler(output_sink=...) instead
of replacing the scheduler's private tokenizer/detokenizer senders after
construction (sgl-project/sglang#48473).
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 10, 2026
No tokenizer or detokenizer process runs (skip_tokenizer_init), and SGLang
hands every scheduler output to the sink; the collector keeps only token
increments and aborts.
Restore the original docstring and update only the sentence that described the
replaced senders.

This branch has not been deployed

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

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant