feat: add rmsnorm_h2048 workloads and baseline solution

#2
definitions/rmsnorm/rmsnorm_h2048.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "rmsnorm_h2048",
3
+ "op_type": "rmsnorm",
4
+ "description": "Root Mean Square Normalization with hidden_size=2048. Captured from Qwen3-30B-A3B. Epsilon is fixed at 1e-6.",
5
+ "tags": [
6
+ "status:verified",
7
+ "model:qwen3-30b-a3b"
8
+ ],
9
+ "axes": {
10
+ "batch_size": {
11
+ "type": "var"
12
+ },
13
+ "hidden_size": {
14
+ "type": "const",
15
+ "value": 2048
16
+ }
17
+ },
18
+ "inputs": {
19
+ "hidden_states": {
20
+ "shape": [
21
+ "batch_size",
22
+ "hidden_size"
23
+ ],
24
+ "dtype": "bfloat16"
25
+ },
26
+ "weight": {
27
+ "shape": [
28
+ "hidden_size"
29
+ ],
30
+ "dtype": "bfloat16"
31
+ }
32
+ },
33
+ "outputs": {
34
+ "output": {
35
+ "shape": [
36
+ "batch_size",
37
+ "hidden_size"
38
+ ],
39
+ "dtype": "bfloat16"
40
+ }
41
+ },
42
+ "reference": "import torch\n\n@torch.no_grad()\ndef run(hidden_states, weight):\n batch_size, hidden_size = hidden_states.shape\n # Check constants\n assert hidden_size == 2048\n\n EPS = 1e-6\n\n x = hidden_states.to(torch.float32)\n inv_rms = torch.rsqrt(x.pow(2).mean(dim=-1, keepdim=True) + EPS)\n y = (x * inv_rms) * weight.to(torch.float32)\n return y.to(hidden_states.dtype)"
43
+ }
solutions/baseline/rmsnorm/rmsnorm_h2048/flashinfer_wrapper_0af255.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "flashinfer_wrapper_0af255",
3
+ "definition": "rmsnorm_h2048",
4
+ "author": "flashinfer",
5
+ "spec": {
6
+ "language": "python",
7
+ "target_hardware": [
8
+ "NVIDIA GeForce RTX 4090",
9
+ "NVIDIA A100",
10
+ "NVIDIA H20",
11
+ "NVIDIA H100",
12
+ "NVIDIA H200",
13
+ "NVIDIA B200"
14
+ ],
15
+ "entry_point": "main.py::run",
16
+ "dependencies": [
17
+ "flashinfer"
18
+ ],
19
+ "destination_passing_style": false
20
+ },
21
+ "sources": [
22
+ {
23
+ "path": "main.py",
24
+ "content": "import torch\nimport flashinfer\n\n\ndef run(hidden_states, weight):\n batch_size, hidden_size = hidden_states.shape\n \n assert hidden_size == 2048\n \n EPS = 1e-6\n \n output = flashinfer.norm.rmsnorm(hidden_states, weight, eps=EPS)\n \n return output\n"
25
+ }
26
+ ],
27
+ "description": "Solution using FlashInfer's optimized rmsnorm kernel for efficient GPU-based RMS normalization with hidden_size=2048."
28
+ }
tests/references/test_rmsnorm_h2048.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import flashinfer
2
+ import torch
3
+
4
+
5
+ @torch.no_grad()
6
+ def run(input, weight, eps, residual=None):
7
+ """
8
+ Reference implementation of RMSNorm with hidden_size=2048.
9
+
10
+ Args:
11
+ input: Input tensor of shape (B, 2048) in bfloat16
12
+ weight: Weight tensor of shape (2048,) in bfloat16
13
+ eps: Small epsilon value for numerical stability
14
+ residual: Optional residual tensor of shape (B, 2048) in bfloat16
15
+
16
+ Returns:
17
+ dict with 'output' key containing normalized output in bfloat16
18
+ """
19
+ batch_size, hidden_size = input.shape
20
+
21
+ # Check constants
22
+ assert hidden_size == 2048
23
+
24
+ # Perform computation in float32 for accuracy
25
+ orig_dtype = input.dtype
26
+ input_fp32 = input.to(torch.float32)
27
+ weight_fp32 = weight.to(torch.float32)
28
+
29
+ if residual is not None:
30
+ residual_fp32 = residual.to(torch.float32)
31
+ input_fp32 = input_fp32 + residual_fp32
32
+
33
+ # Compute RMS
34
+ variance = input_fp32.pow(2).mean(dim=-1, keepdim=True)
35
+ rstd = torch.rsqrt(variance + eps)
36
+
37
+ # Apply normalization and weight
38
+ output = (input_fp32 * rstd) * weight_fp32
39
+
40
+ # Convert back to original dtype
41
+ return {"output": output.to(orig_dtype)}
42
+
43
+
44
+ def generate_random_inputs(batch_size, with_residual=True, device="cuda"):
45
+ """Generate random inputs for testing RMSNorm with hidden_size=2048."""
46
+
47
+ hidden_size = 2048
48
+ eps = 1e-6 # Common value for this configuration
49
+
50
+ # Generate input tensor
51
+ input = torch.randn(batch_size, hidden_size, dtype=torch.bfloat16, device=device)
52
+
53
+ # Generate weight tensor
54
+ weight = torch.randn(hidden_size, dtype=torch.bfloat16, device=device)
55
+
56
+ # Generate residual if needed
57
+ residual = None
58
+ if with_residual:
59
+ residual = torch.randn(batch_size, hidden_size, dtype=torch.bfloat16, device=device)
60
+
61
+ return {"input": input, "weight": weight, "eps": eps, "residual": residual}
62
+
63
+
64
+ def test_correctness(batch_size=8, with_residual=True, atol=8e-3, rtol=1e-2):
65
+ """Test correctness of reference implementation against FlashInfer."""
66
+ print(f"\n{'='*60}")
67
+ print(f"Testing RMSNorm h2048: batch_size={batch_size}, with_residual={with_residual}")
68
+ print(f"{'='*60}")
69
+
70
+ device = "cuda" if torch.cuda.is_available() else "cpu"
71
+ if device == "cpu":
72
+ print("WARNING: CUDA not available, skipping test")
73
+ return False
74
+
75
+ # Generate inputs
76
+ inputs = generate_random_inputs(batch_size, with_residual, device)
77
+
78
+ print(f"Input shape: {inputs['input'].shape}")
79
+ print(f"Weight shape: {inputs['weight'].shape}")
80
+ print(f"Epsilon: {inputs['eps']}")
81
+ print(f"Has residual: {inputs['residual'] is not None}")
82
+
83
+ # Run reference implementation
84
+ print("\nRunning reference implementation...")
85
+ ref_output = run(
86
+ inputs["input"].clone(),
87
+ inputs["weight"],
88
+ inputs["eps"],
89
+ inputs["residual"].clone() if inputs["residual"] is not None else None,
90
+ )
91
+
92
+ # Run FlashInfer implementation
93
+ print("Running FlashInfer implementation...")
94
+ input_fi = inputs["input"].clone().contiguous()
95
+ weight_fi = inputs["weight"].contiguous()
96
+
97
+ if inputs["residual"] is not None:
98
+ residual_fi = inputs["residual"].clone().contiguous()
99
+ # Use fused kernel for residual case
100
+ flashinfer.norm.fused_add_rmsnorm(input_fi, residual_fi, weight_fi, inputs["eps"])
101
+ fi_output = {"output": input_fi}
102
+ else:
103
+ # Standard RMSNorm without residual
104
+ fi_out = flashinfer.norm.rmsnorm(input_fi, weight_fi, eps=inputs["eps"])
105
+ fi_output = {"output": fi_out}
106
+
107
+ # Compare outputs
108
+ print("\nComparing outputs...")
109
+
110
+ # Convert to float32 for comparison
111
+ ref_out_f32 = ref_output["output"].float()
112
+ fi_out_f32 = fi_output["output"].float()
113
+
114
+ # Compute errors
115
+ abs_diff = torch.abs(ref_out_f32 - fi_out_f32)
116
+ rel_diff = abs_diff / (torch.abs(fi_out_f32) + 1e-8)
117
+
118
+ max_abs_diff = abs_diff.max().item()
119
+ max_rel_diff = rel_diff.max().item()
120
+ mean_abs_diff = abs_diff.mean().item()
121
+ mean_rel_diff = rel_diff.mean().item()
122
+
123
+ print(f"\nOutput tensor comparison:")
124
+ print(f"Max absolute difference: {max_abs_diff:.6e}")
125
+ print(f"Max relative difference: {max_rel_diff:.6e}")
126
+ print(f"Mean absolute difference: {mean_abs_diff:.6e}")
127
+ print(f"Mean relative difference: {mean_rel_diff:.6e}")
128
+
129
+ # Check if outputs match within tolerance
130
+ output_close = torch.allclose(ref_out_f32, fi_out_f32, atol=atol, rtol=rtol)
131
+
132
+ if output_close:
133
+ print(f"\n✓ PASSED: Outputs match within tolerance (atol={atol}, rtol={rtol})")
134
+ else:
135
+ print(f"\n✗ FAILED: Outputs differ beyond tolerance (atol={atol}, rtol={rtol})")
136
+
137
+ return output_close
138
+
139
+
140
+ def main():
141
+ """Run comprehensive tests for RMSNorm h2048."""
142
+ print("Testing RMSNorm h2048 Reference Implementation")
143
+
144
+ # Test different configurations
145
+ test_configs = [
146
+ # (batch_size, with_residual)
147
+ (1, True), # Single batch with residual
148
+ (1, False), # Single batch without residual
149
+ (4, True), # Small batch with residual
150
+ (8, True), # Medium batch with residual
151
+ (16, True), # Large batch with residual
152
+ (32, True), # Very large batch with residual
153
+ ]
154
+
155
+ passed = 0
156
+ total = len(test_configs)
157
+
158
+ # Use bfloat16-appropriate tolerance
159
+ atol = 8e-3 # 0.8% absolute tolerance
160
+ rtol = 1e-2 # 1% relative tolerance
161
+
162
+ for batch_size, with_residual in test_configs:
163
+ try:
164
+ if test_correctness(batch_size, with_residual, atol, rtol):
165
+ passed += 1
166
+ except Exception as e:
167
+ print(f"✗ Test failed with exception: {str(e)}")
168
+ import traceback
169
+
170
+ traceback.print_exc()
171
+
172
+ print(f"\n{'='*60}")
173
+ print(f"Summary: {passed}/{total} tests passed")
174
+ print(f"{'='*60}")
175
+
176
+ if passed == total:
177
+ print("✓ All tests passed!")
178
+ else:
179
+ print(f"✗ {total - passed} tests failed")
180
+
181
+
182
+ if __name__ == "__main__":
183
+ main()
workloads/rmsnorm/rmsnorm_h2048.jsonl ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {"definition": "rmsnorm_h2048","solution": null,"workload": {"uuid": "50bbd632-cf16-4021-885b-625552ab8262","axes": {"batch_size": 6},"inputs": {"hidden_states": {"type": "random"},"weight": {"type": "random"}}},"evaluation": null}
2
+ {"definition": "rmsnorm_h2048","solution": null,"workload": {"uuid": "b8b3dda7-8959-4a11-bd6a-59863bc6fffc","axes": {"batch_size": 1},"inputs": {"hidden_states": {"type": "random"},"weight": {"type": "random"}}},"evaluation": null}
3
+ {"definition": "rmsnorm_h2048","solution": null,"workload": {"uuid": "90ca7f35-1e84-43ae-ac4b-805bc012d842","axes": {"batch_size": 34},"inputs": {"hidden_states": {"type": "random"},"weight": {"type": "random"}}},"evaluation": null}
4
+ {"definition": "rmsnorm_h2048","solution": null,"workload": {"uuid": "7fd55dbb-7371-4b46-99d1-84d1e3f16f06","axes": {"batch_size": 79},"inputs": {"hidden_states": {"type": "random"},"weight": {"type": "random"}}},"evaluation": null}
5
+ {"definition": "rmsnorm_h2048","solution": null,"workload": {"uuid": "932f75f9-e29a-4502-8794-68347b591fd5","axes": {"batch_size": 16254},"inputs": {"hidden_states": {"type": "random"},"weight": {"type": "random"}}},"evaluation": null}
6
+ {"definition": "rmsnorm_h2048","solution": null,"workload": {"uuid": "68e79061-ffd0-4733-958a-3415321da93b","axes": {"batch_size": 12383},"inputs": {"hidden_states": {"type": "random"},"weight": {"type": "random"}}},"evaluation": null}
7
+ {"definition": "rmsnorm_h2048","solution": null,"workload": {"uuid": "74280ca1-cb97-433d-b8a9-c2aec2ae560c","axes": {"batch_size": 64},"inputs": {"hidden_states": {"type": "random"},"weight": {"type": "random"}}},"evaluation": null}