MCPcopy Index your code
hub / github.com/pytorch/tutorials / get_next_batch

Function get_next_batch

advanced_source/rpc_ddp_tutorial/main.py:74–90  ·  view source on GitHub ↗
(rank)

Source from the content-addressed store, hash-verified

72
73 # BEGIN run_trainer
74 def get_next_batch(rank):
75 for _ in range(10):
76 num_indices = random.randint(20, 50)
77 indices = torch.LongTensor(num_indices).random_(0, NUM_EMBEDDINGS)
78
79 # Generate offsets.
80 offsets = []
81 start = 0
82 batch_size = 0
83 while start < num_indices:
84 offsets.append(start)
85 start += random.randint(1, 10)
86 batch_size += 1
87
88 offsets_tensor = torch.LongTensor(offsets)
89 target = torch.LongTensor(batch_size).random_(8).cuda(rank)
90 yield indices, offsets_tensor, target
91
92 # Train for 100 epochs
93 for epoch in range(100):

Callers 1

_run_trainerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected