(shape, vocab_size, rng=None, name=None)
| 4828 | |
| 4829 | |
| 4830 | def 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 | |
| 4846 | def random_attention_mask(shape, rng=None, name=None): |
no outgoing calls
no test coverage detected