cuda-kernels

Write and benchmark optimized CUDA kernels for HuggingFace diffusers and transformers models.

Updated Mar 4, 2026
One-click install
npx skills add https://github.com/chisuhua/home --skill cuda-kernels-chisuhua
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cuda-kernels
Source: https://github.com/chisuhua/home/tree/main/.agents/skills.disabled/cuda-kernels
Command: npx skills add https://github.com/chisuhua/home --skill cuda-kernels-chisuhua

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, diffusers, transformers, kernels, and includes scripts (resource) and references (resource) components.

What problem does it solve? Writing high-performance CUDA kernels for diffusion models and LLMs requires deep knowledge of GPU architectures, memory hierarchies, and framework-specific integration pitfalls, and this Skill provides the patterns, templates, and benchmarking tools to do it correctly. ## Core Features & Use Cases - Kernel Development Guidance: Provides vectorized memory access patterns, warp shuffle reductions, and architecture-specific optimization guides for H100, A100, and T4 GPUs. - Framework Integration: Includes minimal working examples for injecting custom kernels into diffusers pipelines (LTX-Video, Stable Diffusion, FLUX) and transformers models (LLaMA, Mistral, Qwen), plus HuggingFace Kernels Hub loading via get_kernel. - Benchmarking: Ships end-to-end video generation benchmarks and isolated RMSNorm micro-benchmarks comparing custom kernels against PyTorch baselines. - Use Case: Patch all RMSNorm modules in an LTX-Video pipeline with a vectorized CUDA kernel achieving 2.67x speedup over PyTorch, then benchmark the end-to-end generation latency against baseline and torch.compile configurations. ## Quick Start Ask the AI to patch the RMSNorm modules in an LTX-Video diffusers pipeline with the custom CUDA kernel and run the benchmark script comparing optimized versus baseline performance.

Frequently Asked Questions about cuda-kernels

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I integrate custom CUDA kernels into a diffusers pipeline?▼

Load the pipeline, move it to CUDA, then monkey-patch target modules by matching type(module).__name__ before enabling CPU offloading. The included ltx_kernel_injection_example.py demonstrates the complete pattern in about 150 lines for LTX-Video.

How do I load pre-compiled CUDA kernels from HuggingFace Hub?▼

Use the kernels library's get_kernel function with a repository ID like kernels-community/activation, optionally pinning a version. Check availability first with has_kernel, and pre-allocate output tensors since most kernels require them.

Why does torch.compile fail with custom CUDA kernels?▼

torch.compile cannot trace unregistered custom kernels and raises a dynamo Unsupported error. Register the kernel as a PyTorch custom op using torch.library.custom_op with a fake implementation, or run kernels and compile as mutually exclusive configurations.

Why does my RMSNorm kernel fail with NoneType has no attribute contiguous?▼

Some diffusers RMSNorm modules use elementwise_affine=False, so module.weight is None. Detect this case and substitute a weight tensor of ones matching the input's device and dtype before calling the kernel.

What speedup do custom CUDA kernels give over PyTorch for RMSNorm?▼

The vectorized RMSNorm kernel achieves a 2.67x average speedup over the PyTorch baseline on H100, reaching 38% of theoretical memory bandwidth. End-to-end video generation speedup is about 6% because RMSNorm is only around 5% of total compute.

Does this support GPUs other than H100?▼

Yes, dedicated optimization guides cover A100 (sm_80) and T4 (sm_75) alongside H100 (sm_90). Note that T4 lacks BF16 support and requires FP16, and A100 has lower memory bandwidth and no TMA or FP8 features.