Commit 81e426c4 authored by zhangyue's avatar zhangyue
Browse files

issue/207: add sync in every test script

parent 9faf1ffc
...@@ -101,6 +101,7 @@ def test( ...@@ -101,6 +101,7 @@ def test(
v_stride=None, v_stride=None,
k_cache_stride=None, k_cache_stride=None,
v_cache_stride=None, v_cache_stride=None,
sync=None
): ):
print( print(
f"Testing Attention on {torch_device} with n_q_head:{n_q_head} n_kv_head:{n_kv_head} seq_len:{seq_len} head_dim:{head_dim} pos:{pos} " f"Testing Attention on {torch_device} with n_q_head:{n_q_head} n_kv_head:{n_kv_head} seq_len:{seq_len} head_dim:{head_dim} pos:{pos} "
...@@ -140,6 +141,9 @@ def test( ...@@ -140,6 +141,9 @@ def test(
k_cache_tensor = to_tensor(k_cache, lib) k_cache_tensor = to_tensor(k_cache, lib)
v_cache_tensor = to_tensor(v_cache, lib) v_cache_tensor = to_tensor(v_cache, lib)
if sync is not None:
sync()
descriptor = infiniopAttentionDescriptor_t() descriptor = infiniopAttentionDescriptor_t()
check_error( check_error(
lib.infiniopCreateAttentionDescriptor( lib.infiniopCreateAttentionDescriptor(
......
...@@ -88,6 +88,7 @@ def test( ...@@ -88,6 +88,7 @@ def test(
padding, padding,
strides, strides,
tensor_dtype=torch.float16, tensor_dtype=torch.float16,
sync=None
): ):
print( print(
f"Testing AvgPool on {torch_device} with x_shape:{x_shape} kernel_shape:{k_shape} padding:{padding} strides:{strides} dtype:{tensor_dtype}" f"Testing AvgPool on {torch_device} with x_shape:{x_shape} kernel_shape:{k_shape} padding:{padding} strides:{strides} dtype:{tensor_dtype}"
...@@ -109,6 +110,10 @@ def test( ...@@ -109,6 +110,10 @@ def test(
x_tensor = to_tensor(x, lib) x_tensor = to_tensor(x, lib)
y_tensor = to_tensor(y, lib) y_tensor = to_tensor(y, lib)
if sync is not None:
sync()
descriptor = infiniopAvgPoolDescriptor_t() descriptor = infiniopAvgPoolDescriptor_t()
check_error( check_error(
......
...@@ -87,6 +87,7 @@ def test( ...@@ -87,6 +87,7 @@ def test(
y_stride=None, y_stride=None,
inplace=Inplace.OUT_OF_PLACE, inplace=Inplace.OUT_OF_PLACE,
dtype=torch.float16, dtype=torch.float16,
sync=None
): ):
print( print(
f"Testing CausalSoftmax on {torch_device} with shape:{shape} x_stride:{x_stride} y_stride:{y_stride} dtype:{dtype} inplace:{inplace}" f"Testing CausalSoftmax on {torch_device} with shape:{shape} x_stride:{x_stride} y_stride:{y_stride} dtype:{dtype} inplace:{inplace}"
...@@ -108,6 +109,9 @@ def test( ...@@ -108,6 +109,9 @@ def test(
y = rearrange_if_needed(y, y_stride) y = rearrange_if_needed(y, y_stride)
y_tensor = to_tensor(y, lib) y_tensor = to_tensor(y, lib)
if sync is not None:
sync()
descriptor = infiniopCausalSoftmaxDescriptor_t() descriptor = infiniopCausalSoftmaxDescriptor_t()
check_error( check_error(
lib.infiniopCreateCausalSoftmaxDescriptor( lib.infiniopCreateCausalSoftmaxDescriptor(
......
...@@ -95,6 +95,7 @@ def test( ...@@ -95,6 +95,7 @@ def test(
dilations, dilations,
tensor_stride=None, tensor_stride=None,
tensor_dtype=torch.float16, tensor_dtype=torch.float16,
sync=None
): ):
assert len(pads) == len(strides) == len(dilations) assert len(pads) == len(strides) == len(dilations)
print( print(
...@@ -118,8 +119,11 @@ def test( ...@@ -118,8 +119,11 @@ def test(
x_tensor = to_tensor(x, lib) x_tensor = to_tensor(x, lib)
w_tensor = to_tensor(w, lib) w_tensor = to_tensor(w, lib)
y_tensor = to_tensor(y, lib) y_tensor = to_tensor(y, lib)
descriptor = infiniopConvDescriptor_t()
if sync is not None:
sync()
descriptor = infiniopConvDescriptor_t()
check_error( check_error(
lib.infiniopCreateConvDescriptor( lib.infiniopCreateConvDescriptor(
handle, handle,
......
...@@ -52,6 +52,7 @@ def test( ...@@ -52,6 +52,7 @@ def test(
y_stride=None, y_stride=None,
x_stride=None, x_stride=None,
tensor_dtype=torch.float16, tensor_dtype=torch.float16,
sync=None
): ):
print( print(
f"Testing Expand on {torch_device} with x_shape:{x_shape} y_shape:{y_shape} x_stride:{x_stride} y_stride:{y_stride} dtype:{tensor_dtype}" f"Testing Expand on {torch_device} with x_shape:{x_shape} y_shape:{y_shape} x_stride:{x_stride} y_stride:{y_stride} dtype:{tensor_dtype}"
...@@ -76,8 +77,11 @@ def test( ...@@ -76,8 +77,11 @@ def test(
x_tensor = to_tensor(x, lib) x_tensor = to_tensor(x, lib)
y_tensor = to_tensor(y, lib) y_tensor = to_tensor(y, lib)
descriptor = infiniopExpandDescriptor_t()
if sync is not None:
sync()
descriptor = infiniopExpandDescriptor_t()
check_error( check_error(
lib.infiniopCreateExpandDescriptor( lib.infiniopCreateExpandDescriptor(
handle, handle,
......
...@@ -51,6 +51,7 @@ def test( ...@@ -51,6 +51,7 @@ def test(
torch_device, torch_device,
x_shape, x_shape,
tensor_dtype=torch.float16, tensor_dtype=torch.float16,
sync=None
): ):
print( print(
f"Testing GlobalAvgPool on {torch_device} with input tensor_shape: {x_shape} dtype: {tensor_dtype}" f"Testing GlobalAvgPool on {torch_device} with input tensor_shape: {x_shape} dtype: {tensor_dtype}"
...@@ -70,8 +71,11 @@ def test( ...@@ -70,8 +71,11 @@ def test(
x_tensor = to_tensor(x, lib) x_tensor = to_tensor(x, lib)
y_tensor = to_tensor(y, lib) y_tensor = to_tensor(y, lib)
descriptor = infiniopGlobalAvgPoolDescriptor_t()
if sync is not None:
sync()
descriptor = infiniopGlobalAvgPoolDescriptor_t()
check_error( check_error(
lib.infiniopCreateGlobalAvgPoolDescriptor( lib.infiniopCreateGlobalAvgPoolDescriptor(
handle, handle,
......
...@@ -83,6 +83,7 @@ def test( ...@@ -83,6 +83,7 @@ def test(
padding, padding,
strides, strides,
tensor_dtype=torch.float16, tensor_dtype=torch.float16,
sync=None
): ):
print( print(
f"Testing MaxPool on {torch_device} with x_shape:{x_shape} kernel_shape:{k_shape} padding:{padding} strides:{strides} dtype:{tensor_dtype}" f"Testing MaxPool on {torch_device} with x_shape:{x_shape} kernel_shape:{k_shape} padding:{padding} strides:{strides} dtype:{tensor_dtype}"
...@@ -104,8 +105,11 @@ def test( ...@@ -104,8 +105,11 @@ def test(
x_tensor = to_tensor(x, lib) x_tensor = to_tensor(x, lib)
y_tensor = to_tensor(y, lib) y_tensor = to_tensor(y, lib)
descriptor = infiniopMaxPoolDescriptor_t()
if sync is not None:
sync()
descriptor = infiniopMaxPoolDescriptor_t()
check_error( check_error(
lib.infiniopCreateMaxPoolDescriptor( lib.infiniopCreateMaxPoolDescriptor(
handle, handle,
......
...@@ -65,6 +65,7 @@ def test( ...@@ -65,6 +65,7 @@ def test(
y_stride=None, y_stride=None,
w12_stride=None, w12_stride=None,
w3_stride=None, w3_stride=None,
sync=None
): ):
print( print(
f"Testing MLP on {torch_device} with num_tokens:{num_tokens} hidden_size:{hidden_size} intermediate_size:{intermediate_size}" f"Testing MLP on {torch_device} with num_tokens:{num_tokens} hidden_size:{hidden_size} intermediate_size:{intermediate_size}"
...@@ -97,6 +98,10 @@ def test( ...@@ -97,6 +98,10 @@ def test(
x_tensor = to_tensor(x, lib) x_tensor = to_tensor(x, lib)
w12_tensor = to_tensor(w12, lib) w12_tensor = to_tensor(w12, lib)
w3_tensor = to_tensor(w3, lib) w3_tensor = to_tensor(w3, lib)
if sync is not None:
sync()
descriptor = infiniopMLPDescriptor_t() descriptor = infiniopMLPDescriptor_t()
check_error( check_error(
lib.infiniopCreateMLPDescriptor( lib.infiniopCreateMLPDescriptor(
......
...@@ -103,6 +103,7 @@ def test( ...@@ -103,6 +103,7 @@ def test(
topk, topk,
temperature, temperature,
dtype=torch.float16, dtype=torch.float16,
sync=None
): ):
print( print(
f"Testing RandomSample on {torch_device} with voc:{voc} random_val:{random_val} topp:{topp} topk:{topk} temperature:{temperature} dtype:{dtype}" f"Testing RandomSample on {torch_device} with voc:{voc} random_val:{random_val} topp:{topp} topk:{topk} temperature:{temperature} dtype:{dtype}"
...@@ -122,6 +123,9 @@ def test( ...@@ -122,6 +123,9 @@ def test(
indices_tensor.descriptor.contents.dt = InfiniDtype.U64 # treat int64 as uint64 indices_tensor.descriptor.contents.dt = InfiniDtype.U64 # treat int64 as uint64
if sync is not None:
sync()
descriptor = infiniopRandomSampleDescriptor_t() descriptor = infiniopRandomSampleDescriptor_t()
check_error( check_error(
lib.infiniopCreateRandomSampleDescriptor( lib.infiniopCreateRandomSampleDescriptor(
......
...@@ -131,6 +131,7 @@ def test( ...@@ -131,6 +131,7 @@ def test(
x_stride, x_stride,
y_stride, y_stride,
dtype=torch.float16, dtype=torch.float16,
sync=None
): ):
print( print(
f"Testing Rerrange on {torch_device} with shape:{shape} x_stride:{x_stride} y_stride:{y_stride} dtype:{dtype}" f"Testing Rerrange on {torch_device} with shape:{shape} x_stride:{x_stride} y_stride:{y_stride} dtype:{dtype}"
...@@ -146,6 +147,9 @@ def test( ...@@ -146,6 +147,9 @@ def test(
x_tensor, y_tensor = [to_tensor(tensor, lib) for tensor in [x, y]] x_tensor, y_tensor = [to_tensor(tensor, lib) for tensor in [x, y]]
if sync is not None:
sync()
descriptor = infiniopRearrangeDescriptor_t() descriptor = infiniopRearrangeDescriptor_t()
check_error( check_error(
lib.infiniopCreateRearrangeDescriptor( lib.infiniopCreateRearrangeDescriptor(
......
...@@ -55,6 +55,7 @@ def test( ...@@ -55,6 +55,7 @@ def test(
tensor_shape, tensor_shape,
tensor_dtype=torch.float16, tensor_dtype=torch.float16,
inplace=Inplace.OUT_OF_PLACE, inplace=Inplace.OUT_OF_PLACE,
sync=None
): ):
print( print(
f"Testing Relu on {torch_device} with tensor_shape:{tensor_shape} dtype:{tensor_dtype} inplace: {inplace.name}" f"Testing Relu on {torch_device} with tensor_shape:{tensor_shape} dtype:{tensor_dtype} inplace: {inplace.name}"
...@@ -78,8 +79,11 @@ def test( ...@@ -78,8 +79,11 @@ def test(
x_tensor = to_tensor(x, lib) x_tensor = to_tensor(x, lib)
y_tensor = to_tensor(y, lib) if inplace == Inplace.OUT_OF_PLACE else x_tensor y_tensor = to_tensor(y, lib) if inplace == Inplace.OUT_OF_PLACE else x_tensor
descriptor = infiniopReluDescriptor_t()
if sync is not None:
sync()
descriptor = infiniopReluDescriptor_t()
check_error( check_error(
lib.infiniopCreateReluDescriptor( lib.infiniopCreateReluDescriptor(
handle, handle,
......
...@@ -117,6 +117,7 @@ def test( ...@@ -117,6 +117,7 @@ def test(
y_strides=None, y_strides=None,
inplace=Inplace.OUT_OF_PLACE, inplace=Inplace.OUT_OF_PLACE,
dtype=torch.float32, dtype=torch.float32,
sync=None
): ):
if inplace == Inplace.INPLACE_X: if inplace == Inplace.INPLACE_X:
y_strides = x_strides y_strides = x_strides
...@@ -147,8 +148,8 @@ def test( ...@@ -147,8 +148,8 @@ def test(
else: else:
y_tensor = to_tensor(y, lib) y_tensor = to_tensor(y, lib)
if torch_device == "npu": if sync is not None:
synchronize_device(torch_device) sync()
check_error( check_error(
lib.infiniopCreateRoPEDescriptor( lib.infiniopCreateRoPEDescriptor(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment