Repository: pytorch
Issue: dynamo (re)compilation issues: shape (1,1), nn.Parameter, mark_dynamic
Labels: good first issue,triaged,oncall: pt2,module: dynamic shapes

### 🐛 Describe the bug

There are following issues:

1. passing `Parameter` as argument instead of `Tensor` causes recompilation
2. setting `torch._dynamo.mark_dynamic` on `Parameter` has no effect
3. passing tensor of size `(1,1)` causes recompilation with a strange guard failure `- 2 <= L['x'].size()[0]`
4. using `torch._dynamo.mark_dynamic(x, 0, min=0)` causes error `not simple sympy type <class 'NoneType'>`
5. using `torch._dynamo.mark_dynamic(x, 0, min=0, max=65536)` causes error `CONSTRAINTS_VIOLATED`

I've checked on 2.4.0 and on nightly

```python
import torch
import torch.nn as nn
from torch import Tensor

import logging
torch._logging.set_logs(recompiles=True, recompiles_verbose = True)


def f(x):
    return x.sin() + 1.0

# def g(x):
#     return x**2

compile_args = dict(fullgraph=True, dynamic = True, backend = "inductor", options={'force_same_precision':True, 'disable_cpp_codegen':False, 'trace.graph_diagram':True, "triton.cudagraphs": False})

@torch.compile(**compile_args)
def foo(x):
    y = f(x)
    # z = g(y)
    return y

shapes = [(2,2), (3,3), (1,1)]

for P in [False, True]:
    for k, shape in enumerate(shapes):
        print(f'Shape {k}: {shape}')
        x = torch.ones(shape)
        if P:
            x = torch.nn.Parameter(x)
        for d in range(x.dim()):
            torch._dynamo.mark_dynamic(x, d) # setting min=0 errors
        z = foo(x)
```

