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

Function ids_tensor

tests/generation/test_logits_process.py:22–35  ·  view source on GitHub ↗
(shape, vocab_size, rng=None, name=None)

Source from the content-addressed store, hash-verified

20
21
22def ids_tensor(shape, vocab_size, rng=None, name=None):
23 # Creates a random int32 tensor of the shape within the vocab size
24 if rng is None:
25 rng = random.Random()
26
27 total_dims = 1
28 for dim in shape:
29 total_dims *= dim
30
31 values = []
32 for _ in range(total_dims):
33 values.append(rng.randint(0, vocab_size - 1))
34
35 return paddle.to_tensor(data=values).reshape(shape)
36
37
38from paddleformers.generation.logits_process import (

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected