Repository: pytorch
Issue: Enable dynamo to handle mark_dynamic X closure 
Labels: low priority,triaged,oncall: pt2,module: dynamic shapes

### 🚀 The feature, motivation and pitch
cc @ezyang @msaroufim @bdhirsh @anijain2305 @chauhang @adnanaziz 
Repro:
```
import torch

a =  torch.ones(3, 3)
torch._dynamo.mark_dynamic(a, 0)

d = a * 2
def test_f(a):
    return a + d

out = torch.compile(test_f)(a)
```

This produces the following error message:
```
E0408 15:14:16.049000 140477988107264 torch/_guards.py:251] [0/0] Error while creating guard:
E0408 15:14:16.049000 140477988107264 torch/_guards.py:251] [0/0] Name: ''
E0408 15:14:16.049000 140477988107264 torch/_guards.py:251] [0/0]     Source: shape_env
E0408 15:14:16.049000 140477988107264 torch/_guards.py:251] [0/0]     Create Function: SHAPE_ENV
E0408 15:14:16.049000 140477988107264 torch/_guards.py:251] [0/0]     Guard Types: None
E0408 15:14:16.049000 140477988107264 torch/_guards.py:251] [0/0]     Code List: None
E0408 15:14:16.049000 140477988107264 torch/_guards.py:251] [0/0]     Object Weakref: None
E0408 15:14:16.049000 140477988107264 torch/_guards.py:251] [0/0]     Guarded Class Weakref: None
E0408 15:14:16.049000 140477988107264 torch/_guards.py:253] [0/0] Created at:
E0408 15:14:16.049000 140477988107264 torch/_guards.py:253] [0/0]   File "/home/yidi/local/pytorch/torch/_dynamo/convert_frame.py", line 490, in transform
E0408 15:14:16.049000 140477988107264 torch/_guards.py:253] [0/0]     tracer = InstructionTranslator(
E0408 15:14:16.049000 140477988107264 torch/_guards.py:253] [0/0]   File "/home/yidi/local/pytorch/torch/_dynamo/symbolic_convert.py", line 2097, in __init__
E0408 15:14:16.049000 140477988107264 torch/_guards.py:253] [0/0]     output=OutputGraph(
E0408 15:14:16.049000 140477988107264 torch/_guards.py:253] [0/0]   File "/home/yidi/local/pytorch/torch/_dynamo/output_graph.py", line 304, in __init__
E0408 15:14:16.049000 140477988107264 torch/_guards.py:253] [0/0]     self.init_ambient_guards()
E0408 15:14:16.049000 140477988107264 torch/_guards.py:253] [0/0]   File "/home/yidi/local/pytorch/torch/_dynamo/output_graph.py", line 419, in init_ambient_guards
E0408 15:14:16.049000 140477988107264 torch/_guards.py:253] [0/0]     self.guards.add(ShapeEnvSource().make_guard(GuardBuilder.SHAPE_ENV))
Traceback (most recent call last):
  File "/home/yidi/local/pytorch/test.py", line 10, in <module>
    out = torch.compile(test_f)(a)
  File "/home/yidi/local/pytorch/torch/_dynamo/eval_frame.py", line 410, in _fn
    return fn(*args, **kwargs)
  File "/home/yidi/local/pytorch/torch/_dynamo/convert_frame.py", line 966, in catch_errors
    return callback(frame, cache_entry, hooks, frame_state, skip=1)
  File "/home/yidi/local/pytorch/torch/_dynamo/convert_frame.py", line 809, in _convert_frame
    result = inner_convert(
  File "/home/yidi/local/pytorch/torch/_dynamo/convert_frame.py", line 404, in _convert_frame_assert
    return _compile(
  File "/home/yidi/local/pytorch/torch/_utils_internal.py", line 70, in wrapper_function
    return function(*args, **kwargs)
  File "/home/yidi/local/miniconda3/envs/pytorch-3.10/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/home/yidi/local/pytorch/torch/_dynamo/convert_frame.py", line 691, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "/home/yidi/local/pytorch/torch/_dynamo/utils.py", line 265, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/yidi/local/pytorch/torch/_dynamo/convert_frame.py", line 649, in compile_inner
    check_fn = CheckFunctionManager(
  File "/home/yidi/local/pytorch/torch/_dynamo/guards.py", line 1734, in __init__
    guard.create(builder)
  File "/home/yidi/local/pytorch/torch/_guards.py", line 249, in create
    return self.create_fn(builder, self)
  File "/home/yidi/local/pytorch/torch/_dynamo/guards.py", line 1333, in SHAPE_ENV
    guards = output_graph.shape_env.produce_guards(
  File "/home/yidi/local/pytorch/torch/fx/experimental/symbolic_shapes.py", line 3378, in produce_guards
    raise ConstraintViolationError(
torch.fx.experimental.symbolic_shapes.ConstraintViolationError: Constraints violated (L['a'].size()[0])! For more information, run with TORCH_LOGS="+dynamic".
  - Not all values of RelaxedUnspecConstraint(L['a'].size()[0]) are valid because L['a'].size()[0] was inferred to be a constant (3).


You can suppress this exception and fall back to eager by setting:
    import torch._dynamo
    torch._dynamo.config.suppress_errors = True

```

It can be a bit unintuitive from user's perspective: d = a * 2 infers that d has the same dynamic shape with but when it's closed in test_f, its shape become static and causes a specialization of a. 

We could either:
1. Support mark_dynamic + closure by having a way of knowing the closure is dynamic.
2. Allow this specialization to happen.

I found TORCHDYNAMO_EXTENDED_DEBUG_GUARD_ADDED="Eq(s0, 3)" TORCH_LOGS=+dynamic very useful in coming up with the minimal repro and the error message is great.