Skip to content

Commit a759efe

Browse files
authored
fix: mark fused rope token tensors dynamic (#458)
1 parent f85bd3f commit a759efe

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

kernels/fused_rope_cache_kernel.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,15 @@ def pack_fp8(vals):
431431
v_elem = vector.extract(v_e, static_position=[vi], dynamic_position=[])
432432
buffer_ops.buffer_store(v_elem, vc_rsrc, vc_nf_off)
433433

434+
def _mark_token_layout_dynamic(tensor):
435+
if hasattr(tensor, "mark_layout_dynamic"):
436+
shape = getattr(tensor, "_orig_shape", None)
437+
leading_dim = len(shape) - 1 if shape is not None else -1
438+
return tensor.mark_layout_dynamic(leading_dim=leading_dim)
439+
return flyc.from_dlpack(tensor).mark_layout_dynamic(leading_dim=tensor.ndim - 1)
440+
434441
@flyc.jit
435-
def launch_fused_rope_cache(
442+
def _jit_launch_fused_rope_cache(
436443
Q: fx.Tensor,
437444
K: fx.Tensor,
438445
V: fx.Tensor,
@@ -459,4 +466,39 @@ def launch_fused_rope_cache(
459466
stream=stream,
460467
)
461468

469+
def launch_fused_rope_cache(
470+
Q,
471+
K,
472+
V,
473+
Positions,
474+
CosCache,
475+
SinCache,
476+
SlotMapping,
477+
KeyCache,
478+
ValueCache,
479+
Q_out,
480+
K_out,
481+
num_tokens,
482+
KScale,
483+
VScale,
484+
stream=fx.Stream(None),
485+
):
486+
return _jit_launch_fused_rope_cache(
487+
_mark_token_layout_dynamic(Q),
488+
_mark_token_layout_dynamic(K),
489+
_mark_token_layout_dynamic(V),
490+
_mark_token_layout_dynamic(Positions),
491+
CosCache,
492+
SinCache,
493+
_mark_token_layout_dynamic(SlotMapping),
494+
KeyCache,
495+
ValueCache,
496+
_mark_token_layout_dynamic(Q_out),
497+
_mark_token_layout_dynamic(K_out),
498+
num_tokens,
499+
KScale,
500+
VScale,
501+
stream=stream,
502+
)
503+
462504
return launch_fused_rope_cache

kernels/topk_gating_softmax_kernel.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ def topk_gating_softmax_kernel(
122122
bid = fx.block_idx.x
123123
tid = fx.thread_idx.x
124124

125-
elem_type = dtype_to_elem_type(dtype_str)
125+
elem_type = dtype_to_elem_type(dtype_str).ir_type
126126
compute_type = T.f32
127+
register_addr_space = int(fx.AddressSpace.Register)
127128

128129
fm_fast = arith.FastMathFlags.fast
129130

@@ -210,7 +211,7 @@ def group_reduce_argmax(val, idx):
210211
atom_reg_ty_in = fx.MemRefType.get(
211212
elem_type,
212213
fx.LayoutType.get(ELEMS_PER_ATOM, 1),
213-
fx.AddressSpace.Register,
214+
register_addr_space,
214215
)
215216
atom_reg_lay_in = fx.make_layout(ELEMS_PER_ATOM, 1)
216217

@@ -219,7 +220,7 @@ def group_reduce_argmax(val, idx):
219220
# near `_store_scalar_i32` below).
220221
copy_atom_f32 = fx.make_copy_atom(fx.rocdl.BufferCopy32b(), 32)
221222
scalar_reg_ty_f32 = fx.MemRefType.get(
222-
T.f32, fx.LayoutType.get(1, 1), fx.AddressSpace.Register
223+
T.f32, fx.LayoutType.get(1, 1), register_addr_space
223224
)
224225
scalar_reg_lay = fx.make_layout(1, 1)
225226

0 commit comments

Comments
 (0)