Repository: pytorch
Issue: inspect.Signature with functools.partial partially applying tensors doesn't work
Labels: high priority,triaged,oncall: pt2,module: dynamo

### 🐛 Describe the bug

```
import torch
from triton.testing import do_bench
from torch.nn.attention.flex_attention import create_block_mask, flex_attention, noop_mask, BlockMask
import torch.nn.functional as F
import functools

torch.manual_seed(0)

import torch
torch.set_default_device('cuda')

def sliding_window(b, h, q_idx, kv_idx, val):
    return (q_idx - kv_idx).abs() < val

sliding_window2 = functools.partial(sliding_window, val=torch.randn(()))
torch.compile(create_block_mask, fullgraph=True)(sliding_window2, None, None, 1024, 1024)
```

```
Traceback (most recent call last):
  File "/home/chilli/local/pytorch/torch/_dynamo/variables/misc.py", line 383, in __init__
    self.fn = self.inspected.get_function()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/variables/functions.py", line 908, in get_function
    return self.as_python_constant()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/variables/functions.py", line 930, in as_python_constant
    **{k: v.as_python_constant() for k, v in self.keywords.items()},
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/variables/functions.py", line 930, in <dictcomp>
    **{k: v.as_python_constant() for k, v in self.keywords.items()},
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/variables/base.py", line 219, in as_python_constant
    raise NotImplementedError(f"{self} is not a constant")
NotImplementedError: TensorVariable() is not a constant

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/users/chilli/repro.py", line 196, in <module>
    block_mask = get_cp_flex_attn_bias("block_causal", tokens, eos_id=1)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/users/chilli/repro.py", line 190, in get_cp_flex_attn_bias
    cp_flex_attn_bias.block_mask = torch.compile(create_block_mask, fullgraph=True)(**kwargs)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/eval_frame.py", line 554, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/convert_frame.py", line 1371, in __call__
    return self._torchdynamo_orig_callable(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/convert_frame.py", line 544, in __call__
    return _compile(
           ^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/convert_frame.py", line 967, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/convert_frame.py", line 695, in compile_inner
    return _compile_inner(code, one_graph, hooks, transform)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_utils_internal.py", line 95, in wrapper_function
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/convert_frame.py", line 728, in _compile_inner
    out_code = transform_code_object(code, transform)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/bytecode_transformation.py", line 1337, in transform_code_object
    transformations(instructions, code_options)
  File "/home/chilli/local/pytorch/torch/_dynamo/convert_frame.py", line 229, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/convert_frame.py", line 657, in transform
    tracer.run()
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 2892, in run
    super().run()
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 1100, in run
    while self.step():
          ^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 1012, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 620, in wrapper
    return inner_fn(self, inst)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 2399, in CALL
    self._call(inst)
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 2393, in _call
    self.call_function(fn, args, kwargs)
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 947, in call_function
    self.push(fn.call_function(self, args, kwargs))  # type: ignore[arg-type]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/variables/functions.py", line 345, in call_function
    return super().call_function(tx, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/variables/functions.py", line 124, in call_function
    return tx.inline_user_function_return(self, [*self.self_args(), *args], kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 953, in inline_user_function_return
    return InliningInstructionTranslator.inline_call(self, fn, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 3107, in inline_call
    return cls.inline_call_(parent, func, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 3235, in inline_call_
    tracer.run()
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 1100, in run
    while self.step():
          ^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 1012, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 620, in wrapper
    return inner_fn(self, inst)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 2399, in CALL
    self._call(inst)
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 2393, in _call
    self.call_function(fn, args, kwargs)
  File "/home/chilli/local/pytorch/torch/_dynamo/symbolic_convert.py", line 947, in call_function
    self.push(fn.call_function(self, args, kwargs))  # type: ignore[arg-type]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/variables/misc.py", line 963, in call_function
    return self.fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/variables/misc.py", line 373, in create
    return InspectSignatureVariable(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chilli/local/pytorch/torch/_dynamo/variables/misc.py", line 389, in __init__
    unimplemented("inspect.signature with non-constant function")
  File "/home/chilli/local/pytorch/torch/_dynamo/exc.py", line 305, in unimplemented
    raise Unsupported(msg, case_name=case_name)
torch._dynamo.exc.Unsupported: inspect.signature with non-constant function

```
cc: @williamwen42 @anijain2305 

### Versions

N/A

cc @ezyang @gchanan @zou3519 @kadeng @msaroufim @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @amjames