Llm Torch Profiler Analysis 标志

Llm Torch Profiler Analysis

社区
BBuf
llm-torch-profiler-analysis

分析现有的 Torch Profiler Chrome 跟踪数据,或从 SGLang、vLLM、TensorRT-LLM 和 TokenSpeed 服务器采集跟踪数据。提供内核归因、重叠执行机会和融合模式;适用于模型分发、CUDA Graph 缺口、流竞争或暴露的内核尾部分析。还包括现有的 SGLang Omni 跟踪数据。

Add to TypingMind

概览

发布者BBuf
代码仓库AI-Infra-Auto-Driven-SKILLS
技能名称llm-torch-profiler-analysis
星标数
946
复刻数
83
附带文件
14
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 14 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 BBuf 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Llm Torch Profiler Analysis AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/BBuf/AI-Infra-Auto-Driven-SKILLS/tree/main/skills/llm-torch-profiler-analysis
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/BBuf/AI-Infra-Auto-Driven-SKILLS.git /tmp/AI-Infra-Auto-Driven-SKILLS
mkdir -p .claude/skills
cp -r /tmp/AI-Infra-Auto-Driven-SKILLS/skills/llm-torch-profiler-analysis .claude/skills/llm-torch-profiler-analysis
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Llm Torch Profiler Analysis,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Llm Torch Profiler Analysis。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Llm Torch Profiler Analysis 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

LLM Torch Profiler Analysis

Produce three tables: kernel/source attribution, overlap opportunities, and fusion patterns. Start from the user's trace or running server. Inspect the actual model, framework revision, phase, device/rank and parallelism before choosing a fast path. Existing traces need no GPU or framework installation. The Python analyzers use the standard library.

Read source contracts for dated source inspections and version-sensitive profiler APIs. Apply the general dispatch and numerical principles to every model. The fusion catalog contains concrete operator families, eligibility examples and storage contracts; the overlap catalog covers scheduling. Consult the model-history knowledge base when detailed PR evidence is needed. Source checks and historical captures are not fresh GPU validation.

Choose the evidence

ModeEvidence and limits
Existing traceAll four frameworks; SGLang Omni Python roots are also recognized. Use Chrome JSON or gzip with GPU events. A generic trace may need --framework explicitly.
Single live captureUse a shared server/client output directory and a supported HTTP profiler. Save actual launch arguments and package revisions.
Mapping + formalEager/graph-off trace supplies call-site context; warmed graph trace supplies timing. Match signatures, shapes and stage before transferring attribution. Never transfer eager timing to the formal run.

For a diffusion workload, record whether it uses the framework's native backend or a Diffusers fallback. A fallback trace can be analyzed, but does not establish native-kernel performance or dispatch.

Read a trace

Commands below are relative to this skill directory.

bash
python3 scripts/analyze_llm_torch_profile.py \
  --framework sglang --input /path/to/TP-0-DECODE.trace.json.gz

python3 scripts/analyze_llm_torch_profile.py \
  --framework vllm \
  --mapping-input /path/to/eager-mapping \
  --formal-input /path/to/warmed-graph

Do not collapse a distributed run to rank0 when investigating rank skew or collective waits. Keep the original capture; a GPU-only or compact export is for sharing, not replacement evidence. Use torch-profiler-layer-track for verified L0/L1 guides and synthetic display lanes, or llm-pipeline-analysis for layer intervals.

Capture against a running server

The common helper defaults to separately driven prefill and decode workloads: nominal input/output lengths 4090/1 and 1/2048, with 10 warmup steps and 5 requested capture steps. Override these to match the slow serving scenario. Synthetic prompt lengths are not a tokenizer-independent guarantee; save actual usage and batch/graph dimensions. A long-context decode bottleneck needs a representative KV length, not automatically the one-token-input default.

