Repository: pytorch
Issue: [1.10 regression][jit][cuda fuse] cat codegen wrong var name
Labels: oncall: jit,Stale

## 🐛 Bug

I have a `ScriptModule`, whose one (scripted) method takes in a `NamedTuple`. Using that method causes the following error, which seems to have wrong variable names.
```py
  Uncaught exception
  Traceback (most recent call last):
    File "/private/home/ssnl/dreamer-pytorch/dreamer_toy/main_new.py", line 671, in <module>
      trainer.fit()
    File "/private/home/ssnl/dreamer-pytorch/dreamer_toy/main_new.py", line 561, in fit
      test()
    File "/private/home/ssnl/dreamer-pytorch/dreamer_toy/main_new.py", line 526, in test
      test_rewards = self.test(
    File "/private/home/ssnl/dreamer-pytorch/dreamer_toy/main_new.py", line 440, in test
      for interact_data in interaction:
    File "/private/home/ssnl/dreamer-pytorch/dreamer_toy/dreamer/envs/interaction.py", line 228, in env_interact_with_dreamer
      yield from env_interact(
    File "/private/home/ssnl/dreamer-pytorch/dreamer_toy/dreamer/envs/interaction.py", line 90, in env_interact
      action, next_state_fn = interactor.act_and_update_state(state)
    File "/private/home/ssnl/dreamer-pytorch/dreamer_toy/dreamer/envs/interaction.py", line 204, in act_and_update_state
      next_dreamer_latent_state: Dreamer.LatentState = self.dreamer_model.posterior_rsample_one_step(
    File "/private/home/ssnl/dreamer-pytorch/dreamer_toy/dreamer/models/dreamer.py", line 317, in posterior_rsample_one_step
      transition_output = self.transition_model.posterior_rsample_one_step(
    File "/private/home/ssnl/dreamer-pytorch/dreamer_toy/dreamer/models/_impls/transition.py", line 975, in posterior_rsample_one_step
      x, y, z = self.forward_generic_one_step(previous_latent_state.as_namedtuple(), action,
  RuntimeError: default_program(21): error: identifier "input2" is undefined

  default_program(21): error: identifier "input3" is undefined

  default_program(21): error: identifier "input4" is undefined

  3 errors detected in the compilation of "default_program".

  nvrtc compilation failed:

  #define NAN __int_as_float(0x7fffffff)
  #define POS_INFINITY __int_as_float(0x7f800000)
  #define NEG_INFINITY __int_as_float(0xff800000)


  template<typename T>
  __device__ T maximum(T a, T b) {
    return isnan(a) ? a : (a > b ? a : b);
  }

  template<typename T>
  __device__ T minimum(T a, T b) {
    return isnan(a) ? a : (a < b ? a : b);
  }

  extern "C" __global__
  void fused_mul_add_cat(float* tx_belief_1, float* tempty_tensor_1, float* tprev_z_belief, float* tprev_z_state, float* tnext_observation_maybe_reward_25, float* ty_posterior_noise, float* aten_cat, float* output_1) {
  {
  if ((long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)<3552ll ? 1 : 0) {
      aten_cat[(long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)] = ((((long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)) % 296ll<40ll ? 1 : 0) ? ((((
long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)) % 296ll<40ll ? 1 : 0) ? ((((long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)) % 296ll<40ll ? 1 : 0) ? ((((long long)(threadIdx.x)
+ 512ll * (long long)(blockIdx.x)) % 296ll<40ll ? 1 : 0) ? __ldg(tx_belief_1 + ((long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)) % 296ll + 40ll * (((long long)(threadIdx.x) + 512ll * (lon
g long)(blockIdx.x)) / 296ll)) : __ldg(input2 + ((long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)) % 296ll - 40ll)) : __ldg(input3 + ((long long)(threadIdx.x) + 512ll * (long long)(blockId
x.x)) % 296ll - 40ll)) : __ldg(input4 + ((long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)) % 296ll - 40ll)) : __ldg(tnext_observation_maybe_reward_25 + (((long long)(threadIdx.x) + 512ll *
 (long long)(blockIdx.x)) % 296ll + 2
0: 56ll * (((long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)) / 296ll)) - 40ll));
    }}
  }
```

Unfortunately all my attempt to get an isolated reproducing example fails. But I hope that this may help identify the issue. The method in question has the following signature:
```py
    @jit.script_method
    def forward_generic_one_step(
        self,
        previous_latent_state: LatentStateTuple,  # A NamedTuple
        action: torch.Tensor,
        next_observation: Optional[torch.Tensor] = None,
        reward: Optional[torch.Tensor] = None,
        next_observation_nonfirststep: Optional[torch.Tensor] = None,
    ) -> Tuple[PartialOutputWithPosterior, PartialOutputWithPosterior, PartialOutputWithPosterior]:  # 3 NamedTuples
```
Currently I have to call JIT private APIs to disable fusing.

The same code works on 1.8.1.

## Environment
```
OS: Ubuntu 20.04.1 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: version 3.19.6
Libc version: glibc-2.31

Python version: 3.8.8 (default, Apr 13 2021, 19:58:26)  [GCC 7.3.0] (64-bit runtime)
Python platform: Linux-5.4.0-52-generic-x86_64-with-glibc2.10
Is CUDA available: True
CUDA runtime version: 11.1.74
GPU models and configuration:
GPU 0: Quadro GP100
GPU 1: Quadro GP100

Nvidia driver version: 450.80.02
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] mypy==0.901
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.20.1
[pip3] numpydoc==1.1.0
[pip3] torch==1.10.0
[pip3] torch-tb-profiler==0.1.0
[pip3] torchaudio==0.10.0
[pip3] torchfile==0.1.0
[pip3] torchvision==0.11.1
[conda] blas                      1.0                         mkl
[conda] cudatoolkit               11.1.74              h6bb024c_0    nvidia
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2021.2.0           h06a4308_296
[conda] mkl-include               2021.2.0           h06a4308_296
[conda] mkl-service               2.3.0            py38h27cfd23_1
[conda] mkl_fft                   1.3.0            py38h42c9631_2
[conda] mkl_random                1.2.1            py38ha9443f7_2
[conda] mypy                      0.901              pyhd3eb1b0_0
[conda] mypy_extensions           0.4.3                    py38_0
[conda] numpy                     1.19.5                   pypi_0    pypi
[conda] numpy-base                1.20.1           py38h7d8b39e_0
[conda] numpydoc                  1.1.0              pyhd3eb1b0_1
[conda] pytorch                   1.10.0          py3.8_cuda11.1_cudnn8.0.5_0    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torch-tb-profiler         0.1.0                    pypi_0    pypi
[conda] torchaudio                0.10.0               py38_cu111    pytorch
[conda] torchfile                 0.1.0                    pypi_0    pypi
[conda] torchvision               0.11.1               py38_cu111    pytorch
```