[PyTorch] contiguous 연산의 필요성, Grad strides do not match bucket view strides
문제 Grad strides do not match bucket view strides. This may indicate grad was not created according to the gradient layout contract, or that the param's strides changed since DDP was constructed. 위와 같이 에러가 나면서 학습이 안되는 상황이 발생. 해결방법 위와 같이 grad stride 관련 이슈가 난다면, 본인 환경이 ddp 학습인지 체크해보고, 아래와 같이 transpose() 연산이나 permute() 연산에 .contiguous() 를 꼭 붙여준다. transpose().contiguous() permute().contiguous() 이유 즉,..
2023.12.04
[PyTorch] 모델 파라미터 일부만 업데이트 하기
pre-trained model의 일부분만 바꿔서 모델을 학습시키려고 할 때 pre-trained model의 파라미터 일부를 가져와 현재 모델의 state dict을 업데이트 하여 학습해야한다. 즉, pre-trained model의 파라미터를 로드하고, 현재 모델에 덮어 씌워주는 과정이다. 먼저, 아래와 같이 pre-trained model과 현재 model을 각각 로드해준다. pretrained_dict = torch.load(PATH) # pretrained 모델 static dict 로드 model_dict = model.state_dict() # 현재 모델 state dict 로드 그 다음 아래와 같이 pre-trained model의 값들 중에서 현재 model의 state dict과 일치하..
2023.04.06
no image
[TFLite] TensorFlow Lite 개념
TensorFlow Lite 개념 TensorFlow Lite는 모바일과 IoT 기기에 딥러닝 모델을 배포하고 추론하기 위해 구글에서 만든 라이브러리이다. 간단히 말하자면, TFLite를 이용하여 TensorFlow 모델을 안드로이드, iOS, 임베디드 기기에서 사용할 수 있도록 모델을 변환할 수 있다. 이러한 기기에서 사용하기 위해서는 컴퓨팅 리소스가 제한적이기 때문에 이를 위해 TFLite는 모델을 경량화해준다고 보면 된다. TFLite는 모델을 변환하는 Converter와 변환된 모델을 실제로 동작시키는 Interpreter로 이루어져있다. Converter는 파이썬 개발환경에서 사용하고, Interpreter는 사용하려는 기기와 동일한 환경에서 사용된다. 그리고 중요한 특징 중 하나는 양자화를 지..
2023.01.18
[ONNX] Brevitas, QAT 모델을 Standard ONNX 모델로 생성하는 라이브러리
Quantization Aware Training로 학습된 모델은 QuantConv2d, QuantLinear 등의 layer 가 생성되는데 이를 Standard ONNX로 변환 시켜주는 Brevitas 라이브러리가 있다. FAQ(https://github.com/Xilinx/brevitas#faq) 를 보면 아직 알려진 이슈들은 많다. https://github.com/Xilinx/brevitas GitHub - Xilinx/brevitas: Brevitas: quantization-aware training in PyTorch Brevitas: quantization-aware training in PyTorch. Contribute to Xilinx/brevitas development by cre..
2022.07.04
no image
[NVIDIA TAO Toolkit] TAO Toolkit 개요
NVIDIA TAO Toolkit을 이용하여 사전 훈련된 NVIDIA 모델에 custom dataset을 적용하여 Computer Vision(이하 CV) 모델을 만들거나 Conversational AI(이하 Conv AI) models을 만들 수 있는 툴킷이다. 비전 분야에서는 주로 object detection, image classification, segmentation, keypoint estimation 등의 모델들을 fine-tuning 할 수 있다. 특히 pre-trained 모델에 새로운 클래스를 추가할 수도 있고, 다양한 케이스에 맞게 다시 학습 시킬 수 있으며, TAO Toolkit은 학습과 관련된 hyperparameter들을 수정하여 custom AI model을 생성할 수 있다...
2022.05.03
[PyTorch] PyTorch 모델을 저장하는 방법 및 고려해야할 점
PyTorch 모델을 학습 한 뒤, 모델을 저장하고 불러오는 방법은 다음과 같다. 모델 저장하고 불러오기 다음과 같이 PyTorch 모델은 학습한 매개변수를 state_dict 이라고 불리는 internal state dictionary에 저장한다. 이 state 값들은 torch.save 함수를 이용하여 저장 할 수 있다고 한다. 모델의 가중치를 불러와서 저장하려면 저장하려는 모델의 인스턴스를 생성한 다음 load_state_dict() 함수를 사용하여 매개변수를 불러온다. 참고로 state_dict은 dictionary 이며 이 형태에 맞게 데이터를 저장하거나 불러오는 것이 가능하다. 이는 각 계층을 매개변수 Tensor로 매핑하며 학습 가능한 매개변수를 갖는 계층(conv layer, linear ..
2022.03.23
no image
[TensorRT] trtexec dumpProfile
공개되어있는 모델을 TensorRT Engine으로 변환하고, trtexec 에 있는 dumpProfile 플래그를 이용하여 Layer 마다 Profile 해본 결과는 아래와 같다. 이를 이용하여 원하는 속도가 나오도록 모델을 적절하게 만들면 될 듯 하다. time 뿐만 아니라 memory 또는 GPU Utilization도 확인하는 방법이 있는지 찾아봐야겠다. 참고로 Profile에 나와있는 PWN은 PointWiseNode이다. ​ ... 참고자료 1 : https://docs.nvidia.com/deeplearning/tensorrt/developer-guide/index.html#trtexec Developer Guide :: NVIDIA Deep Learning TensorRT Documenta..
2022.03.22
no image
[NVIDIA TAO Toolkit] TAO(Train, Adapt, and Optimize) Toolkit
NVIDIA TAO Toolkit User Guide : https://docs.nvidia.com/tao/tao-toolkit/index.html TAO Toolkit — TAO Toolkit 3.21.11 documentation © Copyright 2021, NVIDIA. Last updated on Nov 29, 2021. docs.nvidia.com NVIDIA TAO Toolkit Release Notes : https://docs.nvidia.com/tao/tao-toolkit/text/release_notes.html Release Notes — TAO Toolkit 3.21.11 documentation Release Contents Components included in this r..
2022.03.15
[TensorRT] Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
ONNX를 TRT로 변환하면 아래와 같은 Warning 메세지가 뜬다. Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32. 성능상의 손실은 없는 것으로 판단되나 정말 성능에 영향이 없는지 실험이 필요하다. 왜 뜨는 것일까? 관련 이슈 : https://github.com/onnx/tensorflow-onnx/issues/883#issuecomment-614561227 Your ONNX model has been generated with INT64 weights, while TensorRT does not nati..
2022.02.23
no image
[TensorRT] ONNX 및 TRT에서 Group Normalization 사용하기 (+ Instance Normalization 이슈)
PyTorch 1.6.0 / ONNX opset 10, 11 / TensorRT 7.2.2.3 환경에서 파이토치의 어떤 모델을 ONNX 모델로 변환하고, ONNX 모델을 TensorRT 모델(+ Dynamic Shape)로 변환한 뒤 Python, C++ 각 환경에서 사용하고자 할 때 아래와 같이 Engine Serialization를 못하는 문제가 발생하였었다. 결론부터 말하자면 TensorRT에서는 Group Normalization을 지원하지 않는다. PyTorch에서 Group Normalization을 사용하게 되면 ONNX와 TensorRT에서 Instance Normalization 노드가 생기게 되는데 이는 TensorRT 에서 지원하지 않는다. Custom Plugin 을 생성해줘야한다...
2022.02.23
no image
[TensorFlow Lite] MobileNet v1 모델의 tflite 파일 구조
https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md GitHub - tensorflow/models: Models and examples built with TensorFlow Models and examples built with TensorFlow. Contribute to tensorflow/models development by creating an account on GitHub. github.com 위 GitHub 에서 다운 받은 mobilenet_v1_1.0_224_quantized_1_metadata_1.tflite 을 netron 에서 확인해보았다. 아래와 같이 구성되어 있으며, type이 ..
2022.02.23
[CUDA] CUDA C/C++ Basics Supercomputing 2011 Tutorial
참고자료 : https://www.nvidia.com/docs/IO/116711/sc11-cuda-c-basics.pdf
2022.02.22