bash
python3 scripts/analyze_llm_torch_profile.py \
  --framework sglang --url http://127.0.0.1:30000 \
  --output-dir /shared/profiles/run-001 \
  --profile-workload both --warmup-steps 10 --num-steps 5 \
  --prefill-input-len 4090 --prefill-output-len 1 \
  --decode-input-len 4090 --decode-output-len 2048

--profile-workload accepts both, prefill, decode, or legacy (explicit probe prompt/token settings). Workload labels alone do not make a trace purely decode: inspect stage annotations and exclude request prefill when needed. The helper targets SGLang profiler v1 (default). Declare --sglang-profile-v2 if the remote server enables SGLANG_PROFILE_V2=1; the helper refuses this incompatible flow before issuing control requests. /server_info does not expose remote environment variables. Native v2 needs profile_by_stage:true and num_steps, without start_step, merge_profiles or /stop_profile. The Rust frontend has no HTTP profiler routes; use Python or offline capture. The host launcher explicitly sets SGLANG_PROFILE_V2=0. The helper puts its label in profile_id, so merging can discover rank files. SGLang can emit stage-specific traces; its scheduler stop counter may require a final forward to close the window. The helper's SGLang workload adds a guard request/step. Check actual trace counts instead of assuming identical windows across frameworks.

For other frameworks add --no-profile-by-stage. Their HTTP windows and iteration controls differ:

  • vLLM: launch with --profiler-config '{"profiler":"torch","torch_profiler_dir":"/shared/profiles/run-001","max_iterations":5,"ignore_frontend":true}'. Start/stop has no per-request output/steps body. Configure iteration limits and optional profiler warmup at server launch. The helper's --num-steps controls probe planning, not vLLM's internal profile schedule. torch_profiler_with_stack defaults true in the inspected source. Frontend traces can contain no kernels; select GPU-worker traces for GPU analysis. active_iterations only takes effect with a warmup/wait schedule; use max_iterations to bound workers. The host option is --profiler-max-iterations (--profiler-active-iterations remains an alias). Two capture rounds require vLLM #57460, merged 2026-09-21; older images need separate launches for prefill and decode. Keep CPU in torch_profiler_activities for source attribution and step annotations; CUDA-only activities omit both Python stacks and annotations.
  • TensorRT-LLM: the inspected PyTorch server accepts runtime start with output_dir and activities; the helper sends both and stops after probes. Native traces are uniquely named per request and rank. There is no need for the retired py_executor.py rank0-only patch or host-specific matrix runner. Current setup is in _torch/pyexecutor/profiling.py, still without with_stack=True. Report unresolved Python attribution, or make a separate, recorded mapping build against that installed file. Older images without HTTP support must use their documented capture method plus --input.
  • TokenSpeed: the helper sends output_dir, CPU/GPU activities, with_stack=true, record_shapes=false, and a stage-qualified profile_id. Current servers expose start/stop; verify the deployed image. Proton's native Hatchet artifacts are not Torch Chrome traces. The control sidecar uses --control-port or serve port + 1; external pinned gateway wheels control JSON forwarding, so validate payload fields on the installed image. EXPERT_LOAD writes .expert-load.pt, not Chrome traces. TOKENSPEED_CUPTI_GRAPH_WARMUP=1 can leave zero GPU events in later captures.
bash
python3 scripts/analyze_llm_torch_profile.py \
  --framework trtllm --url http://127.0.0.1:8000 \
  --output-dir /shared/profiles/run-002 \
  --no-profile-by-stage --profile-workload both

A server-side directory must be mounted here or copied back for analysis. The helper rejects a capture with no new artifact, recognizes overwritten filenames, and copies fresh remote traces into a capture-specific subdirectory without moving the server's originals. Preserve that returned directory rather than analyzing every historical run under a shared root. Concurrent profiling sessions still need separate output directories.

