Skip to content
Merged
Changes from 2 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
10 changes: 10 additions & 0 deletions tester/api_config/config_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,16 @@ def get_padding_offset(bsz, max_seq_len, seq_lens_this_time):
else:
# self.check_arg(api_config, 1, "other"):
self.numpy_tensor = self.get_random_numpy_tensor(self.shape, self.dtype, min=-10, max=10)
elif api_config.api_name in {"paddle.Tensor.topk", "paddle.topk"}:
x_numel = self.numel()
if self.dtype in {"float32", "float64"}:
unique_values = numpy.linspace(-1, 1, num=x_numel, dtype=self.dtype)
permuted_values = numpy.random.permutation(unique_values)
self.numpy_tensor = permuted_values.reshape(self.shape)
elif self.dtype in {"int32", "int64"}:
self.numpy_tensor = numpy.random.choice(numpy.arange(-x_numel, x_numel), size=self.shape, replace=False).astype(self.dtype)
else:
raise ValueError(f"Unsupported dtype {self.dtype} for paddle.topk")

if self.numpy_tensor is None:
if USE_CACHED_NUMPY:
Expand Down