Skip to content
Merged
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
17 changes: 10 additions & 7 deletions aiter/ops/mhc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2024-2026, Advanced Micro Devices, Inc. All rights reserved.

import torch
import math
from torch import Tensor

import torch
from aiter import dtypes
from torch import Tensor

from ..jit.core import compile_ops
from ..jit.utils.chip_info import get_cu_num

Expand Down Expand Up @@ -87,18 +89,19 @@ def mhc_pre(
if num_tg > meanwhile_tg * 4:
break

device = residual.device
out_pad = torch.empty(
selected_splitk, m, (hc_mult3 + 31) // 32 * 32, dtype=dtypes.fp32
selected_splitk, m, (hc_mult3 + 31) // 32 * 32, dtype=dtypes.fp32, device=device
Comment on lines +92 to +94
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a regression test that exercises mhc_pre when the global default device is CPU but inputs are explicitly on CUDA (e.g., torch.set_default_device('cpu') then create residual/fn/hc_scale/hc_base on cuda). This change fixes internal tensor allocations to follow residual.device, but current tests may still pass even if allocations accidentally fall back to the default device.

Copilot uses AI. Check for mistakes.
)
out = out_pad[:, :, :hc_mult3]
sqrsum = torch.empty(selected_splitk, m, dtype=dtypes.fp32)
sqrsum = torch.empty(selected_splitk, m, dtype=dtypes.fp32, device=device)
mhc_pre_gemm_sqrsum(out, sqrsum, residual, fn, selected_tile_k)
# out = out.sum(0)
# sqrsum = sqrsum.sum(0)

post_mix = torch.empty(m, hc_mult, 1, dtype=dtypes.fp32)
comb_mix = torch.empty(m, hc_mult, hc_mult, dtype=dtypes.fp32)
layer_input = torch.empty(m, hidden_size, dtype=dtypes.bf16)
post_mix = torch.empty(m, hc_mult, 1, dtype=dtypes.fp32, device=device)
comb_mix = torch.empty(m, hc_mult, hc_mult, dtype=dtypes.fp32, device=device)
layer_input = torch.empty(m, hidden_size, dtype=dtypes.bf16, device=device)
mhc_pre_big_fuse(
post_mix,
comb_mix,
Expand Down
Loading