Name
odh-ai-helpers:torchtalk-trace
Synopsis
/torchtalk:trace <function-name>
/torchtalk:trace <function-name> full
/torchtalk:trace <function-name> dispatch
/torchtalk:trace <function-name> yaml
Description
The torchtalk:trace command traces a PyTorch function's complete binding chain from Python through C++ to CUDA implementations. It uses the TorchTalk MCP server to look up operator definitions in native_functions.yaml, find pybind11 and TORCH_LIBRARY bindings, and map dispatch keys to backend implementations.
After gathering the raw binding data, the command analyzes the results to explain:
- How the Python API connects to the native implementation
- Which dispatch keys route to which backends (CPU, CUDA, MPS, etc.)
- Where each layer is implemented with exact file:line references
- The autograd integration and backward pass formula (if applicable)
- Architectural context about why the dispatch is structured this way
This command requires the TorchTalk MCP server to be running. Run mcp__torchtalk__get_status to verify availability.
Prerequisites
- TorchTalk MCP server must be running and registered with Claude Code
- Run
/torchtalk:setupif not yet installed
Implementation
- Verify MCP server: Call
mcp__torchtalk__get_statusto confirm the TorchTalk server is running and has indexed data available - Trace binding chain: Call
mcp__torchtalk__tracewith the function name and optional focus parameter to retrieve the full binding chain - Get internal dependencies: Call
mcp__torchtalk__callswith the function name to understand what the function invokes internally - Analyze dispatch architecture: Examine the dispatch keys, backend routing, and structured binding patterns returned by the trace
- Synthesize explanation: Combine the trace data, call graph, and dispatch information into a coherent explanation that covers:
- The Python entry point and how it connects to native code
- The
native_functions.yamldefinition and its dispatch configuration - Each backend implementation with file:line references
- The autograd formula (from
derivatives.yaml) if applicable - Architectural observations about the operator's design
- Provide file references: Format all implementation locations as
file:linereferences so the developer can navigate directly to the source
Return Value
- Claude agent text: A structured analysis of the function's binding chain, organized by layer (Python -> YAML definition -> C++ dispatch -> backend implementations), with file:line references and architectural commentary
Examples
-
Trace a common operator:
/torchtalk:trace matmulOutput: Full binding chain from
torch.matmulthroughat::native::matmultoLinearAlgebra.cpp, including CPU and CUDA dispatch paths. -
Focus on dispatch mapping only:
/torchtalk:trace conv2d dispatchOutput: Which backends handle
conv2dand where each kernel is registered. -
Focus on YAML definition:
/torchtalk:trace softmax yamlOutput: The
native_functions.yamlentry for softmax, including its function schema, dispatch keys, and derivative formula. -
Full deep trace:
/torchtalk:trace add fullOutput: Complete trace from Python API through every layer including structured kernel registrations, autograd formula, and all backend implementations.
Arguments
<function-name>: The PyTorch function name to trace (e.g.,matmul,conv2d,softmax,add). Can be a short name or fully qualified (e.g.,at::native::matmul).[focus]: Optional focus parameter. One of:full(default): Complete binding chain across all layersdispatch: Only dispatch key to backend mappingyaml: Only thenative_functions.yamldefinition
See Also
/torchtalk:setup- Install and configure TorchTalk- TorchTalk Analyzer skill - Full MCP tools reference including impact analysis, call graph, and test infrastructure