pytorch-kernel-optimization

pytorch-kernel-optimization is a skill for Claude Code, Codex from AMD-AGI/Apex. It costs 57 tokens per session (823 once invoked), scanned A, original, MIT.

A guide to making PyTorch models and GPU operations run more efficiently. PyTorch is a framework for building and training machine-learning models, and the guide covers both built-in optimisations and custom GPU code.

In plain words
What is it for?
Use it to tune model throughput or latency, apply torch.compile, improve tensor and memory handling, write custom autograd or CUDA/Triton code, use mixed precision, and profile workloads.
Why use it?
It helps identify slow computation, inefficient memory use, excessive data movement, and input bottlenecks. It also helps choose between compiler settings, tensor changes, and custom extensions.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to tune model throughput or latency, apply torch.compile, improve tensor and memory handling, write custom autograd or CUDA/Triton code, use mixed precision, and profile workloads.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/amd-agi/apex/pytorch-kernel-optimization
View source ↗ AMD-AGI/Apex
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add AMD-AGI/Apex --skill pytorch-kernel-optimization
Clone the repo
git clone --depth 1 https://github.com/AMD-AGI/Apex

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pytorch-kernel-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/amd-agi/apex/pytorch-kernel-optimization/github.svg)](https://agentmods.dev/skills/amd-agi/apex/pytorch-kernel-optimization)
Your own site
<a href="https://agentmods.dev/skills/amd-agi/apex/pytorch-kernel-optimization"><img src="https://agentmods.dev/badge/skills/amd-agi/apex/pytorch-kernel-optimization/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for pytorch-kernel-optimization

Your own site · 80×15
<a href="https://agentmods.dev/skills/amd-agi/apex/pytorch-kernel-optimization"><img src="https://agentmods.dev/badge/skills/amd-agi/apex/pytorch-kernel-optimization.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 57 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 823 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00057 $0.00823
Opus 5.5 $0.00023 $0.00329
Sonnet 5.5 $0.00011 $0.00165
Haiku 4.5 $0.00006 $0.00082

Measured 1mo ago against content hash fa9f73ec0e55, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

pytorch-kernel-optimization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

tools/skills/pytorch-kernel-optimization/SKILL.md · 40 lines

How it starts

The opening of the file, as written. The whole thing — 40 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PyTorch Kernel Optimization

Purpose

  • Equip PyTorch workflows with concrete optimization patterns from high-level APIs to custom kernels.
  • Provide practical snippets for compilation, extensions, mixed precision, memory efficiency, and profiling.

When to Use

  • Tuning PyTorch models for throughput/latency on GPU.
  • Deciding between compiler-level optimizations and custom kernels (C++/CUDA/Triton).
  • Profiling and addressing bottlenecks in compute or input pipelines.

How to Use

  • Efficient tensor ops: favor contiguous layouts (.contiguous() when needed); use channels_last for convs; replace Python loops with vectorized ops; prefer in-place ops (add_, mul_, out=) when autograd-safe.
  • torch.compile: wrap functions or models with @torch.compile; choose modes:
    • "default" balanced, "reduce-overhead" for small batches/CUDA graphs, "max-autotune" for peak perf, "max-autotune-no-cudagraphs" when graphs undesirable.
    • Use fullgraph=True for whole-graph capture; set dynamic=False when shapes are static.
  • Custom autograd: implement torch.autograd.Function saving minimal tensors; recompute in backward when memory-bound (e.g., checkpointed attention); use custom backward formulas for fused ops (e.g., SiLU).
  • CUDA extensions: build with CUDAExtension (-O3, --use_fast_math, -arch=sm_80); enforce input checks in C++ bindings; expose kernels via PYBIND11_MODULE.
  • Mixed precision: train with torch.cuda.amp + GradScaler; mix dtypes per op if needed; leverage bfloat16 when supported.
  • Memory optimization: apply gradient checkpointing (checkpoint, checkpoint_sequential); use memory-efficient attention via scaled_dot_product_attention; consider activation offloading (CPU swap) when memory-bound.
  • Data loading: configure DataLoader with num_workers, pin_memory, prefetch_factor, persistent_workers, drop_last; implement fast collate; prefetch to GPU with custom loader using streams and non-blocking copies.
  • Model optimization: fuse Conv+BN (fuse_conv_bn), apply quantization (quant.fuse_modules, prepare, convert), prune weights via torch.nn.utils.prune; ensure evaluation mode during quantization calibration.
  • CUDA graphs: capture steady workloads via torch.cuda.CUDAGraph; warm up then capture forward/backward; reuse static input/output buffers; note torch.compile(mode=\"reduce-overhead\") can leverage graphs automatically.
  • Profiling:
    • Use torch.profiler.profile with CPU/CUDA activities, schedules, and tensorboard_trace_handler; enable record_shapes, profile_memory, with_stack.
    • Review prof.key_averages().table(sort_by=\"cuda_time_total\"); iterate on hotspots.

Read the full file on GitHub · 40 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 40 lines · 57 tokens per session scan A fa9f73ec0e55

Subscribe to this mod's changes

pytorch-kernel-optimization is a skill published in the GitHub repository AMD-AGI/Apex (78 stars, last pushed 23d ago), licensed MIT. It adds 57 tokens to every session and 823 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

write-triton-kv-cache-append-kernel

Guide the agent through implementing a Triton kernel that writes newly computed K and V tensors into a pre-allocated KV cache during LLM inference. This covers two cache layouts (contiguous and paged / vLLM-style PagedAttention), unified prefill and decode handling via a slotmapping tensor, GQA/MQA where the cache…

tensormux/kernel-skills · 0 tokens

write-triton-rope-kernel

Guide the agent through implementing a correct Triton kernel that applies Rotary Position Embeddings (RoPE) to query and key tensors before attention. This covers the two incompatible layout conventions (GPT-NeoX/HuggingFace-LLaMA vs GPT-J/original-paper), pre-computed cos/sin table consumption, per-token position…

tensormux/kernel-skills · 0 tokens

write-cuda-layernorm-kernel

Guide the agent through designing and implementing a correct, efficient CUDA LayerNorm (and RMSNorm) kernel, covering mean/variance computation strategies, Welford online accumulation, epsilon placement, affine transform application, backward pass structure, and decomposition for non-power-of-two hidden dimensions.

tensormux/kernel-skills · 0 tokens

write-cuda-softmax-kernel

Guide the agent through designing and implementing a correct, numerically stable CUDA softmax kernel, covering online (single-pass) computation, row-parallel decomposition, warp-level reductions, fp16/bf16 precision pitfalls, masked softmax variants, and when to fuse with attention versus implementing standalone.

tensormux/kernel-skills · 0 tokens

write-triton-dequant-kernel

Guide the agent through implementing a Triton kernel that unpacks and dequantizes a quantized weight tensor (int4 or int8) into fp16 or bf16. This is the standalone building block underneath W4A16 / W8A16 schemes (AWQ, GPTQ, SqueezeLLM, bitsandbytes NF4, int8 per-channel). Covers bit-unpacking, per-group scale/zero…

tensormux/kernel-skills · 0 tokens

write-triton-fused-add-rmsnorm-kernel

Guide the agent through implementing a single Triton kernel that computes y = rmsnorm(x + residual) while also writing back x + residual for the next transformer block's residual stream. This fusion is the dominant pattern in LLaMA, Mistral, Qwen, and similar decoder blocks: every attention sub-block and every MLP…

tensormux/kernel-skills · 0 tokens