라이브러리
-
Multi-gpu에서 학습된 모델의 weights를 Single-gpu (or CPU)에서 불러오기라이브러리/PyTorch 2022. 9. 12. 03:38
model = torchvision.models.segmentation.__dict__['deeplabv3_resnet50'](pretrained=False, aux_loss=False) device = torch.device("cpu") model.classifier[-1] = torch.nn.Conv2d(model.classifier[-1].in_channels, 1, kernel_size=model.classifier[-1].kernel_size) # change number of outputs to 1 model.to(device) # checkpoint = torch.load("output/segmentation/deeplabv3_resnet50_random/best.pt", map_locati..
-
-
Don't forget to accumulate the Gradient라이브러리/PyTorch 2022. 4. 26. 11:24
ViT와 같은 self-Attention based model 또는 CNN을 Group Normalization + Weight Standardization (Batch Normalization 대신)와 사용중이라면 gradient를 accumulate하는 것을 잊지마세요! Batch Normalization이 사용되고 있을 땐 gradient accumulation이 효과적이지 않을 지도 모르지만, 위와 같은 모델을 사용중이고 GPU VRAM이 한정적이여서 배치 사이즈를 작게 세팅하는 경우 효과적일 거야. AMP+Gradient accumulation은 더 효과적! from torch.cuda import amp scaler = amp.GradScaler() n_accumulate = 16 # n_ac..
-
TF Keras 학습 속도 줄이기 (30%)라이브러리/Tensorflow keras 2022. 4. 26. 10:15
만약 최신 GPU로 TF Keras를 이용하고 있다면, 몇 줄만 추가해서 30% 정도 학습속도를 줄일 수 있다. from tensorflow.keras import mixed_precision policy = mixed_precision.Policy('mixed_float16') mixed_precision.set_global_policy(policy) *주의: TF에선 마지막 레이어가 softmax (sigmoid인 경우도)라면 stability를 위해 float32로 바꾸는 걸 추천함! output_layer = tf.keras.layers.Activation('sigmoid', dtype='float32')(output_layer) 참고 https://www.kaggle.com/competition..
-
gc.collect, torch.cuda.empty_cache()라이브러리/PyTorch 2022. 4. 25. 23:53
gc.collect: Forces an immediate garbage collection of all generations torch.cuda.empty_cache(): Releases all unoccupied cached memory currently held by the caching allocator so that those can be used in other GPU application and visible in nvidia-smi
-
Tensor moduels라이브러리/PyTorch 2022. 3. 7. 14:18
Tensor moduels tensor는 NumPy arrays와 컨셉적으로 유사하다. tensorsms n-차원 배열로 수학적 함수를 적용하고, GPU를 이용해 계산을 가속화 할 수 있으며, computational graph와 gradients 를 추적하는데 사용 될 수 있다. PyTorch에서 tneosrs는 연속적인 메모리 덩어리(contiguous chunks of memory)에 저장된 수치 데이터의 1차원 배열에 대한 views로 구현된다. 이런 배열은 stroage instances라 불린다. 모든 PyTorch tensor는 storage 속성을 갖고 있는데, 이를 호출함으로써 기본 storage 인스턴스(the underlying storage instance)를 출력할 수 있다. po..