Native alternatives include SGLang graph-capture traces under graph_capture_profile/, MEM snapshots, and CUDA_PROFILER with nsys; vLLM capture_torch_profiler, CUDA/NVTX and Proton Chrome export; TRT-LLM TLLM_PROFILE_START_STOP/TLLM_TORCH_PROFILE_TRACE; and TokenSpeed VizTracer/Proton plus tokenspeed merge-traces. Graph-capture and VizTracer artifacts are excluded from default runtime-trace discovery. Pass a file explicitly when intentionally studying one of these artifacts. Native Hatchet, MEM and expert-load outputs require their own readers.

Interpret before optimizing

  1. Confirm nonzero GPU events, a complete warmed forward, actual dispatch and target/draft separation (step[VERIFY ...] versus step[DRAFT ...] in SGLang; vLLM uses execute_context_*_generation_*). BS=1 need not mean kernel M=1 during speculation.
  2. Read all relevant GPU streams. A CPU cudaGraphLaunch span is host time; missing lanes or dropped CUPTI records can look like GPU idle time.
  3. Separate sum of kernel durations, union of GPU busy intervals, and end-to-end wall time. Overlapping kernels can sum to more than wall time. A table's duration share is not removable latency or an additive speedup estimate.
  4. Identify the producer/consumer join and exposed tail. PDL consumers may include dependency wait in kernel duration. Compare PDL on/off with the same warp configuration before attributing a bimodal duration to arithmetic.
  5. Consult source dispatch before proposing fusion. Existing routed-expert activation/quant does not establish shared-expert coverage. Match rounding, clamp, scale/layout, padding and graph reuse contracts.
  6. Time changes without profiling; run kernel correctness and actual-model accuracy on the candidate path. NCU replay/resource metrics help explain a kernel but can perturb or serialize the multi-stream behavior being studied.

For source mapping, prefer model/layer frames over dispatch/runtime wrappers. Retain unknown locations as unknown. Kernel names and eager similarities are hints; inspect the concrete producer, consumer and backend. The script's three tables are observations and candidates, not proof that an optimization is safe or already active in a different framework.

References and output

Load only relevant references:

  • source-map.md: immutable profiler and worker paths.
  • heuristics.md: attribution and overlap labels, dispatch, numerical contracts, validation and their limitations.
  • vllm-torch-compile-fusions.md: current pass registration, platform gates and source patterns.
  • fuse-overlap-catalog.md and overlap-catalog.md: historical precedents; recheck a PR's current state and target revision before borrowing code. The overlap catalog also covers GPU idle gaps, scheduler overlap, phase graphs, metadata glue graphs, replay streams, PDL and collective dispatch.

Return the trace/report path, framework and available model/server arguments; the kernel, overlap-opportunity and fusion-pattern tables; the main exposed bottleneck; attribution confidence and whether mapping/formal traces were used. For a new capture also state which phases/ranks contain GPU events. Do not claim a speedup or accuracy equivalence without the corresponding experiment.

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Llm Torch Profiler Analysis AI 技能有什么作用?

分析现有的 Torch Profiler Chrome 跟踪数据,或从 SGLang、vLLM、TensorRT-LLM 和 TokenSpeed 服务器采集跟踪数据。提供内核归因、重叠执行机会和融合模式;适用于模型分发、CUDA Graph 缺口、流竞争或暴露的内核尾部分析。还包括现有的 SGLang Omni 跟踪数据。

为什么在 TypingMind 中使用 Llm Torch Profiler Analysis?

因为您只需安装一次,就能搭配任何模型使用。Llm Torch Profiler Analysis 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Llm Torch Profiler Analysis?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/BBuf/AI-Infra-Auto-Driven-SKILLS/tree/main/skills/llm-torch-profiler-analysis。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Llm Torch Profiler Analysis?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Llm Torch Profiler Analysis 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Llm Torch Profiler Analysis 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Llm Torch Profiler Analysis AI 技能免费吗?

BBuf 已在 GitHub 上发布了该技能。请查看代码仓库了解许可条款。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