Skip to content
Back to skills

Gradient Checkpointing

ASecurity

Trades compute for memory by recomputing intermediate activations during backprop instead of storing them, reducing memory from O(n) to O(sqrt(n)).

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
toolspython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill gradient-checkpointing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Gradient Checkpointing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Gradient Checkpointing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-gradient-checkpointing/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-gradient-checkpointing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: nlp-gradient-checkpointing
description: >
  Trades compute for memory by recomputing intermediate activations during backprop instead of storing them, reducing memory from O(n) to O(sqrt(n)).
---
# Gradient Checkpointing

## Overview

Large transformer models store all intermediate activations for backpropagation, consuming massive GPU memory. Gradient checkpointing discards most activations during the forward pass and recomputes them on-the-fly during backward. This reduces activation memory from O(n_layers) to O(sqrt(n_layers)) at the cost of ~30% slower training. Essential for fine-tuning large models on limited GPU memory.

## Quick Start

```python
from transformers import AutoModel

model = AutoModel.from_pretrained("microsoft/deberta-v3-base")
model.gradient_checkpointing_enable()

# Now train as usual — memory usage drops significantly
# Pair with mixed precision for maximum memory savings
```

## Workflow

1. Load your pretrained transformer model
2. Call `model.gradient_checkpointing_enable()` before training
3. Train as normal — PyTorch handles activation recomputation automatically
4. Optionally combine with mixed precision (`torch.cuda.amp`) for further savings

## Key Decisions

- **When to use**: When model doesn't fit in GPU memory at your desired batch size
- **Speed cost**: ~25-35% slower per step; offset by enabling larger batch sizes
- **Combine with**: Mixed precision (FP16/BF16), gradient accumulation, frozen layers
- **PyTorch native**: `torch.utils.checkpoint.checkpoint()` for custom models
- **Disable for inference**: Only needed during training; no effect at eval time

## References

- [Optimization approaches for Transformers](https://www.kaggle.com/code/vad13irt/optimization-approaches-for-transformers)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.