[Model] add GLM-5.3-Flash support (#53906)

This commit is contained in:
Jiangyun Zhu
2026-09-03 09:40:35 -07:00
committed by GitHub
parent da8ec28268
commit 98ed0856f3
94 changed files with 17927 additions and 266 deletions
+31 -7
View File
@@ -909,6 +909,7 @@ def rocm_aiter_sparse_attn_indexer(
has_decode = layer_attn_metadata.num_decodes > 0
has_prefill = layer_attn_metadata.num_prefills > 0
num_decode_tokens = layer_attn_metadata.num_decode_tokens
topk_indices_buffer[: hidden_states.shape[0]] = -1
# during speculative decoding, k may be padded to the CUDA graph batch
# size while slot_mapping only covers actual tokens.
@@ -1251,15 +1252,31 @@ _DSV4_SPARSE_NOPE_DIM = 448
_DSV4_SPARSE_ROPE_DIM = 64
def _validate_sparse_dims(
head_dim: int,
nope_head_dim: int,
rope_head_dim: int,
op_name: str,
) -> None:
assert head_dim > 0, f"{op_name} expected a positive head_dim, got {head_dim}"
assert nope_head_dim > 0, (
f"{op_name} expected a positive NoPE dimension, got {nope_head_dim}"
)
assert rope_head_dim >= 0, (
f"{op_name} expected a non-negative RoPE dimension, got {rope_head_dim}"
)
assert head_dim == nope_head_dim + rope_head_dim, (
f"{op_name} expected head_dim={nope_head_dim + rope_head_dim}, got {head_dim}"
)
def _validate_dsv4_sparse_dims(
head_dim: int,
nope_head_dim: int,
rope_head_dim: int,
op_name: str,
) -> None:
assert head_dim == nope_head_dim + rope_head_dim, (
f"{op_name} expected head_dim={nope_head_dim + rope_head_dim}, got {head_dim}"
)
_validate_sparse_dims(head_dim, nope_head_dim, rope_head_dim, op_name)
assert (
nope_head_dim == _DSV4_SPARSE_NOPE_DIM
and rope_head_dim == _DSV4_SPARSE_ROPE_DIM
@@ -1351,6 +1368,12 @@ def _as_int32_contiguous_1d(x: torch.Tensor) -> torch.Tensor:
return x.to(torch.int32).contiguous()
@triton.jit
def _sparse_kv_row_offset(slot, stride):
# A global token slot fits in int32, but its byte/element offset may not.
return slot.to(tl.int64) * stride
@triton.jit
def _sparse_attn_prefill_ragged_kernel(
q_ptr,
@@ -1414,7 +1437,7 @@ def _sparse_attn_prefill_ragged_kernel(
kv = tl.load(
kv_ptr
+ safe_slot[:, None] * kv_stride_n
+ _sparse_kv_row_offset(safe_slot[:, None], kv_stride_n)
+ dim_offsets[None, :] * kv_stride_d,
mask=valid[:, None] & dim_mask[None, :],
other=0.0,
@@ -2573,7 +2596,7 @@ def _rocm_sparse_attn_prefill_ragged_triton(
assert indptr.numel() == num_queries + 1, (
f"expected indptr shape [{num_queries + 1}], got {indptr.shape}"
)
_validate_dsv4_sparse_dims(
_validate_sparse_dims(
head_dim,
nope_head_dim,
rope_head_dim,
@@ -3125,7 +3148,7 @@ def _rocm_sparse_attn_decode_triton(
def rocm_sparse_attn_prefill(
q: torch.Tensor,
kv: torch.Tensor,
indices: torch.Tensor,
indices: torch.Tensor | None,
topk_length: torch.Tensor | None,
scale: float,
head_dim: int,
@@ -3139,7 +3162,7 @@ def rocm_sparse_attn_prefill(
assert kv.ndim == 3 and kv.shape[1] == 1, (
f"ROCm Triton sparse prefill expects kv=[skv,1,d], got {kv.shape}"
)
_validate_dsv4_sparse_dims(
_validate_sparse_dims(
head_dim,
nope_head_dim,
rope_head_dim,
@@ -3157,6 +3180,7 @@ def rocm_sparse_attn_prefill(
rope_head_dim=rope_head_dim,
)
else:
assert indices is not None
indices_2d = indices.reshape(indices.shape[0], -1)
output_chunk = _rocm_sparse_attn_prefill_triton(
q=q,