Skip to content

fix(sglang): port the DataFlow capture backend to sglang 0.5.14 (up-16)#652

Merged
jiapingW merged 4 commits into
sgl-project:dataflow-up-16-zerocopyfrom
maocheng23:dataflow-up-16-sgl0.5.14
Jul 6, 2026
Merged

fix(sglang): port the DataFlow capture backend to sglang 0.5.14 (up-16)#652
jiapingW merged 4 commits into
sgl-project:dataflow-up-16-zerocopyfrom
maocheng23:dataflow-up-16-sgl0.5.14

Conversation

@maocheng23

Copy link
Copy Markdown
Collaborator

Summary

Makes up-16's DataFlow target-capture backend work on sglang 0.5.14, and bumps the pin from 0.5.90.5.14 (matching main).

On main, the 0.5.14 move landed as #605 (eagle3 / custom backends / shared infra) plus the follow-up branch patch/fix_sgl0.5.14_dflash (the DFlash-specific _extend fixes #605 didn't include). Both were written against the old layout (specforge/modeling/target/dflash_target_model.py). up-16 consolidated eagle3 + dflash extend into a single SGLangCaptureBackend (specforge/inference/target_engine/sglang_backend/capture.py), so the same sglang-API adaptations are applied there once and cover both draft algorithms (and DSpark, which builds on the DFlash path).

Changes (sglang_backend/capture.py)

  • Import move: prepare_mlp_sync_batch_raw now comes from sglang.srt.managers.scheduler_components.dp_attn (moved from …scheduler_dp_attn_mixin in 0.5.14). This is the import that was hard-crashing the whole backend on 0.5.14.
  • build(): 0.5.14 split the post-load setup out of ModelRunner.initialize() (which now only loads weights). Since we drive the ModelRunner directly (no scheduler/TpModelWorker), replicate it: alloc_memory_pool() / init_attention_backends() / init_cuda_graphs(). Also set chunked_prefill_size=-1 — we prefill the whole batch in one _forward_extend, and 0.5.14's eager runner otherwise pre-allocates buffers sized to the default chunked_prefill_size (8192) and errors when our token count exceeds it.
  • _forward_extend(): get_model_worker_batch() was removed — ForwardBatch.init_new now consumes the ScheduleBatch directly and reads capture_hidden_mode off it. Also materialize prefill_input_ids_cpu → device (the scheduler normally does this H2D copy in resolve_forward_inputs; we bypass the scheduler).
  • Req construction (dflash + eagle3 + eagle3-vlm): Req.fill_ids was removed in favor of full_untruncated_fill_ids (an array) + integer fill_len.
  • input_lens captured before the forward — origin_input_ids is released during prepare_for_extend/forward on 0.5.13+.
  • pyproject.toml: sglang==0.5.9sglang==0.5.14.

sglang_backend/{utils,patch,model_runner}.py needed no changes.

Testing

  • Against a real sglang 0.5.14 env (venv on sci-h200, 8×H200): the backend imports and the DFlash sglang capture path runs — full GPU smoke in progress; results to follow in a comment.
  • Reference parity: the diffs mirror patch/fix_sgl0.5.14_dflash (DFlash) and upgraded sglang to v0.5.14 #605 (shared/eagle3), re-expressed for the consolidated backend.

Notes

🤖 Generated with Claude Code

maocheng23 and others added 2 commits July 5, 2026 16:51
Ports the sglang 0.5.14 upgrade onto up-16's new-layout target-capture
backend. On `main` the 0.5.14 bump landed via sgl-project#605 (eagle3 / custom
backends) plus the follow-up `patch/fix_sgl0.5.14_dflash` (dflash), but
both target the OLD `specforge/modeling/target/dflash_target_model.py`
layout. up-16 consolidated eagle3 + dflash extend into a single
`SGLangCaptureBackend` (`inference/target_engine/sglang_backend/capture.py`),
so the same API adaptations are applied there once, covering both paths:

- import `prepare_mlp_sync_batch_raw` from `managers.scheduler_components.dp_attn`
  (moved from `managers.scheduler_dp_attn_mixin` in 0.5.14).
- `build()`: replicate the post-load setup 0.5.14 split out of
  `ModelRunner.initialize()` — `alloc_memory_pool()` /
  `init_attention_backends()` / `init_cuda_graphs()` — since we drive the
  ModelRunner directly; and set `chunked_prefill_size=-1` (we prefill the
  whole batch in one `_forward_extend`, no scheduler chunking).
