# Feature: Pattern Matcher Observability

**URL:** <https://dev-discuss.pytorch.org/t/feature-pattern-matcher-observability/3321>\
**Category:** compiler\
**Created:** [March 10, 2026, 3:26pm UTC](https://dev-discuss.pytorch.org/t/feature-pattern-matcher-observability/3321 "2026-03-10T15:26:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![morrison-turnansky](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/morrison-turnansky/32/3135_2.png) [@morrison-turnansky](https://dev-discuss.pytorch.org/u/morrison-turnansky)\
**Post date:** [March 10, 2026, 3:26pm UTC](https://dev-discuss.pytorch.org/t/feature-pattern-matcher-observability/3321/1 "2026-03-10T15:26:40Z")

</div>

# Pattern Matcher Observability

## Summary

This RFC proposes adding opt-in debugging and observability features to the TorchInductor Patter Matcher. These features will help developers understand which patterns are applied, track per-pattern statistics and debug pattern matching issues during torch.compile() all without changing default behavior.

## Problem Statement

The Pattern Matcher is a critical optimization component in TorchInductor that performs graph transformations via search/replace patterns. Despite its importance, developers have limited visibility into its operation.

### Current capabilities

| Capability | Current State |

|------------|---------------|

| Debug pattern matching | Available via TORCHINDUCTOR\_PATTERN\_MATCH\_DEBUG=\<node\_name\> |

| See failure reasons | Available (using env var above) |

| Track pattern counts | Aggregate only |

| Debug multiple nodes | Not available |

| Log all applied patterns | Not available |

| Per pattern counts | Not available |

### Current Limitations

- \*\*Single node only\*\*

- Must specify exact node name; cannot debug multiple nodes or all nodes

- \*\*Must know node name in advance\*\*

- Requires dumping graph first to find node names

- \*\*No summary view\*\*

- No aggregate statistics showing which patterns applied or failed

- \*\*No documentation\*\*

- Users must discover these features by reading source code

## Benefits

- \*\*Compiler developers\*\*: Identify slow patterns or patterns that frequently fail matching

- \*\*Model developers\*\*: Understand which optimizations torch.compile() applies to their model

- \*\*Pattern authors\*\*: Verify new patterns are correctly applied during development

## Proposed Features

### Feature 1: Enhanced Debug Mode

Extend TORCHINDUCTOR\_PATTERN\_MATCH\_DEBUG to support multiple nodes.

\*\*Current Behavior:\*\*

- TORCHINDUCTOR\_PATTERN\_MATCH\_DEBUG=add → debugs only node named exactly “add”

\*\*Proposed Behavior:\*\*

- TORCHINDUCTOR\_PATTERN\_MATCH\_DEBUG=add → same as before (backward compatible)

- TORCHINDUCTOR\_PATTERN\_MATCH\_DEBUG=add,mul,mm → debug multiple nodes

- TORCHINDUCTOR\_PATTERN\_MATCH\_DEBUG=all → debug all nodes

### Feature 2: Per-Pattern Type Tracking

Track how many times each specific pattern type is applied, not just aggregate totals.

\*\*Current Output (aggregate only)\*\*

## Backward Compatibility

| Aspect | Status |

|--------|--------|

| Default behavior | Unchanged |

| Existing env vars | TORCHINDUCTOR\_PATTERN\_MATCH\_DEBUG= works exactly as before |

| Existing failure messages | Preserved format unchanged |

| Public APIs | No breaking changes |

## Proposed Environment Variables

| Variable | Purpose | Values |

|----------|---------|--------|

| TORCHINDUCTOR\_PATTERN\_MATCH\_DEBUG | Debug specific nodes (existing) | \<node\_name\>, ,, all |

---

<div class="post-metadata">

**Author:** ![morrison-turnansky](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/morrison-turnansky/32/3135_2.png) [@morrison-turnansky](https://dev-discuss.pytorch.org/u/morrison-turnansky)\
**Post date:** [March 10, 2026, 3:44pm UTC](https://dev-discuss.pytorch.org/t/feature-pattern-matcher-observability/3321/2 "2026-03-10T15:44:03Z")

</div>

For an implementation see the draft PR at [RFC: Increase Pattern Matcher Observability by morrison-turnansky · Pull Request #177032 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/pull/177032)
