Ad add fusion transformation

From wenyi-li/awesome-agent-kernel-skills · View interactive version

Ad add fusion transformation is an AI agent skill from the GitHub repository wenyi-li/awesome-agent-kernel-skills. Claude Code skill (trtllm-agent-toolkit): implement or extend TensorRT-LLM AutoDeploy fusion transforms under transform/library/ in a TensorRT-LLM checkout. Prefer existing kernels and custom ops; use Triton only when no viable existing-kernel path exists. Use ad-graph-dump for AD_DUMP_GRAPHS_DIR wo

How to use this skill

Skill file

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

Workflow (concise)

  1. Confirm the pattern in current graph dumps (see ad-graph-dump).
  2. Search for an existing kernel or custom-op path before new Triton or CUDA.
  3. Implement the smallest change that proves correctness and matching; add tests.
  4. 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

Outputs

Discovery workflow

  1. Parse dumps for repeated unfused patterns (element-wise chains, norm chains, epilogues, attention-adjacent ops).
  2. Search the tree for equivalent transforms or custom ops; record file/symbol evidence.
  3. If nothing fits, mark Triton or other kernel work as a deliberate fallback.
  4. 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


Inputs (implementation)

Outputs (implementation)

Implementation workflow

  1. Align the pass with observed graph structure from dumps — not assumed op names from docs alone.
  2. Search transform/library/, custom_ops/, torch.ops.auto_deploy.*, and related tests for reuse.
  3. Integrate an existing op when possible; otherwise delegate kernel work to the appropriate skill (triton-kernel-writing, cuda-kernel-writing, etc.).
  4. Keep one logical change per patch; extend tests in the same change.
  5. Re-read dumps after the change; if match counts collapse, suspect pattern availability or metadata propagation.

Where fusion passes live

Tests (typical):

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

Existing kernel first, Triton second

Before Triton:

  1. Search transform/library/ and custom_ops/.
  2. Search torch.ops.auto_deploy.* and TRT-LLM custom op definitions.
  3. Read tests for similar integrations.

Use triton-kernel-writing only when no suitable op exists and you accept owning kernel + integration work.

Validation order

  1. Graph dumps — pattern present, rewrite visible (see ad-graph-dump).
  2. Unit tests for the transform.
  3. 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:

Primary unittest location for library transforms:

Review checklist

Guardrails

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:
- ...
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.