Autodeploy: Add Fusion Transformation Pass
Where this skill applies
This file lives in the trtllm-agent-toolkit plugin. Paths such as tensorrt_llm/..., examples/auto_deploy/..., and tests/... are relative to a TensorRT-LLM source checkout on the user’s machine — not the plugin tree.
After installing the plugin (see the toolkit README.md), skills use the trtllm-agent-toolkit: prefix (for example trtllm-agent-toolkit:ad-add-fusion-transformation).
Related skills in this plugin
| Skill |
Use it for |
| ad-graph-dump |
Enabling AD_DUMP_GRAPHS_DIR, dump file layout, and how to read SSA graph output. |
| trtllm-codebase-exploration |
Mapping existing transforms, custom ops, and search patterns before writing a pass. |
| trtllm-code-contribution |
TensorRT-LLM pre-commit, tests, DCO sign-off, and PR expectations. |
| triton-kernel-writing |
Implementing a Triton op only after existing-kernel lookup fails. |
| triton-tileir-optimization |
Tuning existing Triton kernels for the TileIR backend when that path applies. |
Use this skill when you already know which subgraph or pattern you are targeting (from graph dumps, logs, or code reading). For dump capture and file semantics, follow ad-graph-dump first.
When to use this skill
- Adding, extending, or reviewing a fusion under AutoDeploy transforms in a TensorRT-LLM tree.
Workflow (concise)
- Confirm the pattern in current graph dumps (see ad-graph-dump).
- Search for an existing kernel or custom-op path before new Triton or CUDA.
- Implement the smallest change that proves correctness and matching; add tests.
- Re-run dumps and tests; if outputs drift, separate matching issues from metadata loss from numeric differences.
Finding fusion candidates (lightweight)
Do this before writing a new pass so you work on real graph structure.
Inputs
- Graph dump directory from a run with
AD_DUMP_GRAPHS_DIR set (see ad-graph-dump).
- Model id and active AutoDeploy config (registry YAML,
default.yaml overlays).
- TensorRT-LLM source tree for kernel and transform lookup.
Outputs
- Ordered list of candidates with: graph evidence, existing-kernel lookup (
found / not_found), recommendation (use_existing_kernel, needs_triton_fallback, defer), and trade-offs (complexity, correctness risk).
Discovery workflow
- Parse dumps for repeated unfused patterns (element-wise chains, norm chains, epilogues, attention-adjacent ops).
- Search the tree for equivalent transforms or custom ops; record file/symbol evidence.
- If nothing fits, mark Triton or other kernel work as a deliberate fallback.
- Prefer candidates with clear recurrence, existing support, and lower numerical risk.
Per-candidate template
Candidate: <short-name>
Affected graph pattern: <pattern>
Existing kernel lookup: <found|not_found>
Evidence: <path/symbol>
Recommendation: <use_existing_kernel|needs_triton_fallback|defer>
Strengths / weaknesses / risks:
- ...
Guardrails
- Do not skip existing-kernel lookup.
- Do not default to Triton when a viable existing op already exists.
- If uncertain,
defer and narrow the question with one more dump or test.
Inputs (implementation)
- Chosen candidate or concrete subgraph.
- Active model and config files.
- Fresh graph dumps when available.
- Current baseline: match counts from logs, unit test status, any accuracy notes you already maintain.
Outputs (implementation)
- Pass design or patch: registered transform,
default.yaml entry, optional model-registry YAML.
- Path decision:
existing_kernel_path vs triton_fallback_path (or other kernel stack).
- Validation notes: graph evidence,
[SUMMARY] matches=... before/after from AutoDeploy logs, test results.
Implementation workflow
- Align the pass with observed graph structure from dumps — not assumed op names from docs alone.
- Search
transform/library/, custom_ops/, torch.ops.auto_deploy.*, and related tests for reuse.
- Integrate an existing op when possible; otherwise delegate kernel work to the appropriate skill (triton-kernel-writing, cuda-kernel-writing, etc.).
- Keep one logical change per patch; extend tests in the same change.
- Re-read dumps after the change; if match counts collapse, suspect pattern availability or metadata propagation.
Where fusion passes live
- Transforms:
tensorrt_llm/_torch/auto_deploy/transform/library/
- Registry / base behavior:
tensorrt_llm/_torch/auto_deploy/transform/interface.py
- Default transform list:
tensorrt_llm/_torch/auto_deploy/config/default.yaml
- Dump helper:
tensorrt_llm/_torch/auto_deploy/utils/graph_writer.py
- Graph utilities:
tensorrt_llm/_torch/auto_deploy/utils/node_utils.py, tensorrt_llm/_torch/auto_deploy/utils/_graph.py
- Custom ops:
tensorrt_llm/_torch/auto_deploy/custom_ops/
Tests (typical):
tests/unittest/auto_deploy/singlegpu/transformations/library/
tests/integration/defs/accuracy/test_llm_api_autodeploy.py (when behavior or numerics may change)
How to add a transform
Implement the pass
Create or update a module under transform/library/ and register the class:
@TransformRegistry.register("my_transform_key")
class MyTransform(BaseTransform):
@classmethod
def get_config_class(cls):
return MyTransformConfig
Use a dedicated config class only when the pass needs parameters beyond the base transform config.
Register in default.yaml
Add a key under transforms: in tensorrt_llm/_torch/auto_deploy/config/default.yaml. Copy the field set from the closest existing transform in the same section of the file (required keys depend on the transform config class and on how peers are declared). New experimental passes should stay enabled: false until covered by tests and dumps.
Enable for a specific model
For targeted rollout, adjust registry YAMLs under examples/auto_deploy/model_registry/configs/ rather than turning on unproven passes globally.
Implementation rules
- Prefer existing AutoDeploy / TRT-LLM ops and
torch.ops.auto_deploy entries.
- Prefer stable, backend-neutral graph contracts; avoid hiding real dataflow in
node.meta when an edge should carry it.
- Use metadata for observable tensor facts (shape, dtype) and preserve it across rewrites when replacements should remain traceable.
- One hypothesis per patch — do not mix unrelated fusions.
Existing kernel first, Triton second
Before Triton:
- Search
transform/library/ and custom_ops/.
- Search
torch.ops.auto_deploy.* and TRT-LLM custom op definitions.
- Read tests for similar integrations.
Use triton-kernel-writing only when no suitable op exists and you accept owning kernel + integration work.
Validation order
- Graph dumps — pattern present, rewrite visible (see ad-graph-dump).
- Unit tests for the transform.
- Integration or accuracy checks when numerics or end-to-end behavior may change.
Match counts
AutoDeploy logs [SUMMARY] matches=<n> (or skipped / disabled) per transform. Compare before and after your change; a large drop usually indicates pattern or metadata issues, not “slow runs.”
Testing expectations
Follow trtllm-code-contribution for repo conventions. Cover:
- Happy-path micrograph or exported-graph rewrites.
- Failure modes that must not fuse (multiple consumers, mixed consumers).
- Metadata preservation when an upstream pass feeds your pattern.
Primary unittest location for library transforms:
tests/unittest/auto_deploy/singlegpu/transformations/library/
Review checklist
- Target structure appears in current dumps.
- Transform registered and listed in
default.yaml consistently with peer entries.
- Model-registry toggles are intentional.
- Non-zero
matches where expected, or skipped is explained.
- Before/after dump snippets or diffs saved for the review thread.
- Tests cover both success and intentional non-match cases.
- If outputs change, classify match loss vs metadata loss vs acceptable numeric drift.
Guardrails
- Do not bundle unrelated passes in one change.
- If dumps contradict expectations, document what you observed before chasing unrelated hypotheses.
Iteration note (template)
Candidate: <name>
Path: <existing_kernel_path|triton_fallback_path|other>
Rationale:
- ...
Graph validation: <pass|fail — what files / ops>
Summary logs: <matches before / after>
Tests: <what ran>
Open risks:
- ...
1---2name: nvidia-tensorrt-llm-ad-add-fusion-transformation3description: 'Claude Code skill (trtllm-agent-toolkit): implement or extend TensorRT-LLM4 AutoDeploy fusion transforms under transform/library/ in a TensorRT-LLM checkout.5 Prefer existing kernels and custom ops; use Triton only when no viable existing-kernel6 path exists. Use ad-graph-dump for AD_DUMP_GRAPHS_DIR workflows. Covers TRT-LLM7 paths, registry, default.yaml registration, graph validation, tests, and a review8 checklist — without prescribing profiling tools or throughput targets.910 '11license: Apache-2.012metadata:13 author: NVIDIA Corporation14 tags:15 - tensorrt-llm16 - autodeploy17 - fusion18 - graph-transform19 - optimization20---2122# Autodeploy: Add Fusion Transformation Pass2324## Where this skill applies2526This file lives in the **trtllm-agent-toolkit** plugin. Paths such as `tensorrt_llm/...`, `examples/auto_deploy/...`, and `tests/...` are relative to a **TensorRT-LLM source checkout** on the user’s machine — not the plugin tree.2728After installing the plugin (see the toolkit `README.md`), skills use the `trtllm-agent-toolkit:` prefix (for example `trtllm-agent-toolkit:ad-add-fusion-transformation`).2930## Related skills in this plugin3132| Skill | Use it for |33|-------|------------|34| **ad-graph-dump** | Enabling `AD_DUMP_GRAPHS_DIR`, dump file layout, and how to read SSA graph output. |35| **trtllm-codebase-exploration** | Mapping existing transforms, custom ops, and search patterns before writing a pass. |36| **trtllm-code-contribution** | TensorRT-LLM pre-commit, tests, DCO sign-off, and PR expectations. |37| **triton-kernel-writing** | Implementing a **Triton** op only after existing-kernel lookup fails. |38| **triton-tileir-optimization** | Tuning **existing** Triton kernels for the TileIR backend when that path applies. |3940Use this skill when you already know **which subgraph or pattern** you are targeting (from graph dumps, logs, or code reading). For dump capture and file semantics, follow **ad-graph-dump** first.4142## When to use this skill4344- Adding, extending, or reviewing a fusion under AutoDeploy transforms in a TensorRT-LLM tree.4546### Workflow (concise)47481. Confirm the pattern in **current** graph dumps (see **ad-graph-dump**).492. Search for an existing kernel or custom-op path before new Triton or CUDA.503. Implement the smallest change that proves correctness and matching; add tests.514. Re-run dumps and tests; if outputs drift, separate matching issues from metadata loss from numeric differences.5253## Finding fusion candidates (lightweight)5455Do this before writing a new pass so you work on real graph structure.5657### Inputs5859- Graph dump directory from a run with `AD_DUMP_GRAPHS_DIR` set (see **ad-graph-dump**).60- Model id and active AutoDeploy config (registry YAML, `default.yaml` overlays).61- TensorRT-LLM source tree for kernel and transform lookup.6263### Outputs6465- Ordered list of candidates with: graph evidence, existing-kernel lookup (`found` / `not_found`), recommendation (`use_existing_kernel`, `needs_triton_fallback`, `defer`), and trade-offs (complexity, correctness risk).6667### Discovery workflow68691. Parse dumps for repeated unfused patterns (element-wise chains, norm chains, epilogues, attention-adjacent ops).702. Search the tree for equivalent transforms or custom ops; record file/symbol evidence.713. If nothing fits, mark Triton or other kernel work as a deliberate fallback.724. Prefer candidates with clear recurrence, existing support, and lower numerical risk.7374### Per-candidate template7576```text77Candidate: <short-name>78Affected graph pattern: <pattern>79Existing kernel lookup: <found|not_found>80Evidence: <path/symbol>81Recommendation: <use_existing_kernel|needs_triton_fallback|defer>82Strengths / weaknesses / risks:83- ...84```8586### Guardrails8788- Do not skip existing-kernel lookup.89- Do not default to Triton when a viable existing op already exists.90- If uncertain, `defer` and narrow the question with one more dump or test.9192---9394## Inputs (implementation)9596- Chosen candidate or concrete subgraph.97- Active model and config files.98- Fresh graph dumps when available.99- Current baseline: match counts from logs, unit test status, any accuracy notes you already maintain.100101## Outputs (implementation)102103- Pass design or patch: registered transform, `default.yaml` entry, optional model-registry YAML.104- Path decision: `existing_kernel_path` vs `triton_fallback_path` (or other kernel stack).105- Validation notes: graph evidence, `[SUMMARY] matches=...` before/after from AutoDeploy logs, test results.106107## Implementation workflow1081091. Align the pass with **observed** graph structure from dumps — not assumed op names from docs alone.1102. Search `transform/library/`, `custom_ops/`, `torch.ops.auto_deploy.*`, and related tests for reuse.1113. Integrate an existing op when possible; otherwise delegate kernel work to the appropriate skill (**triton-kernel-writing**, **cuda-kernel-writing**, etc.).1124. Keep one logical change per patch; extend tests in the same change.1135. Re-read dumps after the change; if match counts collapse, suspect pattern availability or metadata propagation.114115## Where fusion passes live116117- Transforms: `tensorrt_llm/_torch/auto_deploy/transform/library/`118- Registry / base behavior: `tensorrt_llm/_torch/auto_deploy/transform/interface.py`119- Default transform list: `tensorrt_llm/_torch/auto_deploy/config/default.yaml`120- Dump helper: `tensorrt_llm/_torch/auto_deploy/utils/graph_writer.py`121- Graph utilities: `tensorrt_llm/_torch/auto_deploy/utils/node_utils.py`, `tensorrt_llm/_torch/auto_deploy/utils/_graph.py`122- Custom ops: `tensorrt_llm/_torch/auto_deploy/custom_ops/`123124Tests (typical):125126- `tests/unittest/auto_deploy/singlegpu/transformations/library/`127- `tests/integration/defs/accuracy/test_llm_api_autodeploy.py` (when behavior or numerics may change)128129## How to add a transform130131### Implement the pass132133Create or update a module under `transform/library/` and register the class:134135```python136@TransformRegistry.register("my_transform_key")137class MyTransform(BaseTransform):138 @classmethod139 def get_config_class(cls):140 return MyTransformConfig141```142143Use a dedicated config class only when the pass needs parameters beyond the base transform config.144145### Register in `default.yaml`146147Add a key under `transforms:` in `tensorrt_llm/_torch/auto_deploy/config/default.yaml`. **Copy the field set from the closest existing transform** in the same section of the file (required keys depend on the transform config class and on how peers are declared). New experimental passes should stay **`enabled: false`** until covered by tests and dumps.148149### Enable for a specific model150151For targeted rollout, adjust registry YAMLs under `examples/auto_deploy/model_registry/configs/` rather than turning on unproven passes globally.152153## Implementation rules154155- Prefer existing AutoDeploy / TRT-LLM ops and `torch.ops.auto_deploy` entries.156- Prefer stable, backend-neutral graph contracts; avoid hiding real dataflow in `node.meta` when an edge should carry it.157- Use metadata for observable tensor facts (shape, dtype) and preserve it across rewrites when replacements should remain traceable.158- **One hypothesis per patch** — do not mix unrelated fusions.159160## Existing kernel first, Triton second161162Before Triton:1631641. Search `transform/library/` and `custom_ops/`.1652. Search `torch.ops.auto_deploy.*` and TRT-LLM custom op definitions.1663. Read tests for similar integrations.167168Use **triton-kernel-writing** only when no suitable op exists and you accept owning kernel + integration work.169170## Validation order1711721. Graph dumps — pattern present, rewrite visible (see **ad-graph-dump**).1732. Unit tests for the transform.1743. Integration or accuracy checks when numerics or end-to-end behavior may change.175176## Match counts177178AutoDeploy logs `[SUMMARY] matches=<n>` (or `skipped` / `disabled`) per transform. Compare before and after your change; a large drop usually indicates pattern or metadata issues, not “slow runs.”179180## Testing expectations181182Follow **trtllm-code-contribution** for repo conventions. Cover:183184- Happy-path micrograph or exported-graph rewrites.185- Failure modes that must **not** fuse (multiple consumers, mixed consumers).186- Metadata preservation when an upstream pass feeds your pattern.187188Primary unittest location for library transforms:189190- `tests/unittest/auto_deploy/singlegpu/transformations/library/`191192## Review checklist193194- Target structure appears in current dumps.195- Transform registered and listed in `default.yaml` consistently with peer entries.196- Model-registry toggles are intentional.197- Non-zero `matches` where expected, or `skipped` is explained.198- Before/after dump snippets or diffs saved for the review thread.199- Tests cover both success and intentional non-match cases.200- If outputs change, classify match loss vs metadata loss vs acceptable numeric drift.201202## Guardrails203204- Do not bundle unrelated passes in one change.205- If dumps contradict expectations, document what you observed before chasing unrelated hypotheses.206207## Iteration note (template)208209```text210Candidate: <name>211Path: <existing_kernel_path|triton_fallback_path|other>212Rationale:213- ...214Graph validation: <pass|fail — what files / ops>215Summary logs: <matches before / after>216Tests: <what ran>217Open risks:218- ...219```