Repository: pytorch
Issue: [ts_converter] Guard error when retracing
Labels: export-triaged,oncall: export

### 🐛 Describe the bug

When converting the blenderbot_small model to exported program, I get the following error:

Torch Script model: https://drive.google.com/drive/folders/1RbB061coy1TYumMSKxWeCcw7kT-TkVnh?usp=sharing

```pytb
Traceback (most recent call last):

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/experimental/symbolic_shapes.py", line 5686, in __torch_function__
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_ops.py", line 720, in __call__
    return self._op(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_subclasses/functional_tensor.py", line 480, in __torch_dispatch__
    outs_unwrapped = func._op_dk(
                     ^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/utils/_stats.py", line 21, in wrapper
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_subclasses/fake_tensor.py", line 1194, in __torch_dispatch__
    return self.dispatch(func, types, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_subclasses/fake_tensor.py", line 1646, in dispatch
    return self._cached_dispatch_impl(func, types, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_subclasses/fake_tensor.py", line 1293, in _cached_dispatch_impl
    output = self._dispatch_impl(func, types, args, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_subclasses/fake_tensor.py", line 1894, in _dispatch_impl
    return decomposition_table[func](*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_refs/__init__.py", line 4589, in view
    return _reshape_view_helper(a, *shape, allow_copy=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_refs/__init__.py", line 3657, in _reshape_view_helper
    shape = utils.infer_size(shape, a.numel())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_prims_common/__init__.py", line 894, in infer_size
    if d == -1:
       ^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/__init__.py", line 679, in __bool__
    return self.node.bool_()
           ^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/experimental/sym_node.py", line 517, in bool_
    return self.guard_bool("", 0)
           ^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/experimental/sym_node.py", line 455, in guard_bool
    r = self.shape_env.evaluate_expr(self.expr, self.hint, fx_node=self.fx_node)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/experimental/recording.py", line 262, in wrapper
    return retlog(fn(*args, **kwargs))
                  ^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/experimental/symbolic_shapes.py", line 5188, in evaluate_expr
    return self._evaluate_expr(orig_expr, hint, fx_node, expect_rational, size_oblivious, forcing_spec=forcing_spec)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/experimental/symbolic_shapes.py", line 5306, in _evaluate_expr
    raise self._make_data_dependent_error(

torch.fx.experimental.symbolic_shapes.GuardOnDataDependentSymNode: Could not guard on data-dependent expression Eq(u1, -1) (unhinted: Eq(u1, -1)).  (Size-like symbols: none)

Potential framework code culprit (scroll up for full backtrace):
  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_prims_common/__init__.py", line 894, in infer_size
    if d == -1:

For more information, run with TORCH_LOGS="dynamic"
For extended logs when we create symbols, also add TORCHDYNAMO_EXTENDED_DEBUG_CREATE_SYMBOL="u1"
If you suspect the guard was triggered from C++, add TORCHDYNAMO_EXTENDED_DEBUG_CPP=1
For more debugging help, see https://docs.google.com/document/d/1HSuTTVvYH1pTew89Rtpeu84Ht3nQEFTYhAX3Ypa_xJs/edit?usp=sharing

For C++ stack trace, run with TORCHDYNAMO_EXTENDED_DEBUG_CPP=1

The following call raised this error:
  File "/home/justinchu/dev/torch-onnx/src/torch_onnx/_torchscript_converter.py", line 1476, in retrace_as_exported_program
    ep = torch.export._trace._export(



During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/justinchu/dev/torch-onnx/src/torch_onnx/_capture_strategies.py", line 90, in __call__
    exported_program = self._capture(model, args, kwargs, dynamic_shapes)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/dev/torch-onnx/src/torch_onnx/_capture_strategies.py", line 238, in _capture
    ).convert()
      ^^^^^^^^^

  File "/home/justinchu/dev/torch-onnx/src/torch_onnx/_torchscript_converter.py", line 1427, in convert
    ep = self.retrace_as_exported_program(
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/dev/torch-onnx/src/torch_onnx/_torchscript_converter.py", line 1476, in retrace_as_exported_program
    ep = torch.export._trace._export(
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/export/_trace.py", line 1070, in wrapper
    raise e

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/export/_trace.py", line 1043, in wrapper
    ep = fn(*args, **kwargs)
         ^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/export/exported_program.py", line 96, in wrapper
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/export/_trace.py", line 2038, in _export
    export_artifact = export_func(  # type: ignore[operator]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/export/_trace.py", line 1842, in _non_strict_export
    aten_export_artifact = _to_aten_func(  # type: ignore[operator]
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/export/_trace.py", line 630, in _export_to_aten_ir
    gm, graph_signature = transform(aot_export_module)(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/export/_trace.py", line 1760, in _aot_export_non_strict
    gm, sig = aot_export(wrapped_mod, args, kwargs=kwargs, **flags)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_functorch/aot_autograd.py", line 1194, in aot_export_module
    fx_g, metadata, in_spec, out_spec = _aot_export_function(
                                        ^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_functorch/aot_autograd.py", line 1426, in _aot_export_function
    fx_g, meta = create_aot_dispatcher_function(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_functorch/aot_autograd.py", line 429, in create_aot_dispatcher_function
    return _create_aot_dispatcher_function(flat_fn, flat_args, aot_config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_functorch/aot_autograd.py", line 594, in _create_aot_dispatcher_function
    fw_metadata = run_functionalized_fw_and_collect_metadata(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/collect_metadata_analysis.py", line 166, in inner
    flat_f_outs = f(*flat_f_args)
                  ^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/utils.py", line 179, in flat_fn
    tree_out = fn(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/traced_function_transforms.py", line 786, in functional_call
    out = mod(*args[params_len:], **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/export/_trace.py", line 1743, in forward
    tree_out = torch.fx.Interpreter(self._export_root).run(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/interpreter.py", line 147, in run
    self.env[node] = self.run_node(node)
                     ^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/interpreter.py", line 204, in run_node
    return getattr(self, n.op)(n.target, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/interpreter.py", line 276, in call_function
    return target(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/_ops.py", line 720, in __call__
    return self._op(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/experimental/symbolic_shapes.py", line 5688, in __torch_function__
    _suggest_fixes_for_data_dependent_error_non_strict(e)

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/experimental/symbolic_shapes.py", line 5661, in _suggest_fixes_for_data_dependent_error_non_strict
    _suggest_torch_checks(e, src_map)

  File "/home/justinchu/anaconda3/envs/onnx/lib/python3.11/site-packages/torch/fx/experimental/symbolic_shapes.py", line 5609, in _suggest_torch_checks
    diff = ", ".join(s for s in cond.free_symbols if s.name not in src_map)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TypeError: sequence item 0: expected str instance, Symbol found

While executing %view_default_4 : [num_users=1] = call_function[target=torch.ops.aten.view.default](args = (%contiguous_default_2, [%_local_scalar_dense_default, -1, 32]), kwargs = {})
Original traceback:
None
```

### Versions

pytorch: 5ae979ab106a4e2bae782e7d4d56aea08ecd60cb

cc @avikchaudhuri @gmagogsfm @zhxchen17 @tugsbayasgalan @angelayi @suo @ydwu4 @penguinwu @titaiwangms @xadupre @gramalingam @shubhambhokare1