0Pricing
Deep Learning Academy · Lezione

Batch norm sincronizzata e stato suddiviso

Mantenga coerenti statistiche e pesi

Batch norm sincronizzata e stato suddiviso è una lezione Deep Learning Academy gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Deep Learning Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Deep Learning Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

The Small-Batch Problem

Batch norm computes stats from each GPU's local batch. Split across many GPUs, each per-device batch shrinks and those stats get noisy.

Enter SyncBatchNorm

SyncBatchNorm fixes this by computing mean and variance across all GPUs together, as if it saw the full global batch.

Convert in One Call

You do not rewrite layers by hand. One helper converts every BatchNorm in your model to its synced version.

import torch.nn as nn
model = nn.SyncBatchNorm.convert_sync_batchnorm(model)

Convert Before Wrapping

Order matters: call the conversion before you wrap the model in DDP, so the synced layers are the ones DDP manages.

model = nn.SyncBatchNorm.convert_sync_batchnorm(model)
model = DDP(model, device_ids=[local_rank])

It Costs Communication

Syncing stats means an extra all-reduce at every batch norm layer. Use it when small per-GPU batches hurt accuracy, not by default.

The Memory Wall

Plain DDP copies the full model, gradients, and optimizer state onto every GPU. For huge models that redundancy wastes memory fast.

Shard the State

Sharding splits those tensors across GPUs so each device stores only a slice. Together the GPUs still hold the whole model.

Meet FSDP

PyTorch's FullyShardedDataParallel shards parameters, gradients, and optimizer state. It lets you train models far larger than one GPU's memory.

from torch.distributed.fsdp import FullyShardedDataParallel as FSDP
model = FSDP(model)

Gather Just in Time

FSDP gathers each layer's full weights only when it is needed for compute, then frees them again. That keeps peak memory low.

ZeRO Stages

Sharding comes in levels, called ZeRO stages: shard optimizer state, then gradients, then parameters. More sharding saves more memory.

Pick the Right Tool

If your model fits per GPU, plain DDP is simplest. When it does not, reach for FSDP to shard state and keep going.

Quick Check

Decide what each technique is really for.

Recap

You met two consistency tools: SyncBatchNorm keeps stats global across GPUs, and FSDP shards state so giant models fit. Use each only when you need it.

Domande Frequenti

La lezione «Batch norm sincronizzata e stato suddiviso» è gratuita?

Sì — il testo completo di «Batch norm sincronizzata e stato suddiviso» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Deep Learning Academy, passa a CoddyKit PRO. Il corso Deep Learning Academy include 4 lezioni in totale.

Cosa imparerò in «Batch norm sincronizzata e stato suddiviso»?

Mantenga coerenti statistiche e pesi Eserciti Deep Learning Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Deep Learning Academy?

Non è richiesta alcuna esperienza precedente. Deep Learning Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.

Quanto tempo richiede la lezione «Batch norm sincronizzata e stato suddiviso»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Deep Learning Academy?

Sì. Ogni lezione Deep Learning Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Parallelismo dei dati e del modello
  2. Nozioni di base su DistributedDataParallel
  3. Batch norm sincronizzata e stato suddiviso
  4. Avviare job con torchrun
← Torna a Deep Learning Academy