Repository: pytorch
Issue: InternalTorchDynamoError: 'FunctionCtx' object has no attribute 'saved_tensors'
Labels: module: autograd,triaged,oncall: pt2,module: dynamo,dynamo-autograd-function

### 🐛 Describe the bug

Accessing a `FunctionCtx` but not using it hits an `InternalTorchDynamoError`.

### Error logs

```
Traceback (most recent call last):
  File "/tmp/smaller-dynbug.py", line 9, in <module>
    f()
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/eval_frame.py", line 469, in _fn
    return fn(*args, **kwargs)
  File "/tmp/smaller-dynbug.py", line 7, in f
    _ = torch.autograd.function.FunctionCtx()
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 1238, in __call__
    return self._torchdynamo_orig_callable(
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 1039, in __call__
    result = self._inner_convert(
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 514, in __call__
    return _compile(
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 929, in _compile
    raise InternalTorchDynamoError(str(e)).with_traceback(
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 902, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 653, in compile_inner
    return _compile_inner(code, one_graph, hooks, transform)
  File "/usr/local/lib/python3.10/dist-packages/torch/_utils_internal.py", line 85, in wrapper_function
    return StrobelightCompileTimeProfiler.profile_compile_time(
  File "/usr/local/lib/python3.10/dist-packages/torch/_strobelight/compile_time_profiler.py", line 129, in p
rofile_compile_time
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 686, in _compile_inner
    out_code = transform_code_object(code, transform)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/bytecode_transformation.py", line 1322, in transform_code_object
    transformations(instructions, code_options)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 208, in _fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 622, in transform
    tracer.run()
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 2731, in run
    super().run()
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 958, in run
    while self.step():
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 870, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 1048, in STORE_FAST
    self._store_fast(inst.argval)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 1044, in _store_fast
    loaded_vt.set_name_hint(name)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/lazy.py", line 156, in realize_and_forward
    return getattr(self.realize(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/lazy.py", line 63, in realize
    self._cache.realize()
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/lazy.py", line 29, in realize
    self.vt = VariableBuilder(tx, self.source)(self.value)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/builder.py", line 333, in __call__
    vt = self._wrap(value)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/builder.py", line 699, in _wrap
    actual_saved_tensors = value.saved_tensors
torch._dynamo.exc.InternalTorchDynamoError: 'FunctionCtx' object has no attribute 'saved_tensors'

from user code:
   File "/tmp/smaller-dynbug.py", line 7, in torch_dynamo_resume_in_f_at_7
    _ = torch.autograd.function.FunctionCtx()

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
```

### Minified repro

```python
import torch

@torch.compile(backend="eager")
def f():
    _ = torch.autograd.function.FunctionCtx()
    return None
f()
```

### Versions

```
python3 -c "import torch; print(torch.__version__)"
2.5.0a0+git4bae7ae
```

cc @ezyang @albanD @gqchen @pearu @nikitaved @soulitzer @Varal7 @xmfan @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @amjames @rec