For example, I saved training on step 10k and exited program, then resuming train loop, can I set 10k step in dataloader so it would give the exact same sample as it would without breaking execution?
No, you most likely wouldn’t get the same DataLoader state if you haven’t used e.g. epoch seeds before.
In your current code snippet you are using a RandomSampler without passing a generator, so a new one will be initialized as seen here.
If you’ve seeded your code before the beginning of the training, this might work.
If not, your new process would use a new random seed and I don’t think your approach would work.
torch.manual_seed(0)
for i in train_loader:
print(i)
Manual seed before calling dataloader make it reproducible, but how can I resume training from the exact step?
Using continue inside loop would make it read all data from disc.