Implement pad_collate(batch, pad_value=0).
batch is a list of (sequence, label) pairs, where each sequence is a 1-D LongTensor of its own length. Return a 4-tuple (padded, lengths, mask, labels):
padded - (B, T_max), every sequence right-padded with pad_value, keeping the input dtypelengths - (B,) long tensor of the original lengthsmask - (B, T_max) bool tensor, True at real tokens and False at paddinglabels - (B,) long tensor of the labelsloader = DataLoader(dataset, batch_size=2, collate_fn=pad_collate)
T_max is the longest sequence in this batch, not a global constant.torch.full((B, T_max), pad_value, dtype=...) then assign each row's prefix.torch.arange(T_max) against lengths with broadcasting.