Repository: pytorch
Issue: `pack_padded_sequence` not compatible with deterministic mode it calls `torch.scatter`
Labels: module: rnn,triaged,module: determinism

### 🐛 Describe the bug


Calling `pack_padded_sequence` in deterministic mode leads to a bug because it calls `torch.scatter` underneath.

```python
import torch
from torch.nn.utils.rnn import pack_padded_sequence

# Preprocessing
minibatch_size = 1
max_seq_length = 1
input_dim = 3

seq_lengths = [
    torch.randint(1, max_seq_length + 1, (1,)).item()
    for _ in range(minibatch_size)
]

padded_data = torch.zeros((max_seq_length, minibatch_size, input_dim))
for i in range(minibatch_size):
    padded_data[: seq_lengths[i], i, :] = torch.randn(seq_lengths[i], input_dim)

# Main problem
torch.use_deterministic_algorithms(True)
packed_data = pack_padded_sequence(
    padded_data, seq_lengths, batch_first=False, enforce_sorted=False
)
```

Traceback

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/private/home/asablayrolles/miniconda3/envs/_throwaway_nightly/lib/python3.9/site-packages/torch/nn/utils/rnn.py", line 263, in pack_padded_sequence
    return _packed_sequence_init(data, batch_sizes, sorted_indices, None)
  File "/private/home/asablayrolles/miniconda3/envs/_throwaway_nightly/lib/python3.9/site-packages/torch/nn/utils/rnn.py", line 195, in _packed_sequence_init
    data, batch_sizes, sorted_indices, unsorted_indices = _packed_sequence_init_args(
  File "/private/home/asablayrolles/miniconda3/envs/_throwaway_nightly/lib/python3.9/site-packages/torch/nn/utils/rnn.py", line 169, in _packed_sequence_init_args
    unsorted_indices = invert_permutation(sorted_indices)
  File "/private/home/asablayrolles/miniconda3/envs/_throwaway_nightly/lib/python3.9/site-packages/torch/nn/utils/rnn.py", line 204, in invert_permutation
    output.scatter_(0, permutation,
RuntimeError: scatter with src tensor and reduce=None does not have a deterministic implementation, but you set 'torch.use_deterministic_algorithms(True)'. You can turn off determinism just for this operation, or you can use the 'warn_only=True' option, if that's acceptable for your application. You can also file an issue at https://github.com/pytorch/pytorch/issues to help us prioritize adding deterministic support for this operation.
```


### Versions


Collecting environment information...
PyTorch version: 1.14.0.dev20221107
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.2 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.9.13 (main, Oct 13 2022, 21:15:33)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.4.0-81-generic-x86_64-with-glibc2.31
Is CUDA available: False
CUDA runtime version: 11.6.112
GPU models and configuration:
GPU 0: Quadro GP100
GPU 1: Quadro GP100

Nvidia driver version: 470.57.02
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.23.3
[pip3] torch==1.14.0.dev20221107
[pip3] torchaudio==0.14.0.dev20221107
[pip3] torchvision==0.15.0.dev20221107
[conda] blas                      1.0                         mkl
[conda] cpuonly                   2.0                           0    pytorch-nightly
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2021.4.0           h06a4308_640
[conda] mkl-service               2.4.0            py39h7f8727e_0
[conda] mkl_fft                   1.3.1            py39hd3c417c_0
[conda] mkl_random                1.2.2            py39h51133e4_0
[conda] numpy                     1.23.3           py39h14f4228_1
[conda] numpy-base                1.23.3           py39h31eccc5_1
[conda] pytorch                   1.14.0.dev20221107     py3.9_cpu_0    pytorch-nightly
[conda] pytorch-mutex             1.0                         cpu    pytorch-nightly
[conda] torchaudio                0.14.0.dev20221107        py39_cpu    pytorch-nightly
[conda] torchvision               0.15.0.dev20221107        py39_cpu    pytorch-nightly

cc @zou3519 @mruberry @kurtamohler