MCPcopy Create free account
hub / github.com/ModalityDance/Omni-R1 / ids_tensor

Function ids_tensor

src/transformers/tests/test_modeling_common.py:4830–4843  ·  view source on GitHub ↗
(shape, vocab_size, rng=None, name=None)

Source from the content-addressed store, hash-verified

4828
4829
4830def ids_tensor(shape, vocab_size, rng=None, name=None):
4831 # Creates a random int32 tensor of the shape within the vocab size
4832 if rng is None:
4833 rng = global_rng
4834
4835 total_dims = 1
4836 for dim in shape:
4837 total_dims *= dim
4838
4839 values = []
4840 for _ in range(total_dims):
4841 values.append(rng.randint(0, vocab_size - 1))
4842
4843 return torch.tensor(data=values, dtype=torch.long, device=torch_device).view(shape).contiguous()
4844
4845
4846def random_attention_mask(shape, rng=None, name=None):

Calls

no outgoing calls

Tested by

no test coverage detected