Repository: pytorch
Issue: [Inductor] Request to support get_attr in pattern matcher
Labels: triaged,oncall: pt2,module: inductor

### Description
It is found currently that `DistilBert` using [`torch.Tensor`](https://github.com/huggingface/transformers/blob/main/src/transformers/models/distilbert/modeling_distilbert.py#L246) generates an op `get_attr` when tracing, which is not supported by pattern matcher. This leads to the failure of making `DistilBert` go into SDPA with pattern matcher, to get a better perf.

The related part of `DistilBert`'s graph is as follows:
```
graph:
    %_tensor_constant0 : [num_users=1] = get_attr[target=_tensor_constant0]
    %lift_fresh_copy : [num_users=0] = call_function[target=torch.ops.aten.lift_fresh_copy.default](args = (%_tensor_constant0,), kwargs = {})
```

### Traceback
```
Traceback (most recent call last):
  File "/home/liaoxuan/pytorch/torch/testing/_internal/common_utils.py", line 1555, in wrapper
    return fn(*args, **kwargs)
  File "test/inductor/test_fused_attention.py", line 685, in _test_sdpa_rewriter_17
    self._check_common(dot_prod_attention, check_train=False, has_dropout=True)
  File "test/inductor/test_fused_attention.py", line 78, in _check_common
    result2, source_code = run_and_get_code(
  File "/home/liaoxuan/pytorch/torch/_inductor/utils.py", line 933, in run_and_get_code
    result = fn(*args, **kwargs)
  File "/home/liaoxuan/pytorch/torch/_dynamo/eval_frame.py", line 417, in _fn
    return fn(*args, **kwargs)
  File "/home/liaoxuan/pytorch/torch/_dynamo/eval_frame.py", line 580, in catch_errors
    return callback(frame, cache_entry, hooks, frame_state)
  File "/home/liaoxuan/pytorch/torch/_dynamo/convert_frame.py", line 386, in _convert_frame_assert
    return _compile(
  File "/home/liaoxuan/pytorch/torch/_dynamo/convert_frame.py", line 645, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "/home/liaoxuan/pytorch/torch/_dynamo/utils.py", line 247, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/liaoxuan/pytorch/torch/_dynamo/convert_frame.py", line 526, in compile_inner
    out_code = transform_code_object(code, transform)
  File "/home/liaoxuan/pytorch/torch/_dynamo/bytecode_transformation.py", line 1033, in transform_code_object
    transformations(instructions, code_options)
  File "/home/liaoxuan/pytorch/torch/_dynamo/convert_frame.py", line 151, in _fn
    return fn(*args, **kwargs)
  File "/home/liaoxuan/pytorch/torch/_dynamo/convert_frame.py", line 491, in transform
    tracer.run()
  File "/home/liaoxuan/pytorch/torch/_dynamo/symbolic_convert.py", line 2097, in run
    super().run()
  File "/home/liaoxuan/pytorch/torch/_dynamo/symbolic_convert.py", line 780, in run
    and self.step()
  File "/home/liaoxuan/pytorch/torch/_dynamo/symbolic_convert.py", line 743, in step
    getattr(self, inst.opname)(inst)
  File "/home/liaoxuan/pytorch/torch/_dynamo/symbolic_convert.py", line 2215, in RETURN_VALUE
    self.output.compile_subgraph(
  File "/home/liaoxuan/pytorch/torch/_dynamo/output_graph.py", line 914, in compile_subgraph
    self.compile_and_call_fx_graph(tx, list(reversed(stack_values)), root)
  File "/home/liaoxuan/anaconda3/envs/flash/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/home/liaoxuan/pytorch/torch/_dynamo/output_graph.py", line 1085, in compile_and_call_fx_graph
    compiled_fn = self.call_user_compiler(gm)
  File "/home/liaoxuan/pytorch/torch/_dynamo/utils.py", line 247, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/liaoxuan/pytorch/torch/_dynamo/output_graph.py", line 1157, in call_user_compiler
    raise BackendCompilerFailed(self.compiler_fn, e).with_traceback(
  File "/home/liaoxuan/pytorch/torch/_dynamo/output_graph.py", line 1138, in call_user_compiler
    compiled_fn = compiler_fn(gm, self.example_inputs())
  File "/home/liaoxuan/pytorch/torch/_dynamo/repro/after_dynamo.py", line 117, in debug_wrapper
    compiled_gm = compiler_fn(gm, example_inputs)
  File "/home/liaoxuan/pytorch/torch/_dynamo/repro/after_dynamo.py", line 117, in debug_wrapper
    compiled_gm = compiler_fn(gm, example_inputs)
  File "/home/liaoxuan/pytorch/torch/__init__.py", line 1714, in __call__
    return compile_fx(model_, inputs_, config_patches=self.config)
  File "/home/liaoxuan/pytorch/torch/_inductor/compile_fx.py", line 1177, in compile_fx
    return aot_autograd(
  File "/home/liaoxuan/pytorch/torch/_dynamo/backends/common.py", line 55, in compiler_fn
    cg = aot_module_simplified(gm, example_inputs, **kwargs)
  File "/home/liaoxuan/pytorch/torch/_functorch/aot_autograd.py", line 889, in aot_module_simplified
    compiled_fn = create_aot_dispatcher_function(
  File "/home/liaoxuan/pytorch/torch/_dynamo/utils.py", line 247, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/liaoxuan/pytorch/torch/_functorch/aot_autograd.py", line 602, in create_aot_dispatcher_function
    compiled_fn = compiler_fn(flat_fn, fake_flat_args, aot_config, fw_metadata=fw_metadata)
  File "/home/liaoxuan/pytorch/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 434, in aot_wrapper_dedupe
    return compiler_fn(flat_fn, leaf_flat_args, aot_config, fw_metadata=fw_metadata)
  File "/home/liaoxuan/pytorch/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 639, in aot_wrapper_synthetic_base
    return compiler_fn(flat_fn, flat_args, aot_config, fw_metadata=fw_metadata)
  File "/home/liaoxuan/pytorch/torch/_functorch/_aot_autograd/jit_compile_runtime_wrappers.py", line 97, in aot_dispatch_base
    compiled_fw = compiler(fw_module, updated_flat_args)
  File "/home/liaoxuan/pytorch/torch/_dynamo/utils.py", line 247, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/liaoxuan/pytorch/torch/_inductor/compile_fx.py", line 1048, in fw_compiler_base
    joint_graph_passes(model)
  File "/home/liaoxuan/pytorch/torch/_inductor/fx_passes/joint_graph.py", line 267, in joint_graph_passes
    lazy_init()
  File "/home/liaoxuan/pytorch/torch/_inductor/pattern_matcher.py", line 1396, in lazy_init
    result = fn()
  File "/home/liaoxuan/pytorch/torch/_inductor/fx_passes/joint_graph.py", line 34, in lazy_init
    _sfdp_init()
  File "/home/liaoxuan/pytorch/torch/_inductor/fx_passes/fuse_attention.py", line 729, in _sfdp_init
    register_replacement(
  File "/home/liaoxuan/pytorch/torch/_inductor/pattern_matcher.py", line 1020, in register_replacement
    pattern = gen_pattern(
  File "/home/liaoxuan/anaconda3/envs/flash/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/home/liaoxuan/pytorch/torch/_inductor/pattern_matcher.py", line 1062, in gen_pattern
    return fx_to_pattern(
  File "/home/liaoxuan/pytorch/torch/_inductor/pattern_matcher.py", line 1282, in fx_to_pattern
    pattern = Converter(gm).run()
  File "/home/liaoxuan/pytorch/torch/fx/interpreter.py", line 144, in run
    self.env[node] = self.run_node(node)
  File "/home/liaoxuan/pytorch/torch/_inductor/pattern_matcher.py", line 1273, in run_node
    rv = super().run_node(n)
  File "/home/liaoxuan/pytorch/torch/fx/interpreter.py", line 201, in run_node
    return getattr(self, n.op)(n.target, args, kwargs)
  File "/home/liaoxuan/pytorch/torch/_inductor/pattern_matcher.py", line 1213, in _not_implemented
    raise NotImplementedError()
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
NotImplementedError: While executing %_tensor_constant0_1 : [num_users=1] = get_attr[target=_tensor_constant0]
```


### Reproduce
Based on https://github.com/pytorch/pytorch/pull/113004, change the line in `_sfdp_pattern_17` from `fill_value = torch.full((), -float("inf"), dtype=query.dtype, device=query.device)` to `fill_value = torch.tensor(torch.finfo(scores.dtype).min)` (same as the code in `DistilBert`).

Then, run `python test/inductor/test_fused_attention.py -k test_sdpa_rewriter_17`.

cc @ezyang @msaroufim @bdhirsh @anijain2305 @zou3519 @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov @ColinPeppler @leslie-fang-intel