ad-graph-dump
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAutoDeploy: Graph dumps (AD_DUMP_GRAPHS_DIR
)
AD_DUMP_GRAPHS_DIRAutoDeploy:图形转储(AD_DUMP_GRAPHS_DIR
)
AD_DUMP_GRAPHS_DIRWhere this skill applies
本技能适用场景
This file is part of trtllm-agent-toolkit. Commands and paths such as and are relative to a TensorRT-LLM source checkout, not the plugin repository.
examples/auto_deploy/tensorrt_llm/本文件是trtllm-agent-toolkit的一部分。和等命令与路径是相对于TensorRT-LLM源代码检出目录的,而非插件仓库。
examples/auto_deploy/tensorrt_llm/When to use this skill
何时使用本技能
- You need to see how the FX graph changes after each registered transform runs.
- You are verifying that a subgraph exists, that a fusion matched, or that metadata / wrappers (,
getitem,view) appeared or disappeared between dumps.reshape - You are pairing log output with on-disk graph files while debugging AutoDeploy.
- 你需要查看每个已注册转换操作执行后,FX图形发生的变化。
- 你需要验证子图形是否存在、融合操作是否匹配,或元数据/包装器(、
getitem、view)在转储前后是否出现或消失。reshape - 调试AutoDeploy时,你需要将日志输出与磁盘上的图形文件配对分析。
Related skills in this plugin
本插件中的相关技能
| Skill | Use it for |
|---|---|
| ad-layer-visualizer | Extracting and visualizing a single decoder layer from a dump as a DOT/PNG diagram. |
| ad-add-fusion-transformation | Implementing or reviewing fusion passes once you know what the graphs show. |
| trtllm-codebase-exploration | Searching the TRT-LLM tree for transforms, custom ops, and patterns. |
| trtllm-code-contribution | Tests and contribution hygiene after you change TRT-LLM. |
| 技能 | 适用场景 |
|---|---|
| ad-layer-visualizer | 从转储中提取单个解码器层并将其可视化为DOT/PNG图。 |
| ad-add-fusion-transformation | 了解图形显示内容后,实现或审核融合处理流程。 |
| trtllm-codebase-exploration | 在TRT-LLM代码树中搜索转换操作、自定义算子和模式。 |
| trtllm-code-contribution | 修改TRT-LLM后的测试与代码贡献规范检查。 |
Environment variable
环境变量
Set:
bash
export AD_DUMP_GRAPHS_DIR=/path/to/output/dirImplementation: in .
GraphWriter.DUMP_GRAPHS_ENV == "AD_DUMP_GRAPHS_DIR"tensorrt_llm/_torch/auto_deploy/utils/graph_writer.pyIf unset, no graph files are written.
设置:
bash
export AD_DUMP_GRAPHS_DIR=/path/to/output/dir实现位置:中的。
tensorrt_llm/_torch/auto_deploy/utils/graph_writer.pyGraphWriter.DUMP_GRAPHS_ENV == "AD_DUMP_GRAPHS_DIR"若未设置该变量,则不会生成任何图形文件。
When dumps are produced
转储生成时机
After each transform application, calls from (immediately after ). So the dump reflects the module after that transform has run.
BaseTransformgraph_writer.dump_graph(mod, t_name, self.config.stage.value)tensorrt_llm/_torch/auto_deploy/transform/interface.py_visualize_graph每次执行转换操作后,会调用中的(紧跟在之后)。因此转储内容反映的是该转换操作执行后的模块状态。
BaseTransformtensorrt_llm/_torch/auto_deploy/transform/interface.pygraph_writer.dump_graph(mod, t_name, self.config.stage.value)_visualize_graphRank / process behavior
Rank/进程行为
From :
GraphWriter.dump_graph- Dumps run only when is set.
AD_DUMP_GRAPHS_DIR - If is set and is not
ADLogger.rank, dumping is skipped (non–rank-0 processes do not write files).0
根据的逻辑:
GraphWriter.dump_graph- 仅当设置了时才会生成转储。
AD_DUMP_GRAPHS_DIR - 若已设置且不为0,则会跳过转储(非rank-0进程不会写入文件)。
ADLogger.rank
Directory lifecycle
目录生命周期
On the first dump on rank 0, removes the target directory if it already exists, then recreates it. Do not point at a directory that must be preserved without copying it first.
GraphWriterAD_DUMP_GRAPHS_DIR当rank-0进程首次生成转储时,会先删除目标目录(若已存在),然后重新创建。请勿将指向需要保留的目录,除非先进行备份。
GraphWriterAD_DUMP_GRAPHS_DIRFile naming and ordering
文件命名与排序
Files are named:
text
{NNN}_{<stage.value>}_{<transform_key>}.txt- is a monotonically increasing three-digit counter (001, 002, …) in run order across all dumps in that process.
NNN - The middle segment is each transform’s value (same enum/string used in
config.stageunder each transform’sdefault.yamlfield).stage: - The last segment is the transform’s registry key (passed into
transform_name).dump_graph
So lexicographic sort by filename matches pipeline order for that run.
文件命名格式如下:
text
{NNN}_{<stage.value>}_{<transform_key>}.txt- 是一个单调递增的三位计数器(001、002……),代表该进程中所有转储的执行顺序。
NNN - 中间段是每个转换操作的值(与
config.stage中每个转换操作下default.yaml字段使用的枚举/字符串一致)。stage: - 最后一段是转换操作的注册表键(传入的
dump_graph)。transform_name
因此,按文件名的字典序排序即可匹配本次运行的流水线顺序。
File contents
文件内容
Each file is text and starts with headers similar to:
text
undefined每个文件均为文本格式,开头包含类似以下的头部信息:
text
undefinedTransform: <transform_key>
Transform: <transform_key>
Stage: <stage.value>
Stage: <stage.value>
GraphModules found: <count>
GraphModules found: <count>
Then, for every `torch.fx.GraphModule` found under `mod.named_modules()` (including the root), the writer emits a section title and an SSA-style listing with shape/dtype metadata via `dump_ssa_with_meta()` in the same module.
Use this to compare operator chains, consumers, and `node.meta` shape/dtype hints across consecutive files.
随后,对于`mod.named_modules()`下找到的所有`torch.fx.GraphModule`(包括根模块),写入器会生成章节标题,并通过同一模块中的`dump_ssa_with_meta()`输出带有形状/数据类型元数据的SSA格式列表。
你可以利用此内容比较连续文件中的算子链、消费者以及`node.meta`形状/数据类型提示。Example: capture dumps from a registry build
示例:从注册表构建中捕获转储
From the root of the TensorRT-LLM clone (adjust the script and flags to your workflow):
bash
AD_DUMP_GRAPHS_DIR=/tmp/ad-graphs \
python examples/auto_deploy/build_and_run_ad.py --model <hf-model-id> --use-registryPick any AutoDeploy entrypoint you already use; the requirement is only that the code path runs the transform pipeline with set in the environment.
AD_DUMP_GRAPHS_DIR在TensorRT-LLM克隆目录的根目录下执行(根据你的工作流程调整脚本和参数):
bash
AD_DUMP_GRAPHS_DIR=/tmp/ad-graphs \
python examples/auto_deploy/build_and_run_ad.py --model <hf-model-id> --use-registry你可以使用任何已在使用的AutoDeploy入口点;唯一要求是代码路径在设置了环境变量的情况下运行转换流水线。
AD_DUMP_GRAPHS_DIRLogs vs dump files
日志与转储文件
While a transform runs, logging is patched so messages can be prefixed with (see in ). Transform summaries log with or / (). Use those lines together with the numbered dump files to tie match counts to graph shape before and after a specific transform.
[stage=<stage.value>, transform=<transform_key>]with_transform_loggingtransform/interface.py[SUMMARY]matches=<n>skippeddisabled_log_transform_summary转换操作运行时,日志会被修补,以便消息前缀可以添加(参见中的)。转换摘要日志会带有标记,包含或/信息(来自)。你可以将这些日志行与带编号的转储文件结合,将匹配计数与特定转换操作前后的图形形状关联起来。
[stage=<stage.value>, transform=<transform_key>]transform/interface.pywith_transform_logging[SUMMARY]matches=<n>skippeddisabled_log_transform_summaryPitfalls
注意事项
- Stale directory: Because the dump dir is deleted on first use, a second run in the same shell without changing overwrites prior output.
AD_DUMP_GRAPHS_DIR - No GraphModules: If the module has no children,
GraphModulereturns without creating a new file for that step (see early return indump_graph).graph_writer.py - Distributed: Only rank 0 writes; other ranks skip silently.
- 目录覆盖:由于首次使用时会删除转储目录,若在同一shell中不修改就再次运行,会覆盖之前的输出。
AD_DUMP_GRAPHS_DIR - 无GraphModule:如果模块没有子模块,
GraphModule会提前返回,不会为该步骤创建新文件(参见dump_graph中的提前返回逻辑)。graph_writer.py - 分布式场景:仅rank-0进程会写入文件,其他进程会静默跳过。
Source references
源码参考
- — env var, filenames, SSA dump.
tensorrt_llm/_torch/auto_deploy/utils/graph_writer.py - — call site after each transform; log prefix decorator.
tensorrt_llm/_torch/auto_deploy/transform/interface.py
- —— 环境变量、文件名、SSA转储逻辑。
tensorrt_llm/_torch/auto_deploy/utils/graph_writer.py - —— 每次转换操作后的调用点;日志前缀装饰器。
tensorrt_llm/_torch/auto_deploy/transform/interface.py