If the model’s output is already padded to the maximum length of the targets, can you simply pad the targets to this length initially? If they are the same length then the standard collation functions should just work.