(shape, vocab_size, rng=None, name=None)
| 819 | |
| 820 | |
| 821 | def 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 | |
| 837 | def floats_tensor(shape, scale=1.0, rng=None, name=None): |
no outgoing calls
no test coverage detected