Skip to content

[DLLM] Implement initial dynamic batching for diffusion LLM - #14883

Merged
hnyls2002 merged 6 commits into
sgl-project:mainfrom
ClawSeven:dllm-batching
Jan 17, 2026
Merged

hnyls2002 merged 6 commits into
sgl-project:mainfrom
ClawSeven:dllm-batching

Conversation

@ClawSeven

@ClawSeven ClawSeven commented Dec 11, 2025 •

Copy link
Copy Markdown
Collaborator

Motivation

The current dLLM implementations lack batching capabilities, with batch size set to 1 by default. Additionally, the existing dLLM implementation is tightly coupled with chunked prefill execution, limiting flexibility and extensibility.

Modifications

This PR introduces two key improvements:

  • Basic Batching Support: Enables the dLLM to batch incoming requests when the number of running requests has not reached the configured limit. New requests will be grouped with existing batches to improve resource utilization.
  • Decoupling of dLLM and Chunked Prefill: Separates the dLLM logic from the chunked prefill execution, laying the foundation for future enhancements such as radix cache support and overlap scheduling.

No new arguments are required—this relies solely on the existing max-running-requests configuration. Note that this is an initial implementation of DLLM batching and is not yet optimized. Currently, prefill and decoding requests are batched together, which may lead to redundant computations. We will address these optimizations in subsequent PRs

Currently, we still recommend using batch size 1 for running dLLM until the batching optimization PRs are merged.

Accuracy Tests

Tested on H20

Accuracy: 0.900
Invalid: 0.000
Latency: 263.453 s
Output throughput: 97.638 token/s
metrics={'accuracy': 0.9, 'invalid': 0.0, 'latency': 263.45285430923104, 'output_throughput': 97.63796284327712}

Here I added a dLLM batching‑accuracy test instead of changing the max‑running‑requests argument in the previous LLaDA unit test, since the current batching performance is suboptimal. Once the optimization PRs are merged, I’ll remove this test.

Benchmarking and Profiling

Checklist

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ClawSeven, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces significant enhancements to the SGLang framework by enabling dynamic batching for Diffusion LLMs (DLLM). The changes allow the system to efficiently process multiple DLLM requests concurrently, leading to improved resource utilization and overall performance. This involved a fundamental shift in how chunked requests are managed, moving from a single request model to a collection-based approach, alongside corresponding updates to the DLLM algorithm for batched processing and adaptations within the scheduler and output handling mechanisms.

Highlights

  • Dynamic Batching for DLLM: The core change introduces dynamic batching capabilities for Diffusion LLMs (DLLM), allowing the system to process multiple DLLM requests concurrently within a single batch, enhancing throughput and efficiency.
  • New ChunkedReqs Class: A new ChunkedReqs class has been implemented to manage a collection of chunked requests, replacing the previous single chunked_req approach. This class handles adding, flushing, and updating the status of multiple requests.
  • Configurable Concurrent Requests: The DllmConfig now includes a max_running_requests parameter, enabling users to configure the maximum number of concurrent DLLM requests the system can handle.
  • Batched Processing in Low Confidence Algorithm: The LowConfidence algorithm (low_confidence.py) has been updated to process input IDs and logits in a batched manner, iterating over multiple blocks and returning a list of next token IDs, reflecting the new batched approach.
  • Scheduler and Output Processor Refactoring: The scheduler and output processing logic have been refactored to seamlessly integrate with the new ChunkedReqs object and correctly handle the batched output generated by the DLLM algorithm.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@ClawSeven ClawSeven mentioned this pull request Dec 11, 2025
20 of 49 tasks

@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 introduces support for dynamic batching in the Diffusion Language Model (DLLM) components. The changes primarily involve modifying the scheduler to handle batches of chunked requests and updating the low-confidence algorithm to process these batches. I've identified a critical issue in the scheduler logic that could lead to incorrect behavior, as well as a significant performance issue in the memory pool's double-free check. Additionally, there are some opportunities for code improvement in terms of readability and efficiency, and an important Fixme that should be addressed.

Comment thread python/sglang/srt/managers/scheduler.py Resolved
start = len(forward_batch.input_ids) - torch.sum(mask_index).item()

# Fast path: if there is no mask token, forward and save kv cache
if torch.sum(mask_index).item() == 0:

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.

medium

Using torch.sum(mask_index).item() == 0 to check for the absence of True values in a boolean tensor is less idiomatic and potentially less efficient than using not mask_index.any(). This pattern is repeated throughout the file (lines 49, 54, 67, 87). I recommend replacing all occurrences for better readability and performance.

Suggested change
if torch.sum(mask_index).item() == 0:
if not mask_index.any():

@ClawSeven
ClawSeven force-pushed the dllm-batching branch 2 times, most recently from 82a13b7 to 5558186 Compare December 25, 2025 12:35
@ClawSeven
ClawSeven marked this pull request as ready for review December 25, 2025 12:36
@ClawSeven

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Dec 26, 2025
@sgl-project sgl-project deleted a comment from ClawSeven Dec 27, 2025
@zhaochenyang20

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

1 similar comment
@ClawSeven

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@@ -1134,6 +1134,59 @@ def __repr__(self):
)


class DllmReqs:

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.

I noticed that the DllmReqs will not be passed as Forwardbatch to the algorithm interface yet. I wonder whether we will pass it to the algorithm interface in the future to enable the token shift for algorithms like fast-dllm-v2. @ClawSeven It looks like passing the DllmReq to the algorithm interface can enable more flexibility in the algorithm side.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I believe we will provide more reqs information for the DLLM algorithm, but I may not parse all of the reqs.

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.

