Repository: pytorch
Issue: Compiling `as_strided` call on a view input errors.
Labels: low priority,triaged,oncall: pt2,module: fakeTensor,module: pt2-dispatcher

### 🐛 Describe the bug

Not sure whether this kind of thing is not supposed to be supported, but trying to get to the base tensor of a view using `as_strided` operation fails when trying to `torch.compile` it.

```python
def foo(x):
    v = x.as_strided((10,), (1,), storage_offset=5)
    v.add_(1)
    return v

def args():
    base = torch.arange(20)
    x = base[:10]
    return (x,)

>>> print(foo(*args()))
tensor([ 6,  7,  8,  9, 10, 11, 12, 13, 14, 15])

>>> print(torch.compile()(foo)(*args()))
Traceback (most recent call last):
  File "examples/test.py", line 14, in <module>
    print(torch.compile(foo)(*args()))
  File "torch/_dynamo/eval_frame.py", line 556, in _fn
    return fn(*args, **kwargs)
  File "torch/_dynamo/convert_frame.py", line 1423, in __call__
    return self._torchdynamo_orig_callable(
  File "torch/_dynamo/convert_frame.py", line 1208, in __call__
    result = self._inner_convert(
  File "torch/_dynamo/convert_frame.py", line 549, in __call__
    return _compile(
  File "torch/_dynamo/convert_frame.py", line 977, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "torch/_dynamo/convert_frame.py", line 708, in compile_inner
    return _compile_inner(code, one_graph, hooks, transform)
  File "torch/_utils_internal.py", line 95, in wrapper_function
    return function(*args, **kwargs)
  File "torch/_dynamo/convert_frame.py", line 743, in _compile_inner
    out_code = transform_code_object(code, transform)
  File "torch/_dynamo/bytecode_transformation.py", line 1348, in transform_code_object
    transformations(instructions, code_options)
  File "torch/_dynamo/convert_frame.py", line 233, in _fn
    return fn(*args, **kwargs)
  File "torch/_dynamo/convert_frame.py", line 662, in transform
    tracer.run()
  File "torch/_dynamo/symbolic_convert.py", line 2909, in run
    super().run()
  File "torch/_dynamo/symbolic_convert.py", line 1115, in run
    while self.step():
  File "torch/_dynamo/symbolic_convert.py", line 1027, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "torch/_dynamo/symbolic_convert.py", line 3100, in RETURN_VALUE
    self._return(inst)
  File "torch/_dynamo/symbolic_convert.py", line 3085, in _return
    self.output.compile_subgraph(
  File "torch/_dynamo/output_graph.py", line 1143, in compile_subgraph
    self.compile_and_call_fx_graph(tx, list(reversed(stack_values)), root)
  File "torch/_dynamo/output_graph.py", line 1414, in compile_and_call_fx_graph
    compiled_fn = self.call_user_compiler(gm)
  File "torch/_dynamo/output_graph.py", line 1463, in call_user_compiler
    return self._call_user_compiler(gm)
  File "torch/_dynamo/output_graph.py", line 1512, in _call_user_compiler
    raise BackendCompilerFailed(self.compiler_fn, e).with_traceback(
  File "torch/_dynamo/output_graph.py", line 1493, in _call_user_compiler
    compiled_fn = compiler_fn(gm, self.example_inputs())
  File "torch/_dynamo/repro/after_dynamo.py", line 130, in __call__
    compiled_gm = compiler_fn(gm, example_inputs)
  File "torch/__init__.py", line 2294, in __call__
    return compile_fx(model_, inputs_, config_patches=self.config)
  File "torch/_inductor/compile_fx.py", line 1707, in compile_fx
    return aot_autograd(
  File "torch/_dynamo/backends/common.py", line 72, in __call__
    cg = aot_module_simplified(gm, example_inputs, **self.kwargs)
  File "torch/_functorch/aot_autograd.py", line 1102, in aot_module_simplified
    compiled_fn = dispatch_and_compile()
  File "torch/_functorch/aot_autograd.py", line 1078, in dispatch_and_compile
    compiled_fn, _ = create_aot_dispatcher_function(
  File "torch/_functorch/aot_autograd.py", line 526, in create_aot_dispatcher_function
    return _create_aot_dispatcher_function(
  File "torch/_functorch/aot_autograd.py", line 634, in _create_aot_dispatcher_function
    fw_metadata = run_functionalized_fw_and_collect_metadata(
  File "torch/_functorch/_aot_autograd/collect_metadata_analysis.py", line 197, in inner
    flat_f_outs = f(*flat_f_args)
  File "torch/_functorch/_aot_autograd/traced_function_transforms.py", line 875, in functional_call
    out = PropagateUnbackedSymInts(mod).run(
  File "torch/fx/interpreter.py", line 167, in run
    self.env[node] = self.run_node(node)
  File "torch/fx/experimental/symbolic_shapes.py", line 6560, in run_node
    result = super().run_node(n)
  File "torch/fx/interpreter.py", line 228, in run_node
    return getattr(self, n.op)(n.target, args, kwargs)
  File "torch/fx/interpreter.py", line 332, in call_method
    return getattr(self_obj, target)(*args_tail, **kwargs)
  File "torch/_subclasses/functional_tensor.py", line 545, in __torch_dispatch__
    outs_unwrapped = func._op_dk(
  File "torch/utils/_stats.py", line 21, in wrapper
    return fn(*args, **kwargs)
  File "torch/_subclasses/fake_tensor.py", line 1271, in __torch_dispatch__
    return self.dispatch(func, types, args, kwargs)
  File "torch/_subclasses/fake_tensor.py", line 1813, in dispatch
    return self._cached_dispatch_impl(func, types, args, kwargs)
  File "torch/_subclasses/fake_tensor.py", line 1372, in _cached_dispatch_impl
    output = self._dispatch_impl(func, types, args, kwargs)
  File "torch/_subclasses/fake_tensor.py", line 2297, in _dispatch_impl
    r = func(*args, **kwargs)
  File "torch/_ops.py", line 723, in __call__
    return self._op(*args, **kwargs)
  File "torch/_prims_common/wrappers.py", line 291, in _fn
    result = fn(*args, **kwargs)
  File "torch/_refs/__init__.py", line 2704, in as_strided_scatter
    return prims.as_strided_scatter(input, src, size, stride, storage_offset_int)
  File "torch/_ops.py", line 723, in __call__
    return self._op(*args, **kwargs)
  File "torch/_library/fake_impl.py", line 95, in meta_kernel
    return fake_impl_holder.kernel(*args, **kwargs)
  File "torch/_library/utils.py", line 31, in __call__
    return self.func(*args, **kwargs)
  File "torch/library.py", line 1186, in inner
    return func(*args, **kwargs)
  File "torch/_library/custom_ops.py", line 588, in fake_impl
    return self._abstract_fn(*args, **kwargs)
  File "torch/_prims/__init__.py", line 1704, in _as_strided_scatter_meta
    torch._check(
  File "torch/__init__.py", line 1615, in _check
    _check_with(RuntimeError, cond, message)
  File "torch/__init__.py", line 1597, in _check_with
    raise error_type(message_evaluated)
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
RuntimeError: as_strided_scatter: sizes [10], strides [1], storage offset 5  and itemsize 8 requiring a storage size of 120 are out of bounds for storage of size 80

While executing %add_ : [num_users=0] = call_method[target=add_](args = (%v, 1), kwargs = {})
Original traceback:
  File "examples/test.py", line 5, in foo
    v.add_(1)


Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information


You can suppress this exception and fall back to eager by setting:
    import torch._dynamo
    torch._dynamo.config.suppress_errors = True
```

### Versions

PyTorch version: 2.6.0a0+git362ca54
Is debug build: True
CUDA used to build PyTorch: 12.6
ROCM used to build PyTorch: N/A

cc @ezyang @chauhang @penguinwu @eellison @zou3519 @bdhirsh @yf225