일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- algorithm
- nlp
- SSL
- Python
- 머신러닝
- 알고리즘
- FGVC
- dl
- CV
- Depth estimation
- computervision
- web
- REACT
- clean code
- Vision
- Torch
- nerf
- classification
- PRML
- 자료구조
- pytorch
- 딥러닝
- ML
- FineGrained
- 3d
- math
- cs
- GAN
- Front
- Meta Learning
- Today
- Total
KalelPark's LAB
[CODE] Multi-GPU 활용하기 본문

Problem
SSL로 Batchsize를 최대한 늘려 학습하고자 하는데, 잘 안되어 분산처리를 봤다. 사실 연관은 없는 것 같다.. (불가능.ㅠ)
결론 저희 연구실에서는 SSL을 하려면,TeslaV100을 하나 장만해야 함을 느꼈습니다..
import os
local_rank=int(os.environ["LOCAL_RANK"])
import torch
import torch.distributed as dist
from torch.utils.data.distributed import DistributedSampler
import torchvision.transforms as T
from torch.utils.data import DataLoader
from torchvision.models import efficientnet_b0
from torchvision.datasets import CIFAR100
import torchvision
dist.init_process_group(backend="nccl")
transforms = T.Compose([
T.Resize((224, 224)),
T.ToTensor()
])
train_path = "/home/psboys/shared/hdd_ext/nvme1/vision/imageNet/train/"
train_dataset = torchvision.datasets.ImageFolder(train_path, transforms)
train_sampler = DistributedSampler(train_dataset, shuffle=True)
train_loader = DataLoader(train_dataset, batch_size=4096, sampler=train_sampler)
model = efficientnet_b0(num_classes=1000).cuda(local_rank)
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
criterion_CE = torch.nn.CrossEntropyLoss()
for epoch in range(100):
for img, label in train_loader:
img = img.cuda(local_rank)
label = label.cuda(local_rank)
output = model(img)
loss = criterion_CE(output, label)
optimizer.zero_grad()
loss.backward()
optimizer.step()
print(epoch)
# CUDA_VISIBLE_DEVICES=1,2,5,7 torchrun --nproc_per_node 3 dummy.py
# CUDA_VISIBLE_DEVICES=1,2,5,6,7 torchrun --nproc_per_node 5 ddp.py

Reference
https://rlawjdghek.github.io/pytorch%20&%20tensorflow%20&%20coding/DataParallel/
파이토치 DataParallel, DistributedDataParallel, apex, amp 정리
파이토치 DataParallel, DistributedDataParallel, apex, amp 정리
rlawjdghek.github.io
A Comprehensive Tutorial to Pytorch DistributedDataParallel
Entire workflow for pytorch DistributedDataParallel, including Dataloader, Sampler, training, and evaluating. Insights&Codes.
medium.com
https://tutorials.pytorch.kr/intermediate/ddp_tutorial.html
분산 데이터 병렬 처리 시작하기
저자: Shen Li 감수: Joe Zhu 번역: 조병근 선수과목(Prerequisites): PyTorch 분산 처리 개요, 분산 데이터 병렬 처리 API 문서, 분산 데이터 병렬 처리 문서. 분산 데이터 병렬 처리(DDP)는 여러 기기에서 실행
tutorials.pytorch.kr
'Data Science > CODE' 카테고리의 다른 글
[CODE] Gradient Accumulate이란? (0) | 2023.03.20 |
---|---|
[CODE] MixUp 분할해서 구현하기 (3) | 2023.03.20 |
[CODE] Masked AutoEncoder CODE로 살펴보기 (0) | 2023.03.16 |
[CODE] How to making useful logger? (0) | 2023.03.15 |
[CODE] NLP's Study for BERT tutorial (1) | 2023.03.13 |