We may discuss this issue in the other algorithm support PR like fast dllm v2. Keep this for now.

@@ -38,6 +40,12 @@ def from_server_args(
f"Unknown diffusion LLM: {model_config.hf_config.architectures[0]}"
)

max_running_requests = (
1

@Monstertail Monstertail Jan 3, 2026 •

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.

Shall we set it to a more reasonable default value rather than 1 in the future? As in speculative decoding, it is set to 48.

self.max_running_requests = 48

Even if we want to show a latency-sensitive case, maybe 2 would be better?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The current dLLM implementation does not separate prefill and decode batching, meaning the PR is still in the initial version and only supports dynamic batching. Performance optimization will be added later. The default batch size will be set to 8 in the future.

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.

I see... That makes sense

curr_block_start:curr_block_end,
]

x = torch.argmax(curr_logits, dim=-1)

@Monstertail Monstertail Jan 7, 2026 •

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.

In the future, we may need to replace the argmax to support sampling. #16615

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we have a PR for implementing more sampling algorithms.

@hnyls2002 hnyls2002 removed the run-ci CI: run the baseline test suite on this PR label Jan 14, 2026

@hnyls2002 hnyls2002 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add a unit-test for that.

Comment thread python/sglang/srt/managers/utils.py Resolved
@hnyls2002

Copy link
Copy Markdown
Collaborator

@ClawSeven

I don’t think dllm_reqs is a good name here.
This variable represents an intermediate/in-flight state (similar to chunked_req), not a stable set of requests. Using dllm_reqs is confusing and makes it unclear what stage these requests are in.

Maybe rename it to something like:

  • dllm_running_requests
  • dllm_ongoing_requests

For the has_running_req logic, you can just rely on the container itself (e.g. size() / empty()).

Comment thread python/sglang/srt/managers/scheduler.py Resolved
Comment thread python/sglang/srt/managers/scheduler.py Resolved
Comment thread python/sglang/srt/managers/scheduler.py Resolved
Comment thread python/sglang/srt/managers/scheduler.py Resolved
Comment thread python/sglang/srt/managers/scheduler.py Resolved
@ClawSeven ClawSeven changed the title [DLLM] Support dynamic batching in dllm [DLLM] Implement initial dynamic batching for diffusion LLM Jan 15, 2026
@ClawSeven

Copy link
Copy Markdown
Collaborator Author

@ClawSeven

I don’t think dllm_reqs is a good name here. This variable represents an intermediate/in-flight state (similar to chunked_req), not a stable set of requests. Using dllm_reqs is confusing and makes it unclear what stage these requests are in.

Maybe rename it to something like:

  • dllm_running_requests
  • dllm_ongoing_requests

For the has_running_req logic, you can just rely on the container itself (e.g. size() / empty()).

@hnyls2002 Hi,
I'm currently using dllm_staging_reqs as a replacement for dllm_reqs, and I'm using non_empty() as the function name instead of has_running_req. Do you have any suggestions or feedback?

@hnyls2002

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jan 16, 2026
@hnyls2002
hnyls2002 merged commit d2c8638 into sgl-project:main Jan 17, 2026
0826joyce pushed a commit to 0826joyce/sglang-perf-opt that referenced this pull request May 19, 2026
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 29, 2026
…fill has not returned

Three boots of forensics land on one invariant. A request that has never
produced an output token has nothing to decode from, and decoding it anyway is
what has been killing this window's boots on their first short prompt.

The chain, measured end to end: get_next_batch_to_run makes a freshly built
PREFILL batch the running batch in the same breath. Upstream that holds --
without PP the prefill runs in the same round, so output_ids is non-empty by
the time update_running_batch sees it. The seam is stock, every commit
touching it is an upstream PR (sgl-project#29408, sgl-project#22131, sgl-project#20343, sgl-project#14320, sgl-project#17484,
sgl-project#14883), none of ours, so there is nothing to revert. PP=3 widens it: the
result comes back several passes later while membership was granted
immediately, and with one short request and no other traffic the next round
has nothing else to do and decodes it first. prepare_for_decode then leaves
the prefill input_ids in place -- there is no last token to embed -- and the
batch travels on labelled DECODE while carrying extend tokens.

Boot 67 read every link: rid e463acc5, prefix_lens=0 fill_lens=3 out_lens=0,
one ADMIT, no retraction, and no void at all (797_void=0, 798_void=0, so the
void explanation is excluded). It surfaced first as forward_mode=2 with
batch_size=1 and input_ids=3 through the sgl-project#1007 probe, then as
"causal_conv1d_update: conv_state_indices has 1 entr(ies) for a batch of 3".
Every short prompt does this, health checks included; long chunked prompts
under continuous load never reach the state, which is exactly why it stayed
latent behind every other defect this window.

So the hold sits where decode eligibility is decided, not on a consumer. The
requests are neither dropped nor reset: they stay in the running batch and
become eligible the moment their prefill result lands, and filter_batch's
keep_indices keeps the parallel tensors consistent rather than reseating reqs
by hand.

The counter is cumulative on purpose (INDIKATOR-GESETZ): a held_total that
never grows means the class no longer occurs, one that grows without bound
means results are not landing at all. Those are different diagnoses and a
per-call line could not tell them apart.

Evidence: desk, executed. py_compile; the condition sits inside
update_running_batch ahead of prepare_for_decode, and the counter is written
once and read twice. Belegstufe: DESK-BEWIESEN -- BOOT-BEWIESEN only once the
3-token probe returns tokens.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

high priority run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants