Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions fla/ops/common/chunk_delta_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,13 @@ def chunk_gated_delta_rule_fwd_h(
assert K <= 256, "current kernel does not support head dimension larger than 256."

if transpose_state_layout:
h = k.new_empty(B, NT, HV, V, K)
h = k.new_zeros(B, NT, HV, V, K)
final_state = k.new_zeros(N, HV, V, K, dtype=torch.float32) if output_final_state else None
else:
h = k.new_empty(B, NT, HV, K, V)
h = k.new_zeros(B, NT, HV, K, V)
final_state = k.new_zeros(N, HV, K, V, dtype=torch.float32) if output_final_state else None

v_new = torch.empty_like(u) if save_new_value else None
v_new = torch.zeros_like(u) if save_new_value else None
def grid(meta): return (triton.cdiv(V, meta['BV']), N*HV)
chunk_gated_delta_rule_fwd_kernel_h_blockdim64[grid](
k=k,
Expand Down Expand Up @@ -685,11 +685,11 @@ def chunk_gated_delta_rule_bwd_dhu(
N, NT, chunk_offsets = len(cu_seqlens) - 1, len(chunk_indices), prepare_chunk_offsets(cu_seqlens, BT)

if transpose_state_layout:
dh = q.new_empty(B, NT, HV, V, K)
dh = q.new_zeros(B, NT, HV, V, K)
else:
dh = q.new_empty(B, NT, HV, K, V)
dh0 = torch.empty_like(h0, dtype=torch.float32) if h0 is not None else None
dv2 = torch.empty_like(dv)
dh = q.new_zeros(B, NT, HV, K, V)
dh0 = torch.zeros_like(h0, dtype=torch.float32) if h0 is not None else None
dv2 = torch.zeros_like(dv)

def grid(meta): return (triton.cdiv(V, meta['BV']), N*HV)
chunk_gated_delta_rule_bwd_kernel_dhu_blockdim64[grid](
Expand Down
14 changes: 7 additions & 7 deletions fla/ops/common/chunk_o.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def chunk_fwd_o(
if scale is None:
scale = k.shape[-1] ** -0.5

o = torch.empty_like(v)
o = torch.zeros_like(v)
def grid(meta): return (triton.cdiv(V, meta['BV']), NT, B * HV)
chunk_fwd_kernel_o[grid](
q=q,
Expand Down Expand Up @@ -572,7 +572,7 @@ def chunk_bwd_dv(
if scale is None:
scale = k.shape[-1] ** -0.5

dv = torch.empty_like(do)
dv = torch.zeros_like(do)
grid = (NV, NT, B * HV)
chunk_bwd_kernel_dv[grid](
q=q,
Expand Down Expand Up @@ -624,7 +624,7 @@ def chunk_bwd_dv_local(
BV = min(max(triton.next_power_of_2(V), 16), CONST_TILING)
NT = triton.cdiv(T, BT) if cu_seqlens is None else len(chunk_indices)

dv = torch.empty_like(do)
dv = torch.zeros_like(do)
grid = (NT, B * HV)
chunk_bwd_kernel_dv_local[grid](
q=q,
Expand Down Expand Up @@ -689,10 +689,10 @@ def chunk_bwd_dqkwg(
BK = min(max(triton.next_power_of_2(K), 16), CONST_TILING)
BV = min(max(triton.next_power_of_2(V), 16), CONST_TILING)
NK = triton.cdiv(K, BK)
dq = q.new_empty(B, T, HV, K)
dk = k.new_empty(B, T, HV, K)
dg = torch.empty(NK, *g.shape, dtype=torch.float32, device=g.device) if g is not None else None
dw = torch.empty_like(w) if w is not None else None
dq = q.new_zeros(B, T, HV, K)
dk = k.new_zeros(B, T, HV, K)
dg = torch.zeros(NK, *g.shape, dtype=torch.float32, device=g.device) if g is not None else None
dw = torch.zeros_like(w) if w is not None else None

grid = (NK, NT, B * HV)
chunk_bwd_kernel_dqkwg[grid](
Expand Down
12 changes: 6 additions & 6 deletions fla/ops/gated_delta_rule/wy_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ def recompute_w_u_fwd(
chunk_indices = prepare_chunk_indices(cu_seqlens, BT)
NT = triton.cdiv(T, BT) if cu_seqlens is None else len(chunk_indices)

w = k.new_empty(B, T, HV, K)
u = torch.empty_like(v)
w = k.new_zeros(B, T, HV, K)
u = torch.zeros_like(v)
recompute_w_u_fwd_kernel[(NT, B*HV)](
k=k,
v=v,
Expand Down Expand Up @@ -286,10 +286,10 @@ def prepare_wy_repr_bwd(
BK = min(max(triton.next_power_of_2(K), 16), CONST_TILING)
BV = min(max(triton.next_power_of_2(V), 16), CONST_TILING)

dk = k.new_empty(B, T, HV, K)
dv = torch.empty_like(v)
dg = torch.empty_like(g) if g is not None else None
db = torch.empty_like(beta)
dk = k.new_zeros(B, T, HV, K)
dv = torch.zeros_like(v)
dg = torch.zeros_like(g) if g is not None else None
db = torch.zeros_like(beta)
prepare_wy_repr_bwd_kernel[(NT, B * HV)](
k=k,
v=v,
Expand Down
Loading