Yes,
But the to_onehot function that you send call scatter on a 2D tensor that it creates and add one dimension to indices before giving it to scatter. So the original indices tensor given to to_onehot should be 1D.