Repository: pytorch
Issue: [torch.compile] Constraint violation error during dynamic shape compilation
Labels: triaged,oncall: pt2,module: dynamic shapes

### 🐛 Describe the bug

Hello, I'm trying to compile a simple model using `torch_tensorrt`. Here's the code 
```py
import torch
import torch_tensorrt 

class MyModule(torch.nn.Module):
        def __init__(self):
            super().__init__()
            self.conv = torch.nn.Conv2d(3, 16, 3, stride=1, bias=True)
            self.relu = torch.nn.ReLU()

        def forward(self, x):
            out = self.conv(x)
            out = self.relu(out)
            return out

model = MyModule().eval().cuda()

compile_spec = {
    "device": torch_tensorrt.Device("cuda:0"),
    "enabled_precisions": {torch.float},
    "ir": "torch_compile",
    "min_block_size": 1,
    "debug": True
}

input_bs4 = torch.randn((4, 3, 224, 224)).to("cuda")
torch._dynamo.mark_dynamic(input_bs4, 0, min=2, max=8)
# Compile the model
trt_model = torch.compile(model, backend="tensorrt", options=compile_spec)
out_bs4 = trt_model(input_bs4)
input_bs6 = torch.randn((6, 3, 224, 224)).to("cuda")
out_bs6 = trt_model(input_bs6)
```

The error I see is 
```py
File "/home/dperi/.pyenv/versions/3.11.7/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 726, in compile_inner
    check_fn = CheckFunctionManager(
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/dperi/.pyenv/versions/3.11.7/lib/python3.11/site-packages/torch/_dynamo/guards.py", line 2141, in __init__
    guard.create(builder)
  File "/home/dperi/.pyenv/versions/3.11.7/lib/python3.11/site-packages/torch/_guards.py", line 259, in create
    return self.create_fn(builder, self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dperi/.pyenv/versions/3.11.7/lib/python3.11/site-packages/torch/_dynamo/guards.py", line 1728, in SHAPE_ENV
    guards = output_graph.shape_env.produce_guards(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dperi/.pyenv/versions/3.11.7/lib/python3.11/site-packages/torch/fx/experimental/symbolic_shapes.py", line 4167, in produce_guards
    raise ConstraintViolationError(
torch.fx.experimental.symbolic_shapes.ConstraintViolationError: Constraints violated (L['x'].size()[0])! For more information, run with TORCH_LOGS="+dynamic".
  - Not all values of L['x'].size()[0] = L['x'].size()[0] in the specified range L['x'].size()[0] <= 8 satisfy the generated guard 4 <= L['x'].size()[0] and L['x'].size()[0] <= 8
```

It seems like the guard is modified to use [4, 8] range instead of the [2, 8] range I initially provided using `torch._dynamo.mark_dynamic(input_bs4, 0, min=2, max=8)`. 
Here's the full log : 
[full_log.txt](https://github.com/user-attachments/files/15962156/full_log.txt)

If I modify it to `torch._dynamo.mark_dynamic(input_bs4, 0, min=4, max=8)`, the code works. Any suggestions here ? Thanks !! 
cc: @ezyang @avikchaudhuri @angelayi 

### Error logs

_No response_

### Minified repro

_No response_

### Versions

Versions of relevant libraries:
[pip3] flake8==6.1.0
[pip3] flake8-bugbear==23.3.23
[pip3] flake8-comprehensions==3.12.0
[pip3] flake8-executable==2.1.3
[pip3] flake8-logging-format==0.9.0
[pip3] flake8-pyi==23.3.1
[pip3] flake8-simplify==0.19.3
[pip3] mypy==1.3.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.3
[pip3] onnx==1.15.0
[pip3] onnx-graphsurgeon==0.3.25
[pip3] onnxruntime==1.16.3
[pip3] onnxruntime_extensions==0.10.1
[pip3] onnxscript==0.1.0.dev20240205
[pip3] onnxsim==0.4.35
[pip3] optree==0.10.0
[pip3] pytorch-lightning==2.0.7
[pip3] pytorch-triton==3.0.0+45fff310c8
[pip3] pytorch-triton-rocm==2.2.0
[pip3] torch==2.5.0.dev20240617+cu124
[pip3] torch_tensorrt==2.5.0.dev0+5fbf19e4a
[pip3] torchmetrics==1.4.0.post0
[pip3] torchprofile==0.0.4
[pip3] torchsurgeon==0.1.2
[pip3] torchvision==0.19.0.dev20240617+cu124
[pip3] triton==2.3.1

cc @ezyang @anijain2305 @chauhang @penguinwu