기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
ARM64 GPU PyTorch DLAMI 사용
Arm64 프로세서 기반 GPU와 함께 AWS Deep Learning AMI 바로 사용할 수 있으며 최적화된 상태로 제공됩니다. PyTorch ARM64 GPU PyTorch DLAMI에는 딥러닝 트레이닝 및 추론 사용 사례에 PyTorch
PyTorch Python 환경 확인하기
G5g 인스턴스에 연결하고 다음 명령을 사용하여 기본 Conda 환경을 활성화합니다.
source activate base
명령 프롬프트에, 및 기타 라이브러리가 포함된 PyTorch 기본 Conda 환경에서 작업 중임을 나타내야 합니다. TorchVision
(base) $
PyTorch 환경의 기본 도구 경로를 확인하십시오.
(base) $ which python (base) $ which pip (base) $ which conda (base) $ which mamba >>> import torch, torchvision >>> torch.__version__ >>> torchvision.__version__ >>> v = torch.autograd.Variable(torch.randn(10, 3, 224, 224)) >>> v = torch.autograd.Variable(torch.randn(10, 3, 224, 224)).cuda() >>> assert isinstance(v, torch.Tensor)
다음을 사용하여 교육 샘플을 실행하십시오. PyTorch
샘플 MNIST 교육 작업을 실행합니다.
git clone https://github.com/pytorch/examples.git cd examples/mnist python main.py
출력은 다음과 비슷한 형태가 됩니다.
... Train Epoch: 14 [56320/60000 (94%)] Loss: 0.021424 Train Epoch: 14 [56960/60000 (95%)] Loss: 0.023695 Train Epoch: 14 [57600/60000 (96%)] Loss: 0.001973 Train Epoch: 14 [58240/60000 (97%)] Loss: 0.007121 Train Epoch: 14 [58880/60000 (98%)] Loss: 0.003717 Train Epoch: 14 [59520/60000 (99%)] Loss: 0.001729 Test set: Average loss: 0.0275, Accuracy: 9916/10000 (99%)
다음을 사용하여 추론 샘플을 실행합니다. PyTorch
다음 명령을 사용하여 사전 학습된 densenet161 모델을 다운로드하고 다음을 사용하여 추론을 실행합니다. TorchServe
# Set up TorchServe cd $HOME git clone https://github.com/pytorch/serve.git mkdir -p serve/model_store cd serve # Download a pre-trained densenet161 model wget https://download.pytorch.org/models/densenet161-8d451a50.pth >/dev/null # Save the model using torch-model-archiver torch-model-archiver --model-name densenet161 \ --version 1.0 \ --model-file examples/image_classifier/densenet_161/model.py \ --serialized-file densenet161-8d451a50.pth \ --handler image_classifier \ --extra-files examples/image_classifier/index_to_name.json \ --export-path model_store # Start the model server torchserve --start --no-config-snapshots \ --model-store model_store \ --models densenet161=densenet161.mar &> torchserve.log # Wait for the model server to start sleep 30 # Run a prediction request curl http://127.0.0.1:8080/predictions/densenet161 -T examples/image_classifier/kitten.jpg
출력은 다음과 비슷한 형태가 됩니다.
{ "tiger_cat": 0.4693363308906555, "tabby": 0.4633873701095581, "Egyptian_cat": 0.06456123292446136, "lynx": 0.0012828150065615773, "plastic_bag": 0.00023322898778133094 }
다음 명령을 사용하여 densenet161 모델을 등록 취소하고 서버를 중지하세요.
curl -X DELETE http://localhost:8081/models/densenet161/1.0 torchserve --stop
출력은 다음과 비슷한 형태가 됩니다.
{ "status": "Model \"densenet161\" unregistered" } TorchServe has stopped.