dimanche 2 juillet 2023

torch randint() function is not working properly

I am trying to use below code to choose random values from defined integer constrained.

block_size = 4 batch_size = 8

def get_batch(split):
    data = [list of 2 million numbers numbers]
    ix = torch.randint(len(data) - block_size, (batch_size,))
    print(ix)
    x = torch.stack([data[i:i+block_size] for i in ix])
    y = torch.stack([data[i+1:i+block_size+1] for i in ix])
    return x,y

But, every time, the tensor generated is --> tensor([0, 0, 0, 0])

But when i run below code independently, i get random values

ix = torch.randint(len(data) - block_size, (batch_size,))

tensor([ 560685, 1199, 167746, 1028068])

Can anyone tell me what i am doing wrong? I have tried using for loop as well

for i in range(batch_size):
    print(i)
    ix = torch.randint(len(data) - block_size, (batch_size,))
    print(ix)
    x = torch.stack([data[i:i+block_size] for i in ix])
    print(x)
    y = torch.stack([data[i+1 : i+block_size + 1 ] for i in ix])



Aucun commentaire:

Enregistrer un commentaire