Generally for this kind of problem, you could use torch.repeat_interleave:
x = torch.arange(5)
torch.repeat_interleave(x, torch.tensor([1, 2, 3, 4, 5]), dim=0)

However, in your example, somehow a 0 is added at the beginning and the 4 is missing, so you might need to use torch.cat and a slicing operation.