orchestra-research avatar

Optimizing Attention Flash

If you're working with transformer models and attention is your bottleneck, this implements Flash Attention to speed things up 2-4x while cutting memory usage by 10-20x. It uses IO-aware tiling and recomputation tricks under the hood. The skill shows you how to use PyTorch's native scaled_dot_product_attention (which auto-detects Flash Attention support) plus presumably the standalone flash-attn library for more control. Worth noting this has passed multiple security audits and comes from a repo with solid GitHub traction. The performance gains are real and measurable, especially on longer sequences where standard attention becomes prohibitively expensive.

skills.sh installs
1K
GitHub stars
14.4K
last updated
Aug 21, 2026

Install

$ npx -y skills add orchestra-research/ai-research-skills --skill optimizing-attention-flash --agent claude-code

Installs into .claude/skills of the current project.

Files

Flash Attention - Fast Memory-Efficient Attention

Quick start

Flash Attention provides 2-4x speedup and 10-20x memory reduction for transformer attention through IO-aware tiling and recomputation.

PyTorch native (easiest, PyTorch 2.2+):

import torch
import torch.nn.functional as F

q = torch.randn(2, 8, 512, 64, device='cuda', dtype=torch.float16)  # [batch, heads, seq, dim]
k = torch.randn(2, 8, 512, 64, device='cuda', dtype=torch.float16)
v = torch.randn(2, 8, 512, 64, device='cuda', dtype=torch.float16)

# Automatically uses Flash Attention if available
out = F.scaled_dot_product_attention(q, k, v)

flash-attn library (more features):

pip install flash-attn --no-build-isolation
from flash_attn import flash_attn_func

# q, k, v: [batch, seqlen, nheads, headdim]
out = flash_attn_func(q, k, v, dropout_p=0.0, causal=True)

Common workflows

Workflow 1: Enable in existing PyTorch model

Copy this checklist:

Flash Attention Integration:
- [ ] Step 1: Check PyTorch version (≥2.2)
- [ ] Step 2: Enable Flash Attention backend
- [ ] Step 3: Verify speedup with profiling
- [ ] Step 4: Test accuracy matches baseline

Sponsors

Details

Repository
github.com/orchestra-research/ai-research-skills
Categories
AI & Agent Building, Data Science & ML
First seen
Jun 3, 2026

More from orchestra-research/ai-research-skills

All 95
1orchestra-research avatarpytorch-lightningorchestra-research/ai-research-skillsHigh-level PyTorch framework with Trainer class, automatic distributed training (DDP/FSDP/DeepSpeed), callbacks system, and minimal boilerplate. Scales from lap1Kskills.sh installs
2orchestra-research avataraxolotlorchestra-research/ai-research-skillsExpert guidance for fine-tuning LLMs with Axolotl - YAML configs, 100+ models, LoRA/QLoRA, DPO/KTO/ORPO/GRPO, multimodal support1Kskills.sh installs
3orchestra-research avatarhqq-quantizationorchestra-research/ai-research-skillsHalf-Quadratic Quantization for LLMs without calibration data. Use when quantizing models to 4/3/2-bit precision without needing calibration datasets, for fast 1Kskills.sh installs
4orchestra-research avatarhuggingface-tokenizersorchestra-research/ai-research-skillsFast tokenizers optimized for research and production. Rust-based implementation tokenizes 1GB in <20 seconds. Supports BPE, WordPiece, and Unigram algorithms. 1Kskills.sh installs
5orchestra-research avatarlong-contextorchestra-research/ai-research-skillsExtend context windows of transformer models using RoPE, YaRN, ALiBi, and position interpolation techniques. Use when processing long documents (32k-128k+ token1Kskills.sh installs
6orchestra-research avatarnanogptorchestra-research/ai-research-skillsEducational GPT implementation in ~300 lines. Reproduces GPT-2 (124M) on OpenWebText. Clean, hackable code for learning transformers. By Andrej Karpathy. Perfec1Kskills.sh installs