Files
nvfp4-megamoe-kernel/tests/unit/test_p5_python_minimal.py

26 lines
907 B
Python
Raw Normal View History

2026-05-30 10:43:26 +00:00
"""Minimal multi-tile test via Python."""
import torch, sys, math
sys.path.insert(0, '/root/dsv4-nvfp4-workspace/kernel')
from dsv4.kernels.attention.fmha_multitile_op import fmha_multitile_decode_raw
torch.manual_seed(42)
hd = 64
N = 256
scale = 1.0 / math.sqrt(hd)
q = torch.randn(1, 1, 1, hd, dtype=torch.bfloat16, device='cuda').contiguous()
k = torch.randn(1, 1, N, hd, dtype=torch.bfloat16, device='cuda').contiguous()
v = torch.randn(1, 1, hd, N, dtype=torch.bfloat16, device='cuda').contiguous()
print(f'q align: {q.data_ptr() % 128}, k align: {k.data_ptr() % 128}, v align: {v.data_ptr() % 128}')
print(f'q shape: {q.shape}, k shape: {k.shape}, v shape: {v.shape}')
try:
o, lse = fmha_multitile_decode_raw(q, k, v, scale)
print(f'Output[0,0,0,:5]: {o[0,0,0,:5].float()}')
print(f'LSE: {lse[0,0,0].item():.4f}')
print('SUCCESS')
except Exception as e:
print(f'FAILED: {e}')