# Ponowne liczenie aktywacji (gradient checkpointing)

EN: **Gradient (activation) checkpointing** · id `gradcheckpointing` · aliases: gradient checkpointing, activation checkpointing, activation recomputation, rematerialization, rematerializacja

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Trenowanie i dostrajanie](https://aiatlasgraph.com/t/training.md) › [Proces uczenia](https://aiatlasgraph.com/t/optimization.md) › [Oszczędzanie pamięci podczas treningu](https://aiatlasgraph.com/t/memefficienttraining.md) › Ponowne liczenie aktywacji (gradient checkpointing)

## Description

- PL: Zapamiętuje się tylko wybrane aktywacje, a brakujące oblicza ponownie podczas propagacji wstecznej.
- EN: Only selected activations are stored; the missing ones are recomputed during backpropagation.

## In one sentence

- PL: Model w trakcie nauki zapisuje tylko niektóre wyniki pośrednie, a resztę liczy jeszcze raz, gdy będą potrzebne.
- EN: While training, the model saves only some intermediate results and recalculates the rest when they're needed.

## Problem it solves

- PL: Wyniki pośrednie każdej warstwy zajmują ogromną pamięć, szczególnie przy długich tekstach i głębokich modelach.
- EN: Intermediate results from every layer take huge amounts of memory, especially with long texts and deep models.

## What it does

- PL: Jak notowanie wyniku co dziesiątej strony obliczeń: gdy potrzebujesz czegoś ze środka, przeliczasz od najbliższej notatki.
- EN: Like noting a result every tenth page of calculations: when you need something in between, you redo it from the nearest note.

## Everyday example

- PL: Dostrajasz model na długich umowach i po włączeniu tej opcji trening przestaje się przerywać z braku pamięci.
- EN: You fine-tune a model on long contracts, and after switching this on, training stops crashing for lack of memory.

## This concerns you if you…

- PL: trenujesz na długich sekwencjach
- PL: wolisz wolniejszy trening niż brak pamięci
- EN: train on long sequences
- EN: prefer slower training over running out of memory

## Keywords

activation recomputation · torch.utils.checkpoint · selective recomputation · sublinear memory · rematerialization · Megatron-LM

## How it works

- PL: Sieć dzieli się na segmenty i w przejściu w przód zapisuje tylko aktywacje na ich granicach. W przejściu wstecz każdy segment liczy się ponownie od punktu kontrolnego; przy podziale na około √n segmentów pamięć rośnie jak O(√n) kosztem mniej więcej jednego dodatkowego przejścia w przód.
- EN: The network is split into segments, and the forward pass stores only activations at their boundaries. In the backward pass each segment is recomputed from its checkpoint; with about √n segments memory grows as O(√n) at the cost of roughly one extra forward pass.

## Limits

- PL: Wydłuża trening o koszt dodatkowego przejścia w przód. Nie zmniejsza pamięci wag ani stanów optymalizatora; warianty selektywne wymagają wyboru, które operacje przeliczać, a które trzymać.
- EN: It lengthens training by the cost of an extra forward pass. It doesn't reduce memory for weights or optimiser states; selective variants require choosing which operations to recompute and which to keep.

## Key terms

- PL: **punkt kontrolny**: Zapisana aktywacja, od której można ponownie policzyć dalszą część sieci.
- PL: **rematerializacja**: Ponowne wyliczenie wartości zamiast trzymania jej w pamięci.
- EN: **checkpoint**: A stored activation from which later parts of the network can be recomputed.
- EN: **rematerialisation**: Recomputing a value instead of keeping it in memory.

## Know first

- [Propagacja wsteczna (backpropagation) (Backpropagation)](https://aiatlasgraph.com/t/backprop.md)

## Sources

- [Training Deep Nets with Sublinear Memory Cost](<https://arxiv.org/abs/1604.06174>) `chen-2016-sublinear` · by Tianqi Chen, Bing Xu, Chiyuan Zhang, Carlos Guestrin

---

AI Atlas revision 122 (2026-10-30) · HTML: https://aiatlasgraph.com/t/gradcheckpointing · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
