@triton.jit
def rz_linear_backward_weight_grad_core(a_ptr, b_ptr, c_ptr, init_factor, M,
    N, K, H, stride_am, stride_ak, stride_bm, stride_bn, R7: int, R6: int,
    R5: int, R4: int, R3: int, R2: int, R1: int, R0: int, allow_tf32: tl.
    constexpr, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,
    BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE: tl.constexpr):
    """Kernel for computing the matmul C = A^T x B.
    A has shape (M, K), B has shape (M, N) and C has shape (K, N)
    """
    pid = tl.program_id(axis=0)
    num_pid_k = tl.cdiv(K, BLOCK_SIZE_K)
    num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)
    num_pid_in_group = GROUP_SIZE * num_pid_n
    group_id = pid // num_pid_in_group
    first_pid_k = group_id * GROUP_SIZE
    group_size_k = min(num_pid_k - first_pid_k, GROUP_SIZE)
    pid_k = first_pid_k + pid % group_size_k
    pid_n = pid % num_pid_in_group // group_size_k
    offs_ak = pid_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)
    offs_am = tl.arange(0, BLOCK_SIZE_M)
    a_ptrs = a_ptr + offs_ak[:, None] * stride_am + offs_am[None, :
        ] * stride_ak
    offs_bn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)
    offs_bm = tl.arange(0, BLOCK_SIZE_M)
    b_ptrs = b_ptr + offs_bm[:, None] * stride_bm + offs_bn[None, :
        ] * stride_bn
    offs_ck = pid_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)
    offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)
    a_zero = tl.zeros((BLOCK_SIZE_K, BLOCK_SIZE_M), dtype=tl.float32)
    b_zero = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)
    c = tl.zeros((BLOCK_SIZE_K, BLOCK_SIZE_N), dtype=tl.float32)
    for m in range(0, tl.cdiv(M, BLOCK_SIZE_M)):
        offs_m = m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)
        a_mask = (offs_ck[:, None] < K) & (offs_m[None, :] < M)
        b_mask = (offs_m[:, None] < M) & (offs_cn[None, :] < N)
        a = tl.load(a_ptrs, mask=a_mask, other=a_zero)
        b = tl.load(b_ptrs, mask=b_mask, other=b_zero)
        c += tl.dot(a, b, allow_tf32=allow_tf32)
        a_ptrs += BLOCK_SIZE_M * stride_ak
        b_ptrs += BLOCK_SIZE_M * stride_bm
    c_offset = c_ptr + tl.arange(0, BLOCK_SIZE_K)[:, None
        ] * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)[None, :]
    c_ptrs = c_offset + ((pid_k * R3 + pid_n * R2 + R1) % R0 * R0 + (pid_k *
        R7 + pid_n * R5 + R4) % R0) % (H - BLOCK_SIZE_K * BLOCK_SIZE_N)
    tl.atomic_add(c_ptrs, c * init_factor)
