Thanks for the update.
I would personally stick to the scatter_ approach and either check for a different batch size or just recreate the tensor e.g. via torch.zeros_like. F.one_hot would also recreate the tensor additionally to the permutation, so you wouldn’t avoid this operation.
Regarding the dim argument for one_hot: could you create a feature request on GitHub and explain your use case to start the discussion please?