Last active
February 17, 2023 00:34
-
-
Save DaisukeMiyamoto/485306807d64747c10e848f754e24158 to your computer and use it in GitHub Desktop.
AWS Inferentia example for AWS Batch with NEURON SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example neuron-container dockerfile. by midaisuk | |
# To build: | |
# docker build -t neuron-container . | |
# Prepare application: | |
# before launch the docker image, you need to prepare some files based on the document and upload to S3 bucket. | |
# https://github.com/aws/aws-neuron-sdk/blob/master/docs/tensorflow-neuron/tutorial-compile-infer.md | |
# resnet50_neuron.zip | |
# infer_resnet50.py | |
# kitten_small.jpg | |
# Note: the container must start with CAP_SYS_ADMIN + CAP_IPC_LOCK capabilities in order | |
# to map the memory needed from the Infernetia devices. These capabilities will | |
# be dropped following initialization. | |
# i.e. To start the container with required capabilities: | |
# docker run --env AWS_NEURON_VISIBLE_DEVICES="0" -v /run:/run -it neuron-container | |
FROM amazonlinux:2 | |
RUN echo $'[neuron] \n\ | |
name=Neuron YUM Repository \n\ | |
baseurl=https://yum.repos.neuron.amazonaws.com \n\ | |
enabled=1' > /etc/yum.repos.d/neuron.repo | |
RUN rpm --import https://yum.repos.neuron.amazonaws.com/GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB | |
RUN yum install -y \ | |
aws-neuron-runtime-base \ | |
aws-neuron-runtime \ | |
aws-neuron-tools \ | |
python3 \ | |
gcc-c++ \ | |
unzip tar gzip | |
RUN python3 -m venv neuron_venv && \ | |
source neuron_venv/bin/activate && \ | |
pip install -U pip && \ | |
echo $'[global] \n\ | |
extra-index-url = https://pip.repos.neuron.amazonaws.com' > $VIRTUAL_ENV/pip.conf && \ | |
pip install pillow && \ | |
pip install neuron-cc && \ | |
pip install tensorflow-neuron && \ | |
pip install awscli | |
RUN echo $'\ | |
source neuron_venv/bin/activate \n\ | |
aws s3 cp s3://midaisuk-neuron/resnet50_neuron.zip . \n\ | |
aws s3 cp s3://midaisuk-neuron/infer_resnet50.py . \n\ | |
aws s3 cp s3://midaisuk-neuron/kitten_small.jpg . \n\ | |
unzip resnet50_neuron.zip \n\ | |
python infer_resnet50.py'\ | |
> /tmp/job.sh &&\ | |
chmod +x /tmp/job.sh | |
ENV PATH="/opt/aws/neuron/bin:${PATH}" | |
CMD /tmp/job.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"LaunchTemplateVersions": [ | |
{ | |
"LaunchTemplateId": "lt-06b3aac8f5a3ddc92", | |
"LaunchTemplateName": "inf1-neuron-rtd", | |
"VersionNumber": 7, | |
"CreateTime": "2020-05-14T20:43:38.000Z", | |
"CreatedBy": "arn:aws:iam::441877424058:user/midaisuk", | |
"DefaultVersion": true, | |
"LaunchTemplateData": { | |
"EbsOptimized": false, | |
"ImageId": "ami-0aee8ced190c05726", | |
"UserData": "TUlNRS1WZXJzaW9uOiAxLjAKQ29udGVudC1UeXBlOiBtdWx0aXBhcnQvbWl4ZWQ7IGJvdW5kYXJ5PSI9PU1ZQk9VTkRBUlk9PSIKCi0tPT1NWUJPVU5EQVJZPT0KQ29udGVudC1UeXBlOiB0ZXh0L3gtc2hlbGxzY3JpcHQ7IGNoYXJzZXQ9InVzLWFzY2lpIgoKIyEvYmluL2Jhc2gKdGVlIC9ldGMveXVtLnJlcG9zLmQvbmV1cm9uLnJlcG8gPiAvZGV2L251bGwgPDxFT0YKW25ldXJvbl0KbmFtZT1OZXVyb24gWVVNIFJlcG9zaXRvcnkKYmFzZXVybD1odHRwczovL3l1bS5yZXBvcy5uZXVyb24uYW1hem9uYXdzLmNvbQplbmFibGVkPTEKbWV0YWRhdGFfZXhwaXJlPTAKRU9GCgpycG0gLS1pbXBvcnQgaHR0cHM6Ly95dW0ucmVwb3MubmV1cm9uLmFtYXpvbmF3cy5jb20vR1BHLVBVQi1LRVktQU1BWk9OLUFXUy1ORVVST04uUFVCCgp5dW0gaW5zdGFsbCAteSBhd3MtbmV1cm9uLXJ1bnRpbWUtYmFzZSBhd3MtbmV1cm9uLXJ1bnRpbWUgYXdzLW5ldXJvbi10b29scyBweXRob24zIGdjYy1jKysgdW56aXAKCi0tPT1NWUJPVU5EQVJZPT0tLQ==" | |
} | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIME-Version: 1.0 | |
Content-Type: multipart/mixed; boundary="==MYBOUNDARY==" | |
--==MYBOUNDARY== | |
Content-Type: text/cloud-config; charset="us-ascii" | |
#!/bin/bash | |
tee /etc/yum.repos.d/neuron.repo > /dev/null <<EOF | |
[neuron] | |
name=Neuron YUM Repository | |
baseurl=https://yum.repos.neuron.amazonaws.com | |
enabled=1 | |
metadata_expire=0 | |
EOF | |
rpm --import https://yum.repos.neuron.amazonaws.com/GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB | |
yum install -y aws-neuron-runtime-base aws-neuron-runtime aws-neuron-tools python3 gcc-c++ unzip | |
--==MYBOUNDARY==-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment