krishna511:

My code is doing so but the selection is not exact division


That would be expected, since you are randomly splitting it.
If you want an exact division in 80%-20%, you could use something like:
lines = [a for a in range(100)]
idx = torch.randperm(len(lines))
idx_train = idx[:int(0.8*len(idx))]
idx_val = idx[int(0.8*len(idx)):]