[sp] Make attention-TP sequence sharding a per-forward batch property (#37546)
Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Lianmin Zheng <lianminzheng@gmail.com>
This commit is contained in:
co-authored by
Claude
Lianmin Zheng
parent
67248e04b4
commit
44c786679f
@@ -1629,7 +1629,7 @@ def run_dsa_forward(
|
||||
input_hidden = inputs["input_hidden"]
|
||||
# `input_hidden` may have trailing padding for split-op static-token
|
||||
# contracts; project only the live token rows for QKV. The kernel
|
||||
# respects `num_token_non_padded_cpu` via the metadata.
|
||||
# respects `global_num_token_non_padded_cpu` via the metadata.
|
||||
live_input_hidden = input_hidden[: case.num_input_tokens]
|
||||
input_parts = _split_by_lens(live_input_hidden, case.input_lens)
|
||||
kv_hidden = torch.cat(
|
||||
@@ -1668,7 +1668,7 @@ def expected_dsa_output_from_inputs(
|
||||
def dsa_attention_layers(fixture: DSAAttentionFixture) -> list:
|
||||
"""Return the RadixAttention layers the backend forwards through. The
|
||||
split-op runner uses this to install per-layer
|
||||
`num_token_non_padded_cpu` metadata before forward."""
|
||||
`global_num_token_non_padded_cpu` metadata before forward."""
|
||||
return [fixture.actual_module.attn]
|
||||
|
||||
|
||||
|
||||
@@ -1055,7 +1055,7 @@ def make_lightning_token_padded_inputs(
|
||||
def lightning_attention_layers(fixture: LightningAttentionFixture) -> list:
|
||||
"""Return the RadixAttention layers the backend forwards through. The
|
||||
split-op runner uses this list to install per-layer
|
||||
`num_token_non_padded_cpu` metadata before forward."""
|
||||
`global_num_token_non_padded_cpu` metadata before forward."""
|
||||
return [fixture.actual_module.attn]
|
||||
|
||||
|
||||
|
||||
@@ -223,13 +223,13 @@ def _make_static_forward_batch(raw_batch, static_num_tokens: int, device: str):
|
||||
dim=0,
|
||||
)
|
||||
|
||||
raw_batch.num_token_non_padded_cpu = raw_num_tokens
|
||||
raw_batch.global_num_token_non_padded_cpu = raw_num_tokens
|
||||
return replace(
|
||||
raw_batch,
|
||||
input_ids=input_ids,
|
||||
positions=positions,
|
||||
out_cache_loc=out_cache_loc,
|
||||
num_token_non_padded_cpu=raw_num_tokens,
|
||||
global_num_token_non_padded_cpu=raw_num_tokens,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ def make_forward_batch(
|
||||
input_ids: Optional[torch.Tensor] = None,
|
||||
positions: Optional[torch.Tensor] = None,
|
||||
out_cache_loc: Optional[torch.Tensor] = None,
|
||||
num_token_non_padded_cpu: Optional[int] = None,
|
||||
global_num_token_non_padded_cpu: Optional[int] = None,
|
||||
) -> SimpleNamespace:
|
||||
seq_lens_default = list(seq_lens_list[:bs])
|
||||
if req_pool_indices is None:
|
||||
@@ -216,7 +216,7 @@ def make_forward_batch(
|
||||
input_ids=input_ids,
|
||||
positions=positions,
|
||||
out_cache_loc=out_cache_loc,
|
||||
num_token_non_padded_cpu=num_token_non_padded_cpu,
|
||||
global_num_token_non_padded_cpu=global_num_token_non_padded_cpu,
|
||||
req_all_ids_flat=None,
|
||||
req_all_ids_lens=None,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user