Recent Posts
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Torch
- SSL
- Vision
- FineGrained
- dl
- FGVC
- Depth estimation
- PRML
- REACT
- web
- nerf
- CV
- 딥러닝
- clean code
- 머신러닝
- pytorch
- Meta Learning
- 자료구조
- cs
- 3d
- Front
- math
- Python
- nlp
- GAN
- classification
- computervision
- ML
- 알고리즘
- algorithm
- 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/
https://tutorials.pytorch.kr/intermediate/ddp_tutorial.html
'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 |
Comments