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.
npx skills add AMD-AGI/Apex --skill pytorch-kernel-optimizationgit clone --depth 1 https://github.com/AMD-AGI/ApexWrote 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.
[](https://agentmods.dev/skills/amd-agi/apex/pytorch-kernel-optimization)<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.
<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>- NVIDIA SkillSpector pass
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.
| Model | Per session | Once 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 |
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.
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); usechannels_lastfor 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=Truefor whole-graph capture; setdynamic=Falsewhen shapes are static.
- Custom autograd: implement
torch.autograd.Functionsaving 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 viaPYBIND11_MODULE. - Mixed precision: train with
torch.cuda.amp+GradScaler; mix dtypes per op if needed; leveragebfloat16when supported. - Memory optimization: apply gradient checkpointing (
checkpoint,checkpoint_sequential); use memory-efficient attention viascaled_dot_product_attention; consider activation offloading (CPU swap) when memory-bound. - Data loading: configure
DataLoaderwithnum_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 viatorch.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; notetorch.compile(mode=\"reduce-overhead\")can leverage graphs automatically. - Profiling:
- Use
torch.profiler.profilewith CPU/CUDA activities, schedules, andtensorboard_trace_handler; enablerecord_shapes,profile_memory,with_stack. - Review
prof.key_averages().table(sort_by=\"cuda_time_total\"); iterate on hotspots.
- Use
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.
- 1mo ago First seen · 40 lines · 57 tokens per session scan A fa9f73ec0e55
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.
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…
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…
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.
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.
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…
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…