@@ -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 ("\n key fp8= " , key_cache [0 ,0 ,0 ,:,:])
157158 run_benchmark (num_iters = 1 , profile = False )
158159 print ("\n result 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 ("\n key f16= " , key_cache_f16 [0 ,0 ,0 ,:,:])
164165 run_benchmark (num_iters = 1 , profile = False )
165166 print ("\n result 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+ "\n mean = " , torch .mean (diff ).item (),
177+ "\n max = " , torch .max (diff ).item (),
178+ "\n mdeian = " , torch .median (diff ).item (),
179+ "\n std = " , torch .std (diff ).item ())
180+
181+ print ("Outlier: " , loc .shape , torch .sum (loc ).item (),
182+ "\n diff = " , diff [loc == True ],
183+ "\n fp16 = " , f16_output [sel ][loc == True ],
184+ "\n fp8 = " , fp8_output [sel ][loc == True ],
185+ "\n query= " , query [sel ][loc == True ])
172186
173187if __name__ == "__main__" :
174188 logger .warning (
0 commit comments