[Hardware] Replace torch.cuda.synchronize() api with torch.accelerator.synchronize (#36085)

Signed-off-by: Kunshang Ji <kunshang.ji@intel.com>
This commit is contained in:
Kunshang Ji
2026-03-05 10:36:39 +00:00
committed by GitHub
parent 0bfa229bf1
commit 66a2209645
59 changed files with 158 additions and 161 deletions
@@ -165,7 +165,7 @@ def test_merge_attn_states(
suffix_lse_torch,
output_lse_torch,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
for _ in range(repeat_times):
start.record()
@@ -178,7 +178,7 @@ def test_merge_attn_states(
output_lse_torch,
)
end.record()
torch.cuda.synchronize()
torch.accelerator.synchronize()
total_time_torch_kernel += start.elapsed_time(end)
avg_time_torch_kernel = total_time_torch_kernel / repeat_times
@@ -200,7 +200,7 @@ def test_merge_attn_states(
suffix_lse,
output_lse_ref_triton,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
for _ in range(repeat_times):
start.record()
@@ -213,7 +213,7 @@ def test_merge_attn_states(
output_lse_ref_triton,
)
end.record()
torch.cuda.synchronize()
torch.accelerator.synchronize()
total_time_triton_kernel += start.elapsed_time(end)
avg_time_triton_kernel = total_time_triton_kernel / repeat_times
@@ -232,7 +232,7 @@ def test_merge_attn_states(
suffix_lse,
output_lse_cuda,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
for _ in range(repeat_times):
start.record()
@@ -245,7 +245,7 @@ def test_merge_attn_states(
output_lse_cuda,
)
end.record()
torch.cuda.synchronize()
torch.accelerator.synchronize()
total_time_cuda_kernel += start.elapsed_time(end)
avg_time_cuda_kernel = total_time_cuda_kernel / repeat_times
@@ -239,7 +239,7 @@ def test_contexted_kv_attention(
v_scale,
sliding_window=sliding_window,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
start_time = time.time()
op(
query,
@@ -258,7 +258,7 @@ def test_contexted_kv_attention(
v_scale,
sliding_window=sliding_window,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
end_time = time.time()
print(f"triton Time: {(end_time - start_time) * 1000:.2f} ms")
@@ -298,7 +298,7 @@ def test_contexted_kv_attention(
dropout_p=0.0,
scale=scale,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
start_time = time.time()
output_ref = F.scaled_dot_product_attention(
query_sdpa,
@@ -308,7 +308,7 @@ def test_contexted_kv_attention(
dropout_p=0.0,
scale=scale,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
end_time = time.time()
print(f"PyTorch SDPA Time: {(end_time - start_time) * 1000:.2f} ms")
@@ -482,7 +482,7 @@ def test_contexted_kv_attention_alibi(
v_scale,
alibi_slopes=alibi_slopes,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
start_time = time.time()
op(
query,
@@ -501,7 +501,7 @@ def test_contexted_kv_attention_alibi(
v_scale,
alibi_slopes=alibi_slopes,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
end_time = time.time()
print(f"triton Time: {(end_time - start_time) * 1000:.2f} ms")
scale = float(1.0 / (head_size**0.5))
@@ -517,7 +517,7 @@ def test_contexted_kv_attention_alibi(
output_ref = torch.empty_like(output)
torch.cuda.synchronize()
torch.accelerator.synchronize()
start_time = time.time()
query_start = 0
@@ -572,7 +572,7 @@ def test_contexted_kv_attention_alibi(
query_start = query_end
key_start = key_end
torch.cuda.synchronize()
torch.accelerator.synchronize()
end_time = time.time()
print(f"PyTorch SDPA Time: {(end_time - start_time) * 1000:.2f} ms")
atol = 1e-3 if "fp8" in kv_cache_dtype else 1e-6
+1 -1
View File
@@ -127,7 +127,7 @@ def test_fused_rms_norm_quant(
out_quant, x_unfused.contiguous(), quant_scale_t
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
torch.testing.assert_close(residual_fused, residual, atol=1e-2, rtol=1e-2)
opcheck(
torch.ops._C.fused_add_rms_norm_static_fp8_quant,
@@ -34,7 +34,7 @@ def do_profile(
record_shapes=True,
) as tprof:
fn(**fn_kwargs)
torch.cuda.synchronize(torch.cuda.current_device())
torch.accelerator.synchronize(torch.cuda.current_device())
# TODO (varun): Add a descriptive trace file name
tprof.export_chrome_trace(
+2 -2
View File
@@ -318,8 +318,8 @@ def test_w8a8_block_fp8_deep_gemm_fused_moe(M, N, K, E, topk, seed, monkeypatch)
out = deep_gemm_moe_fp8_fn(
a, w1, w2, w1_s, w2_s, topk_weights, topk_ids
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
graph.replay()
torch.cuda.synchronize()
torch.accelerator.synchronize()
torch.testing.assert_close(out, ref_out, atol=0.035, rtol=0.035)
+2 -2
View File
@@ -399,9 +399,9 @@ def test_cutlass_moe_8_bit_cuda_graph(
mt, topk_weights, topk_ids, per_act_token, per_out_ch
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
graph.replay()
torch.cuda.synchronize()
torch.accelerator.synchronize()
torch.testing.assert_close(triton_output, cutlass_output, atol=9e-2, rtol=1e-2)
+3 -3
View File
@@ -272,9 +272,9 @@ def run_moe_test(
global_num_experts=global_num_experts,
expert_map=expert_map,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
graph.replay()
torch.cuda.synchronize()
torch.accelerator.synchronize()
torch.testing.assert_close(test_output, baseline_output, atol=atol, rtol=rtol)
@@ -768,7 +768,7 @@ def test_mixtral_moe(
F.pad(vllm_moe.experts.w2_weight, (0, 128), "constant", 0)[..., 0:-128],
requires_grad=False,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
torch.accelerator.empty_cache()
# FIXME (zyongye) fix this after we move self.kernel
@@ -122,7 +122,7 @@ def test_gptq_allspark_gemm_ampere(mnk_factors, group_size, has_zp, dtype):
)
output_ref = torch.matmul(input, w_ref)
torch.cuda.synchronize()
torch.accelerator.synchronize()
max_diff = compute_max_diff(output, output_ref)
assert max_diff < 0.04
@@ -269,7 +269,7 @@ def test_cutlass_w4a8_moe_mm_end_to_end(shape, random_zero):
setup.c_strides,
setup.group_scale_strides,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
out_ref = compute_moe_reference_output(setup)
torch.testing.assert_close(setup.out, out_ref, rtol=1e-2, atol=1e-2)
@@ -260,7 +260,7 @@ def test_gptq_marlin_repack(
marlin_q_w_2 = ops.gptq_marlin_repack(
q_w_gptq, sort_indices, size_k, size_n, quant_type.size_bits, is_a_8bit
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
torch.testing.assert_close(marlin_q_w_1, marlin_q_w_2)
@@ -308,7 +308,7 @@ def test_awq_marlin_repack(k_chunk, n_chunk, quant_type, is_a_8bit, nk_factors):
marlin_q_w_2 = ops.awq_marlin_repack(
q_w_awq, size_k, size_n, quant_type.size_bits, is_a_8bit
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
torch.testing.assert_close(marlin_q_w_1, marlin_q_w_2)
@@ -564,7 +564,7 @@ def test_marlin_gemm_subset_input():
)
output_ref = torch.matmul(a_input, w_ref)
torch.cuda.synchronize()
torch.accelerator.synchronize()
max_diff = compute_max_diff(output, output_ref)
@@ -613,7 +613,7 @@ def test_marlin_gemm_with_bias(size_m):
)
output_ref = torch.matmul(a_input, w_ref) + b_bias.view(1, -1)
torch.cuda.synchronize()
torch.accelerator.synchronize()
max_diff = compute_max_diff(output, output_ref)
+1 -1
View File
@@ -57,7 +57,7 @@ def test_gather_cache_oob():
seq_starts,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
assert True
+1 -1
View File
@@ -219,7 +219,7 @@ def _run_top_k_per_row_decode_test(
top_k,
)
torch.cuda.synchronize()
torch.accelerator.synchronize()
# Run reference implementation
torch_indices = torch.empty((num_rows, top_k), dtype=torch.int32, device="cuda")