Batching rule not implemented for aten::unsafe_chunk
Labels: triaged, actionable, module: vmap, module: functorch

### 🐛 Describe the bug

LSTM with batch-jacobian  (with vmap) seem not support batch derivative computation with the new version of pytorch.
When the output of a LSTM layer is used with some derivation manipulation (eg torch.func.jacrev), the forward step in the training process raised an error due to the vmap function

torch version :  2.1.0.dev20230716 (the previous version version of pytorch can not be used due to some corrections add after https://github.com/pytorch/pytorch/issues/99413) 

Here a simple example to reproduce the error :


```python
import torch
from torch import nn
import torch.optim as optim

class MyNet(nn.Module) :
    def __init__(self,n_input,n_layers,hiddden_size):
        super(MyNet,self).__init__()
        self.n_input = n_input
        self.n_layers = n_layers
        self.hidden_size = hiddden_size

        # Layers
        self.rnn = nn.LSTM(input_size = self.n_input, hidden_size = self.hidden_size,num_layers = self.n_layers)
        self.layer_out = nn.Linear(self.hidden_size,1)

        self.time_trace = torch.func.vmap(torch.trace)

    def forward(self,x) : 
        self.jac = torch.func.vmap(torch.func.jacrev(self.RNN_forward))
        der_out = torch.diagonal(self.jac(x),dim1=1,dim2=3)[:,0].transpose(2,3).transpose(1,2)
        
        return der_out
    
    def RNN_forward(self,x) :
        output,_ = self.rnn(self.time_trace(x)[:,None])
        return self.layer_out(output)

if __name__ == "__main__" : 
    batch = 10
    seq_len = 12
    Net = MyNet(1,4,20)

    x = torch.rand(batch,seq_len,3,3)
    x.requires_grad = True
    y_truth = torch.rand(batch,seq_len,3,3)
    y_pred = Net(x)

    criterion = nn.MSELoss()
    optimizer = optim.Adam(Net.parameters(), lr = 1e-3)

    optimizer.zero_grad()
    loss = criterion(y_pred,y_truth)
    loss.backward()
    optimizer.step()

```

The error :
```
/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/nn/modules/rnn.py:835: UserWarning: There is a performance drop because we have not yet implemented the batching rule for aten::mkldnn_rnn_layer. Please file us an issue on GitHub so that we can prioritize its implementation. (Triggered internally at /opt/conda/conda-bld/pytorch_1689491447879/work/aten/src/ATen/functorch/BatchedFallback.cpp:82.)
  result = _VF.lstm(input, hx, self._flat_weights, self.bias, self.num_layers,
Traceback (most recent call last):
  File "/home/npistenon/Documents/Multifidelity/Visco_elasticity_nonlinear/Issue/Pb_DerTorch3.py", line 36, in <module>
    y_pred = Net(x)
             ^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1522, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1531, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/npistenon/Documents/Multifidelity/Visco_elasticity_nonlinear/Issue/Pb_DerTorch3.py", line 20, in forward
    der_out = torch.diagonal(self.jac(x),dim1=1,dim2=3)[:,0].transpose(2,3).transpose(1,2)
                             ^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/_functorch/vmap.py", line 436, in wrapped
    return _flat_vmap(
           ^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/_functorch/vmap.py", line 39, in fn
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/_functorch/vmap.py", line 621, in _flat_vmap
    batched_outputs = func(*batched_inputs, **kwargs)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/_functorch/eager_transforms.py", line 602, in wrapper_fn
    flat_jacobians_per_input = compute_jacobian_stacked()
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/_functorch/eager_transforms.py", line 533, in compute_jacobian_stacked
    chunked_result = vmap(vjp_fn)(basis)
                     ^^^^^^^^^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/_functorch/vmap.py", line 436, in wrapped
    return _flat_vmap(
           ^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/_functorch/vmap.py", line 39, in fn
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/_functorch/vmap.py", line 621, in _flat_vmap
    batched_outputs = func(*batched_inputs, **kwargs)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/_functorch/eager_transforms.py", line 329, in wrapper
    result = _autograd_grad(flat_primals_out, flat_diff_primals, flat_cotangents,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/_functorch/eager_transforms.py", line 117, in _autograd_grad
    grad_inputs = torch.autograd.grad(diff_outputs, inputs, grad_outputs,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/npistenon/Documents/anaconda3/envs/torchtest/lib/python3.11/site-packages/torch/autograd/__init__.py", line 319, in grad
    result = Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Batching rule not implemented for aten::unsafe_chunk. We could not generate a fallback.
```

### Versions

PyTorch version: 2.1.0.dev20230716
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
Clang version: Could not collect
CMake version: version 3.26.3
Libc version: glibc-2.35

Python version: 3.11.4 (main, Jul  5 2023, 13:45:01) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.19.0-46-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture :                          x86_64
Mode(s) opératoire(s) des processeurs : 32-bit, 64-bit
Address sizes:                          39 bits physical, 48 bits virtual
Boutisme :                              Little Endian
Processeur(s) :                         12
Liste de processeur(s) en ligne :       0-11
Identifiant constructeur :              GenuineIntel
Nom de modèle :                         Intel(R) Xeon(R) W-11855M CPU @ 3.20GHz
Famille de processeur :                 6
Modèle :                                141
Thread(s) par cœur :                    2
Cœur(s) par socket :                    6
Socket(s) :                             1
Révision :                              1
Vitesse maximale du processeur en MHz : 4900.0000
Vitesse minimale du processeur en MHz : 800.0000
BogoMIPS :                              6374.40
Drapaux :                               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l2 invpcid_single cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves split_lock_detect dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear ibt flush_l1d arch_capabilities
Virtualisation :                        VT-x
Cache L1d :                             288 KiB (6 instances)
Cache L1i :                             192 KiB (6 instances)
Cache L2 :                              7.5 MiB (6 instances)
Cache L3 :                              18 MiB (1 instance)
Nœud(s) NUMA :                          1
Nœud NUMA 0 de processeur(s) :          0-11
Vulnerability Itlb multihit:            Not affected
Vulnerability L1tf:                     Not affected
Vulnerability Mds:                      Not affected
Vulnerability Meltdown:                 Not affected
Vulnerability Mmio stale data:          Not affected
Vulnerability Retbleed:                 Not affected
Vulnerability Spec store bypass:        Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:               Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:               Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                    Not affected
Vulnerability Tsx async abort:          Not affected

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] torch==2.1.0.dev20230716
[pip3] torchaudio==2.1.0.dev20230716
[pip3] torchvision==0.16.0.dev20230716
[conda] blas                      1.0                         mkl  
[conda] brotlipy                  0.7.0           py311h9bf148f_1002    pytorch-nightly
[conda] cffi                      1.15.1          py311h9bf148f_3    pytorch-nightly
[conda] cpuonly                   2.0                           0    pytorch-nightly
[conda] cryptography              38.0.4          py311h46ebde7_0    pytorch-nightly
[conda] filelock                  3.9.0                   py311_0    pytorch-nightly
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0           py311h9bf148f_0    pytorch-nightly
[conda] mkl_fft                   1.3.1           py311hc796f24_0    pytorch-nightly
[conda] mkl_random                1.2.2           py311hbba84a0_0    pytorch-nightly
[conda] mpmath                    1.2.1                   py311_0    pytorch-nightly
[conda] numpy                     1.24.3          py311hc206e33_0  
[conda] numpy-base                1.24.3          py311hfd5febd_0  
[conda] pillow                    9.3.0           py311h3fd9d12_2    pytorch-nightly
[conda] pysocks                   1.7.1                   py311_0    pytorch-nightly
[conda] pytorch                   2.1.0.dev20230716    py3.11_cpu_0    pytorch-nightly
[conda] pytorch-mutex             1.0                         cpu    pytorch-nightly
[conda] requests                  2.28.1                  py311_0    pytorch-nightly
[conda] torchaudio                2.1.0.dev20230716       py311_cpu    pytorch-nightly
[conda] torchvision               0.16.0.dev20230716       py311_cpu    pytorch-nightly
[conda] urllib3                   1.26.14                 py311_0    pytorch-nightly

cc @zou3519 @Chillee @samdow @kshitij12345 @janeyx99