ARM64 GPU PyTorch DLAMI の使用 - Deep Learning AMI

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

ARM64 GPU PyTorch DLAMI の使用

AWS Deep Learning AMI は Arm64 プロセッサベースの GPUsで使用できるようになり、 用に最適化されています PyTorch。ARM64 GPU PyTorch DLAMI にはPyTorch、深層学習のトレーニングと推論のユースケースTorchServe用に、TorchVision、、および で事前設定された Python 環境が含まれています。

PyTorch Python 環境の検証

G5g インスタンスに接続し、次のコマンドを使用して Base Conda 環境を有効化します。

source activate base

コマンドプロンプトには、、 PyTorch TorchVision、およびその他のライブラリを含む基本 Conda 環境で作業していることを示す必要があります。

(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.