Below a solution to keep the same shape when computing first differences across the last dimension by padding zeros at the front.
import torch.nn.functional as F
t = torch.rand((10, 10, 10))
diff = t - F.pad(t, (1, 0))[:, :, :-1]

Note 1: you can also create a Conv layer with a 2 sized kernel with fixed weights [-1, 1], but that comes down to the same thing.
Note 2: Don’t know if this is optimal in terms of speed, I know it’s faster than using a concatenation. Happy to learn when someone has a faster option