- `_forward_extend()`: drop the removed `get_model_worker_batch()` step —
  `ForwardBatch.init_new` now consumes the `ScheduleBatch` directly and reads
  `capture_hidden_mode` off it; and materialize `prefill_input_ids_cpu` -> device
  (the scheduler normally does this in `resolve_forward_inputs`).
- Req construction (dflash + eagle3 + eagle3-vlm): `fill_ids` was removed in
  favor of `full_untruncated_fill_ids` (array) + integer `fill_len`.
- capture `input_lens` BEFORE the forward — `origin_input_ids` is released
  during prepare_for_extend/forward on 0.5.13+.
- bump pyproject pin to `sglang==0.5.14`.

Benefits eagle3 + dflash (+ dspark, which builds on the dflash path).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Two more 0.5.14 API drifts in the vendored parallel_state setup (surfaced
building the target on 0.5.14, mirrors main's post-sgl-project#605 patch.py):

- init_model_parallel_group() dropped the pynccl_use_current_stream kwarg
  (removed in 0.5.13) — remove it from the tp and pdmux_prefill_tp calls.
- compute_dp_attention_world_info() now returns a 4-tuple
  (attn_tp_rank, attn_tp_size, attn_dp_rank, attn_dp_size); the attn-tp
  rank/size are no longer module globals, so keep only _ATTN_DP_RANK.

Validated: sglang DFlash capture (Qwen2.5-0.5B) runs on sglang 0.5.14 and
returns correctly-shaped concatenated hidden states.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@maocheng23

Copy link
Copy Markdown
Collaborator Author

Validated on real sglang 0.5.14 (venv on sci-h200, 8×H200, torch 2.11): the DFlash sglang capture path builds the target and runs a real forward — generate_dflash_data on Qwen2.5-0.5B returns hidden_states=(2, 16, 2688) (3 capture layers × 896), finite. Backend imports cleanly and _forward_extend completes end-to-end.

Note: needed two extra patch.py fixes beyond the initial commit (parallel-state init) — init_model_parallel_group dropped pynccl_use_current_stream, and compute_dp_attention_world_info now returns a 4-tuple. Both mirror main's post-#605 patch.py. Now folded in.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the sglang dependency from version 0.5.9 to 0.5.14 and adapts the sglang_backend/capture.py module to accommodate several breaking changes introduced in sglang versions 0.5.13 and 0.5.14. These adaptations include updating import paths, disabling chunked prefill, replicating post-load setup steps for the ModelRunner, handling host-to-device input ID copies, adjusting ForwardBatch initialization, capturing input lengths prior to forwarding, and replacing deprecated request attributes like fill_ids with full_untruncated_fill_ids and fill_len. There are no review comments, so I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

maocheng23 and others added 2 commits July 5, 2026 17:20
The 0.5.14 port added multi-line rationale comments at each sglang-API
adaptation; several were 5-6 lines and the Req.fill_ids explanation was
duplicated verbatim across the three req-construction sites. Collapse each
to a concise "<version>: what changed / what we do" line, keeping the
version markers (the useful part in a version-coupling boundary file) and
dropping the prose. Comments only; no code changes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…iter

replaced_logits_processor_forward_for_eagle3 read self.multi_item_delimiter,
which sglang removed from the LogitsProcessor in 0.5.13 (now carried per-request
on the ForwardBatch as multi_item_delimiter_indices). On 0.5.14 that attribute
access raises AttributeError on the eagle3 capture path (wrap_eagle3_logits=True);
dflash sets it False, so the dflash smoke test did not exercise this. Extract
the indices off the ForwardBatch before the LogitsMetadata conversion, mirroring
sglang's own logits_processor. Matches the fix in sgl-project#605.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@maocheng23

Copy link
Copy Markdown
Collaborator Author

🔁 Re-validated on sglang 0.5.14 after the eagle3 fix (f59f014) + comment trim:

  • eagle3 sglang capture now runs end-to-end (wrap_eagle3_logits=True): hidden_states=(2,16,2688), target=(2,16,151936)EAGLE3_SGLANG_OK. Confirms the replaced_logits_processor_forward_for_eagle3 / multi_item_delimiter_indices fix.
  • dflash sglang capture still OK ((2,16,2688)) — no regression from the update.

Both eagle3 and dflash capture paths now work on 0.5.14.

@jiapingW jiapingW merged commit 8e793ec into sgl-project:dataflow-up-16-zerocopy Jul 6, 2026
1 check passed
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