Skip to content

Commit 3dd0ba4

Browse files
committed
add llama-bench_1B_swiglu benchmark
1 parent 673c0a2 commit 3dd0ba4

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# RUN: %PYTHON %S/kernel_bench.py --input %s --dump-kernel xegpu-wg | FileCheck %s --implicit-check-not=memref.alloc --implicit-check-not=memref.copy --implicit-check-not=gpu.alloc
2+
# REQUIRES: torch, torch_mlir
3+
4+
"""Llama 3.2 1B bias-free SwiGLU FFN, without normalization or residual.
5+
6+
The three GEMM kernels materialize activated gate and gated activations.
7+
SiLU is fused into gate projection; the multiply into up projection's
8+
epilogue. Down projection consumes the gated tensor without recomputing it.
9+
"""
10+
11+
import torch
12+
import torch.nn as nn
13+
import torch.nn.functional as F
14+
15+
16+
batch_size = 4
17+
n_ctx = 512
18+
dim = 2048
19+
hidden_dim = 8192
20+
21+
22+
class Model(nn.Module):
23+
def __init__(self):
24+
super().__init__()
25+
self.gate_proj = nn.Linear(dim, hidden_dim, bias=False)
26+
self.up_proj = nn.Linear(dim, hidden_dim, bias=False)
27+
self.down_proj = nn.Linear(hidden_dim, dim, bias=False)
28+
29+
def forward(self, x: torch.Tensor) -> torch.Tensor:
30+
return self.down_proj(F.silu(self.gate_proj(x)) * self.up_proj(x))
31+
32+
33+
def get_inputs():
34+
return [torch.randn(batch_size, n_ctx, dim)]
35+
36+
37+
def get_init_inputs():
38+
return []
39+
40+
41+
# CHECK-COUNT-2: gpu.alloc
42+
# CHECK-NOT: gpu.alloc
43+
# CHECK: gpu.func @main_kernel
44+
# CHECK: xegpu.dpas
45+
# CHECK: math.exp
46+
# CHECK: xegpu.store_nd
47+
# CHECK: gpu.func @main_kernel
48+
# CHECK: xegpu.dpas
49+
# CHECK: arith.mulf
50+
# CHECK: xegpu.store_nd
51+
# CHECK: gpu.func @main_kernel
52+
# CHECK: xegpu.dpas
53+
# CHECK: xegpu.store_nd
54+
# CHECK-NOT: gpu.func

0 commit comments

Comments
 (0)