```
Shape 0: (2, 2)
Shape 1: (3, 3)
Shape 2: (1, 1)
V0903 12:36:59.429000 140550974269248 torch/_dynamo/guards.py:2609] [0/1] [__recompiles_verbose] Recompiling function foo in /mnt/datagrid/personal/shekhovt/quant/debug/test_compile1.py:17
V0903 12:36:59.429000 140550974269248 torch/_dynamo/guards.py:2609] [0/1] [__recompiles_verbose]     triggered by the following guard failure(s):
V0903 12:36:59.429000 140550974269248 torch/_dynamo/guards.py:2609] [0/1] [__recompiles_verbose]     guard 0 failures:
V0903 12:36:59.429000 140550974269248 torch/_dynamo/guards.py:2609] [0/1] [__recompiles_verbose]     - 2 <= L['x'].size()[0]                                         # _dynamo/output_graph.py:452 in init_ambient_guards
V0903 12:36:59.429000 140550974269248 torch/_dynamo/guards.py:2609] [0/1] [__recompiles_verbose]     - 2 <= L['x'].size()[1]                                         # _dynamo/output_graph.py:452 in init_ambient_guards
Shape 0: (2, 2)
V0903 12:37:02.287000 140550974269248 torch/_dynamo/guards.py:2609] [0/2] [__recompiles_verbose] Recompiling function foo in /mnt/datagrid/personal/shekhovt/quant/debug/test_compile1.py:17
V0903 12:37:02.287000 140550974269248 torch/_dynamo/guards.py:2609] [0/2] [__recompiles_verbose]     triggered by the following guard failure(s):
V0903 12:37:02.287000 140550974269248 torch/_dynamo/guards.py:2609] [0/2] [__recompiles_verbose]     guard 0 failures:
V0903 12:37:02.287000 140550974269248 torch/_dynamo/guards.py:2609] [0/2] [__recompiles_verbose]     - expected type of 'L['x']' to be a tensor type, ' but found <class 'torch.nn.parameter.Parameter'>
V0903 12:37:02.287000 140550974269248 torch/_dynamo/guards.py:2609] [0/2] [__recompiles_verbose] 
V0903 12:37:02.287000 140550974269248 torch/_dynamo/guards.py:2609] [0/2] [__recompiles_verbose]     guard 1 failures:
V0903 12:37:02.287000 140550974269248 torch/_dynamo/guards.py:2609] [0/2] [__recompiles_verbose]     - expected type of 'L['x']' to be a tensor type, ' but found <class 'torch.nn.parameter.Parameter'>
Shape 1: (3, 3)
V0903 12:37:05.634000 140550974269248 torch/_dynamo/guards.py:2609] [0/3] [__recompiles_verbose] Recompiling function foo in /mnt/datagrid/personal/shekhovt/quant/debug/test_compile1.py:17
V0903 12:37:05.634000 140550974269248 torch/_dynamo/guards.py:2609] [0/3] [__recompiles_verbose]     triggered by the following guard failure(s):
V0903 12:37:05.634000 140550974269248 torch/_dynamo/guards.py:2609] [0/3] [__recompiles_verbose]     guard 0 failures:
V0903 12:37:05.634000 140550974269248 torch/_dynamo/guards.py:2609] [0/3] [__recompiles_verbose]     - tensor 'L['x']' size mismatch at index 0. expected 2, actual 3
V0903 12:37:05.634000 140550974269248 torch/_dynamo/guards.py:2609] [0/3] [__recompiles_verbose] 
V0903 12:37:05.634000 140550974269248 torch/_dynamo/guards.py:2609] [0/3] [__recompiles_verbose]     guard 1 failures:
V0903 12:37:05.634000 140550974269248 torch/_dynamo/guards.py:2609] [0/3] [__recompiles_verbose]     - expected type of 'L['x']' to be a tensor type, ' but found <class 'torch.nn.parameter.Parameter'>
V0903 12:37:05.634000 140550974269248 torch/_dynamo/guards.py:2609] [0/3] [__recompiles_verbose] 
V0903 12:37:05.634000 140550974269248 torch/_dynamo/guards.py:2609] [0/3] [__recompiles_verbose]     guard 2 failures:
V0903 12:37:05.634000 140550974269248 torch/_dynamo/guards.py:2609] [0/3] [__recompiles_verbose]     - expected type of 'L['x']' to be a tensor type, ' but found <class 'torch.nn.parameter.Parameter'>
Shape 2: (1, 1)
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose] Recompiling function foo in /mnt/datagrid/personal/shekhovt/quant/debug/test_compile1.py:17
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose]     triggered by the following guard failure(s):
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose]     guard 0 failures:
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose]     - tensor 'L['x']' size mismatch at index 0. expected 3, actual 1
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose] 
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose]     guard 1 failures:
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose]     - tensor 'L['x']' size mismatch at index 0. expected 2, actual 1
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose] 
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose]     guard 2 failures:
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose]     - expected type of 'L['x']' to be a tensor type, ' but found <class 'torch.nn.parameter.Parameter'>
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose] 
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose]     guard 3 failures:
V0903 12:37:08.674000 140550974269248 torch/_dynamo/guards.py:2609] [0/4] [__recompiles_verbose]     - expected type of 'L['x']' to be a tensor type, ' but found <class 'torch.nn.parameter.Parameter'>
```

### Versions

Collecting environment information...
PyTorch version: 2.5.0.dev20240902+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (GCC) 13.2.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.11.5 (main, Oct  2 2023, 09:22:39) [GCC 13.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-1062-nvidia-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.2.140
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA A100-SXM4-40GB
GPU 1: NVIDIA A100-SXM4-40GB
GPU 2: NVIDIA A100-SXM4-40GB
GPU 3: NVIDIA DGX Display
GPU 4: NVIDIA A100-SXM4-40GB

Nvidia driver version: 535.183.01
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        43 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               128
On-line CPU(s) list:                  0-127
Vendor ID:                            AuthenticAMD
Model name:                           AMD EPYC 7742 64-Core Processor
CPU family:                           23
Model:                                49
Thread(s) per core:                   2
Core(s) per socket:                   64
Socket(s):                            1
Stepping:                             0
Frequency boost:                      enabled
CPU max MHz:                          2250,0000
CPU min MHz:                          1500,0000
BogoMIPS:                             4491.73
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sme sev sev_es
Virtualization:                       AMD-V
L1d cache:                            2 MiB (64 instances)
L1i cache:                            2 MiB (64 instances)
L2 cache:                             32 MiB (64 instances)
L3 cache:                             256 MiB (16 instances)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-127
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Mitigation; untrained return thunk; SMT enabled with STIBP protection
Vulnerability Spec rstack overflow:   Mitigation; safe RET
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Retpolines; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] pytorch-triton==3.0.0+dedb7bdf33
[pip3] torch==2.5.0.dev20240902+cu118
[pip3] torchaudio==2.5.0.dev20240902+cu118
[pip3] torchvision==0.20.0.dev20240902+cu118
[conda] Could not collect


cc @ezyang @chauhang @penguinwu