MCPcopy Create free account
hub / github.com/huggingface/transformers / ids_tensor

Function ids_tensor

tests/test_modeling_common.py:821–834  ·  view source on GitHub ↗
(shape, vocab_size, rng=None, name=None)

Source from the content-addressed store, hash-verified

819
820
821def ids_tensor(shape, vocab_size, rng=None, name=None):
822 # Creates a random int32 tensor of the shape within the vocab size
823 if rng is None:
824 rng = global_rng
825
826 total_dims = 1
827 for dim in shape:
828 total_dims *= dim
829
830 values = []
831 for _ in range(total_dims):
832 values.append(rng.randint(0, vocab_size - 1))
833
834 return torch.tensor(data=values, dtype=torch.long, device=torch_device).view(shape).contiguous()
835
836
837def floats_tensor(shape, scale=1.0, rng=None, name=None):

Calls

no outgoing calls

Tested by

no test coverage detected