# torch 2.15.0 (BSD-3-Clause), harvested by tools/harvest_corpus.py
=== input

# Inductor Pattern Matcher

The pattern matcher enables search/replace within an FX graph.

The main entrypoint to the pattern matcher is register_replacement(). Given a
search function and a replacement function this will register a replacement with
a pass (such as torch._inductor.fx_passes.joint_graph.patterns).

Internally the pattern matcher represents patterns as a graph (a DAG). Creating
new patterns manually as a graph is cumbersome and error-prone so the standard
way to create patterns (using register_replacement()) is to provide a search
function and a replacement function which is traced and converted into a graph.

Because the search functions are built somewhat generic (they tend to ignore
tensor sizes, for example) register_replacement() allows you to specify an
`extra_check` function which performs additional checks to verify that the
matched pattern fully matches before returning it.

## Precompiled Patterns

New patterns are added using register_replacement(). Patterns added in this way
can have a compile-time overhead because they need to be traced before
use. Patterns can be precompiled and added using gen_register_replacement()
instead. To do this you call gen_register_replacement() instead of
register_replacement(). The arguments are the same except for an additional
unique name which is used as a lookup key.

## Internals

The match DAG is represented by a graph of `PatternExpr` nodes. Each PatternExpr
implements a `_match` method which returns either a `Match` object for a
successful match or a `FailedMatch` object for a failure to match.

=== parse google
short_description: '# Inductor Pattern Matcher'
long_description: |
  The pattern matcher enables search/replace within an FX graph.
  
  The main entrypoint to the pattern matcher is register_replacement(). Given a
  search function and a replacement function this will register a replacement with
  a pass (such as torch._inductor.fx_passes.joint_graph.patterns).
  
  Internally the pattern matcher represents patterns as a graph (a DAG). Creating
  new patterns manually as a graph is cumbersome and error-prone so the standard
  way to create patterns (using register_replacement()) is to provide a search
  function and a replacement function which is traced and converted into a graph.
  
  Because the search functions are built somewhat generic (they tend to ignore
  tensor sizes, for example) register_replacement() allows you to specify an
  `extra_check` function which performs additional checks to verify that the
  matched pattern fully matches before returning it.
  
  ## Precompiled Patterns
  
  New patterns are added using register_replacement(). Patterns added in this way
  can have a compile-time overhead because they need to be traced before
  use. Patterns can be precompiled and added using gen_register_replacement()
  instead. To do this you call gen_register_replacement() instead of
  register_replacement(). The arguments are the same except for an additional
  unique name which is used as a lookup key.
  
  ## Internals
  
  The match DAG is represented by a graph of `PatternExpr` nodes. Each PatternExpr
  implements a `_match` method which returns either a `Match` object for a
  successful match or a `FailedMatch` object for a failure to match.
blank_after_short_description: True
blank_after_long_description: False
style: google
=== detect
rest
=== compose google
# Inductor Pattern Matcher

The pattern matcher enables search/replace within an FX graph.

The main entrypoint to the pattern matcher is register_replacement(). Given a
search function and a replacement function this will register a replacement with
a pass (such as torch._inductor.fx_passes.joint_graph.patterns).

Internally the pattern matcher represents patterns as a graph (a DAG). Creating
new patterns manually as a graph is cumbersome and error-prone so the standard
way to create patterns (using register_replacement()) is to provide a search
function and a replacement function which is traced and converted into a graph.

Because the search functions are built somewhat generic (they tend to ignore
tensor sizes, for example) register_replacement() allows you to specify an
`extra_check` function which performs additional checks to verify that the
matched pattern fully matches before returning it.

## Precompiled Patterns

New patterns are added using register_replacement(). Patterns added in this way
can have a compile-time overhead because they need to be traced before
use. Patterns can be precompiled and added using gen_register_replacement()
instead. To do this you call gen_register_replacement() instead of
register_replacement(). The arguments are the same except for an additional
unique name which is used as a lookup key.

## Internals

The match DAG is represented by a graph of `PatternExpr` nodes. Each PatternExpr
implements a `_match` method which returns either a `Match` object for a
successful match or a `FailedMatch` object for a failure to match.
