Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion op_acc_stable_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,4 @@ def check_tensor_diff(x, y, *, atol, rtol, err_msg=""):
y = y.astype(paddle.float32)
x = x.numpy()
y = y.numpy()
np.testing.assert_allclose(x, y, atol=atol, rtol=rtol, err_msg=err_msg)
np.testing.assert_allclose(x, y, atol=atol, rtol=rtol, err_msg=err_msg)
2 changes: 1 addition & 1 deletion tests/softmax_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def check_diff(self, paddle, pd_ret, th_ret):


if __name__ == "__main__":
op_acc_stable_run(SoftmaxTest)
op_acc_stable_run(SoftmaxTest)
59 changes: 59 additions & 0 deletions tests/zeros_like_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
from op_acc_stable_run import check_tensor_diff, op_acc_stable_run

class Zero_like_Test:
def __init__(self, x_shape, dtype):
self.x_shape = x_shape
self.dtype = dtype

def set_configs(self, paddle):
self.tmp_cache_path = "."
self.inputs = {
"x": paddle.to_tensor(np.random.random(size=self.x_shape).astype(self.dtype) - 0.5) ,
}

def run_paddle(self, paddle):
x = self.inputs["x"]
y = paddle.zeros_like(x, dtype=self.dtype)
return y

def run_torch(self, torch):
def convert_dtype(dtype):
ret = None
if dtype == "float32":
ret = torch.float32
elif dtype == "float16":
ret = torch.float16
elif dtype == "bfloat16":
ret = torch.bfloat16
elif dtype == "int64":
ret = torch.int64
elif dtype == "uint16":
ret = torch.bfloat16
return ret
x = self.inputs["x"]
type = convert_dtype(self.dtype)
y = torch.zeros_like(x, dtype=type)
return y

def check_diff(self, paddle, pd_ret, th_ret):
assert len(pd_ret) == len(th_ret)
for pd, th in zip(pd_ret, th_ret):
check_tensor_diff(pd, th, atol=1e-6, rtol=1e-6)

if __name__ == "__main__":
op_acc_stable_run(Zero_like_Test(x_shape = [1, 8192], dtype ='int64'))