Skip to content

Commit b8add97

Browse files
Xiao YUXiao YU
authored andcommitted
Update unit test fp16 vs fp8 output verify logic
1 parent 1775084 commit b8add97

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

tests/kernels/attention/test_paged_attention.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,39 @@ def run_cuda_benchmark(num_iters: int, profile: bool = False) -> float:
150150
# Warmup.
151151
print("Verification...")
152152
run_benchmark = run_cuda_benchmark
153+
import copy
153154

154155
key_cache, value_cache = key_cache_fp8, value_cache_fp8
155156
kv_cache_dtype = "fp8"
156157
print("\nkey fp8= ", key_cache[0,0,0,:,:])
157158
run_benchmark(num_iters=1, profile=False)
158159
print("\nresult fp8= ", output.shape, output[0,0,:])
159-
fp8_output = output
160-
160+
fp8_output = copy.deepcopy(output)
161+
161162
key_cache, value_cache = key_cache_f16, value_cache_f16
162163
kv_cache_dtype = "auto"
163164
print("\nkey f16= ", key_cache_f16[0,0,0,:,:])
164165
run_benchmark(num_iters=1, profile=False)
165166
print("\nresult f16= ", output.shape, output[0,0,:])
166-
f16_output = output
167+
f16_output = copy.deepcopy(output)
167168

169+
sel = torch.abs(f16_output)>1e-3 # min precision for fp8
168170
diff = f16_output - fp8_output
169-
print("output mean(fp16, fp8) = ", torch.mean(f16_output), torch.mean(fp8_output))
170-
print("diff(fp16, fp8) mean, std = ", torch.mean(diff), torch.std(diff))
171171

172+
diff = 100*torch.abs(diff[sel]/f16_output[sel])
173+
loc = diff>10 # different > 10%
174+
175+
print("Diff = 100*(fp16-fp8)/fp16: ",
176+
"\nmean = ", torch.mean(diff).item(),
177+
"\nmax = ", torch.max(diff).item(),
178+
"\nmdeian = ", torch.median(diff).item(),
179+
"\nstd = ", torch.std(diff).item())
180+
181+
print("Outlier: ", loc.shape, torch.sum(loc).item(),
182+
"\ndiff = ", diff[loc==True],
183+
"\nfp16 = ", f16_output[sel][loc==True],
184+
"\nfp8 = ", fp8_output[sel][loc==True],
185+
"\nquery= ", query[sel][loc==True])
172186

173187
if __name__ == "__main__":
174188
logger.warning(

0 commit comments

Comments
 (0)