0Pricing
Deep Learning Academy · บทเรียน

Batch Norm แบบซิงก์และสถานะแบ่งส่วน

รักษาสถิติและน้ำหนักให้สอดคล้องกัน

Batch Norm แบบซิงก์และสถานะแบ่งส่วน เป็นบทเรียน Deep Learning Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Deep Learning Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Deep Learning Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

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.

คำถามที่พบบ่อย

บทเรียน “Batch Norm แบบซิงก์และสถานะแบ่งส่วน” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “Batch Norm แบบซิงก์และสถานะแบ่งส่วน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Deep Learning Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Deep Learning Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “Batch Norm แบบซิงก์และสถานะแบ่งส่วน”

รักษาสถิติและน้ำหนักให้สอดคล้องกัน คุณปฏิบัติ Deep Learning Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Deep Learning Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Deep Learning Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “Batch Norm แบบซิงก์และสถานะแบ่งส่วน” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Deep Learning Academy นี้ได้ไหม

ได้ บทเรียน Deep Learning Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การประมวลผลแบบขนานด้านข้อมูลกับด้านโมเดล
  2. พื้นฐาน DistributedDataParallel
  3. Batch Norm แบบซิงก์และสถานะแบ่งส่วน
  4. เปิดงานด้วย torchrun
← กลับไปที่ Deep Learning Academy