GPU Optimization Patterns

Optimize PyTorch GPU performance with memory profiling and mixed-precision training.

Updated Feb 25, 2026
One-click install
npx skills add https://github.com/HermeticOrmus/LibreMLOps-Claude-Code --skill gpu-optimization-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: GPU Optimization Patterns
Source: https://github.com/HermeticOrmus/LibreMLOps-Claude-Code/tree/main/plugins/gpu-optimization/skills/gpu-optimization-patterns
Command: npx skills add https://github.com/HermeticOrmus/LibreMLOps-Claude-Code --skill gpu-optimization-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill addresses the critical need to optimize GPU resource utilization, reduce memory consumption, and accelerate model training and inference for deep learning workloads.

Core Features & Use Cases

  • Memory Management: Profile and estimate GPU memory usage for models and optimizers.
  • Compilation Strategies: Apply torch.compile with various modes (default, reduce-overhead, max-autotune) for performance gains.
  • Profiling: Utilize torch.profiler to identify bottlenecks in training steps.
  • Mixed Precision: Implement BF16 and FP16 training with autocast and GradScaler.
  • Quantization: Load models in 4-bit precision using bitsandbytes for reduced memory footprint.
  • DataLoader Optimization: Configure DataLoader for maximum GPU throughput.
  • Use Case: You're training a large language model and hitting GPU memory limits. This Skill helps you profile memory, switch to BF16 mixed precision, and optimize your DataLoader to fit the model and train faster.

Quick Start

Use the gpu-optimization-patterns skill to profile the memory usage of your PyTorch model.

Frequently Asked Questions about GPU Optimization Patterns

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

FAQPage Schema
How do I optimize PyTorch GPU memory usage for large model training?

To optimize PyTorch GPU memory usage, you can profile memory consumption and apply mixed-precision training using BF16 or FP16 with autocast. This Skill provides patterns to estimate memory for models and optimizers to prevent out-of-memory errors.

What is the best way to use torch.compile for performance gains?

The best way to use torch.compile for performance gains is selecting the appropriate mode. This Skill covers applying torch.compile with default, reduce-overhead, and max-autotune modes to accelerate your deep learning workflows.

Can I load large language models in 4-bit quantization with bitsandbytes?

Yes, you can load large language models in 4-bit quantization using bitsandbytes. This Skill provides expert patterns for loading models in 4-bit precision to significantly reduce your GPU memory footprint.

Does PyTorch mixed precision training with BF16 and FP16 require GradScaler?

PyTorch mixed precision training with BF16 and FP16 uses autocast for automatic casting. This Skill details implementing mixed-precision training, covering the application of GradScaler alongside autocast to optimize GPU throughput.

Why is my PyTorch DataLoader causing GPU training bottlenecks?

Your PyTorch DataLoader might cause GPU training bottlenecks due to suboptimal configuration. This Skill helps you configure the DataLoader for maximum GPU throughput and utilize torch.profiler to identify training step bottlenecks.

Do I need torch and transformers to implement GPU profiling and optimization?

Yes, you need torch and transformers to implement these GPU profiling and optimization patterns. This Skill requires PyTorch, bitsandbytes, and transformers libraries to fully support memory management, profiling, and quantization tasks.