Agent skill
torch-compile
Install this agent skill to your Project
npx add-skill https://github.com/cuba6112/skillfactory/tree/main/skills/torch-compile
SKILL.md
Torch Compile
Overview
Use torch.compile to JIT-compile PyTorch code into optimized kernels, then validate speedups with warmups and graph-break audits.
When to Use
Use this skill only when the frontmatter triggers apply; otherwise keep eager mode.
Decision Tree
- Do you need to reduce Python overhead in hot paths?
- Yes: compile and benchmark.
- Are first runs much slower than eager?
- Yes: warm up and re-measure after caching.
- Are graph breaks frequent?
- Yes: audit with
torch._dynamo.explainor logging and reduce non-tensor logic.
- Yes: audit with
Workflows
1. Compile Benchmark With Warmup
- Run a short eager baseline.
- Compile the model and run warmup iterations.
- Measure steady-state latency after warmup.
- Compare the eager and compiled timings.
2. Graph Break Audit
- Run
torch._dynamo.explainon the target function. - Record graph break counts and reasons.
- Move non-tensor logic outside the compiled region.
- Re-run the explain pass to confirm fewer breaks.
3. Speedup Expectation Check
- Confirm the workload is Python-overhead bound.
- If the workload is GPU compute bound, expect lower gains.
- Adjust batch size or fuse operations to increase gains.
Non-Obvious Insights
- Compilation overhead shows up on the first few executions, so warmup is required before benchmarking.
- Speedup depends on reducing Python overhead and GPU read/writes; architecture and batch size affect the outcome.
- Graph breaks trade optimization opportunities for correctness rather than crashing.
Evidence
- "torch.compile makes PyTorch code run faster by JIT-compiling PyTorch code into optimized kernels, while requiring minimal code changes." - PyTorch
- "torch.compile takes extra time to compile the model on the first few executions." - PyTorch
- "reducing Python overhead and GPU read/writes, and so the observed speedup may vary on factors such as model architecture and batch size." - PyTorch
- "Graph breaks result in lost optimization opportunities, which may still be undesirable, but this is better than silent incorrectness or a hard crash." - PyTorch
Scripts
scripts/torch-compile_tool.py: CLI for probing torch.compile availability, benchmarking, and explain output.scripts/torch-compile_tool.js: Node.js wrapper for the same CLI.
Dependencies
- Python 3.11+ or Node 18+.
- PyTorch 2.0+ for torch.compile.
References
- references/README.md
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
prompt-engineering
Comprehensive prompt engineering techniques for Claude models. Use this skill when crafting, optimizing, or debugging prompts for Claude API, Claude Code, or any Claude-powered application. Covers system prompts, role prompting, multishot examples, chain of thought, XML structuring, long context handling, extended thinking, prompt chaining, Claude 4.x-specific best practices, and agentic orchestration including subagents, agent loops, skills, MCP integration, and multi-agent workflows.
adk-rag-agent
Build RAG (Retrieval-Augmented Generation) agents with Google ADK and Vertex AI RAG Engine. Use when implementing document Q&A, knowledge base search, or citation-backed responses. Covers VertexAiRagRetrieval tool, corpus setup, and citation formatting.
headless-cli-agents
Build agentic systems using Claude CLI in headless mode or the Claude Agent SDK. Use when building automation pipelines, CI/CD integrations, multi-agent orchestration, or programmatic Claude interactions. Covers CLI flags (-p, --output-format), session management (--resume, --continue), Python SDK (claude-agent-sdk), custom tools, and agent loop patterns.
notion-knowledge-capture
Capture conversations and decisions into structured Notion pages; use when turning chats/notes into wiki entries, how-tos, decisions, or FAQs with proper linking.
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
gh-fix-ci
Inspect GitHub PR checks with gh, pull failing GitHub Actions logs, summarize failure context, then create a fix plan and implement after user approval. Use when a user asks to debug or fix failing PR CI/CD checks on GitHub Actions and wants a plan + code changes; for external checks (e.g., Buildkite), only report the details URL and mark them out of scope.
Didn't find tool you were looking for?