[V1][Scheduler] Apply Mamba alignment before encoder caps (#51603)

Signed-off-by: Jiangyun Zhu <riverclouds.zhu@qq.com>
Co-authored-by: Akshat Anand <40275336+cipheraxat@users.noreply.github.com>
Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
Jiangyun Zhu
2026-08-10 16:37:17 +08:00
committed by GitHub
co-authored by Akshat Anand Codex
parent d89ba6481b
commit 243c63baf5
2 changed files with 105 additions and 20 deletions
+22 -20
View File
@@ -530,6 +530,12 @@ class Scheduler(SchedulerInterface):
- self.num_sampled_tokens_per_step,
)
# Apply Mamba alignment before encoder caps.
if self.need_mamba_block_aligned_split:
num_new_tokens = self._mamba_block_aligned_split(
request, num_new_tokens
)
# Schedule encoder inputs.
encoder_inputs_to_schedule = None
external_load_encoder_input: list[int] = []
@@ -548,11 +554,6 @@ class Scheduler(SchedulerInterface):
shift_computed_tokens=1 if self.use_eagle else 0,
)
if self.need_mamba_block_aligned_split:
num_new_tokens = self._mamba_block_aligned_split(
request, num_new_tokens
)
if num_new_tokens == 0:
# The request cannot be scheduled because one of the following
# reasons:
@@ -906,6 +907,17 @@ class Scheduler(SchedulerInterface):
num_new_tokens = min(num_new_tokens, token_budget)
assert num_new_tokens > 0
# Apply Mamba alignment before encoder caps.
if self.need_mamba_block_aligned_split:
num_new_tokens = self._mamba_block_aligned_split(
request,
num_new_tokens,
num_new_local_computed_tokens,
num_external_computed_tokens,
)
if num_new_tokens == 0:
break
# Schedule encoder inputs.
if request.has_encoder_inputs:
(
@@ -924,17 +936,6 @@ class Scheduler(SchedulerInterface):
# The request cannot be scheduled.
break
# Skip block alignment when setting up async receive (no local work).
if self.need_mamba_block_aligned_split and not load_kv_async:
num_new_tokens = self._mamba_block_aligned_split(
request,
num_new_tokens,
num_new_local_computed_tokens,
num_external_computed_tokens,
)
if num_new_tokens == 0:
break
# During async KV load, no forward pass is run yet.
# Allocate speculative lookahead slots later to avoid
# mismatching local and remote block counts.
@@ -1501,10 +1502,13 @@ class Scheduler(SchedulerInterface):
mm_hashes_to_schedule = set()
num_embeds_to_schedule = 0
encoder_window_end = (
num_computed_tokens + num_new_tokens + shift_computed_tokens
)
lo, hi = get_mm_features_in_window(
mm_features,
start=num_computed_tokens,
end=num_computed_tokens + num_new_tokens + shift_computed_tokens,
end=encoder_window_end,
)
# For encoder-decoder, all inputs sit at start_pos=0, so lo=0 always.
if self.is_encoder_decoder:
@@ -1586,9 +1590,7 @@ class Scheduler(SchedulerInterface):
# Calculate the number of embeddings to schedule in the current range
# of scheduled encoder placeholder tokens.
start_idx_rel = max(0, num_computed_tokens - start_pos)
end_idx_rel = min(
num_encoder_tokens, num_computed_tokens + num_new_tokens - start_pos
)
end_idx_rel = min(num_encoder_tokens, encoder_window_end - start_pos)
curr_embeds_start, curr_embeds_end = (
mm_feature.mm_position.get_embeds_indices_in_range(
start_idx_rel, end_idx_rel