MCPcopy
hub / github.com/PaddlePaddle/PaddleFormers / ids_tensor

Function ids_tensor

tests/generation/test_stopping_criteria.py:29–42  ·  view source on GitHub ↗
(shape, vocab_size, rng=None, name=None)

Source from the content-addressed store, hash-verified

27
28
29def ids_tensor(shape, vocab_size, rng=None, name=None):
30 # Creates a random int32 tensor of the shape within the vocab size
31 if rng is None:
32 rng = random.Random()
33
34 total_dims = 1
35 for dim in shape:
36 total_dims *= dim
37
38 values = []
39 for _ in range(total_dims):
40 values.append(rng.randint(0, vocab_size - 1))
41
42 return paddle.to_tensor(data=values).reshape(shape)
43
44
45class StoppingCriteriaTestCase(unittest.TestCase):

Callers 1

_get_tensorsMethod · 0.70

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected