This code sample demonstrates how to integrate SageMaker Edge Manager with Greengrass v2 via components. At the end of the sample, you will have a Python-based component running inference at the edge with the SageMaker Edge Manager binary agent, and a YOLOv3 Darknet model.
In the folder examples/mlops-console-example there are two additional examples that use SageMaker Edge Manager and Greengrass v2 to implement a machine learning operations flow on NXP or virtual devices. They include step by step implementation instructions from the AWS Console.
Ensure you have AWS CLI installed, a IAM user with an access key, and a named profile configured:
NOTE: In this demo, we are using a NVIDIA Xavier NX / AGX Xavier development kit. Please adjust PLATFORM as required for your device.
Valid PLATFORM options include linux-armv8, linux-x64, windows-x86, and windows-x64.
Valid TARGET_DEVICE options can be found here: Supported edge devices for SageMaker Neo.
export AWS_PROFILE=<PROFILE-NAME>
export AWS_REGION=<REGION>
export PLATFORM=linux-armv8
export TARGET_DEVICE=jetson_xavier
export SSH_USER=<USER>
export SSH_HOST=<IP_ADDRESS>
export IOT_THING_NAME=<THING_NAME>
export BUCKET_NAME=<BUCKET_NAME>
chmod +x ./scripts/*.sh
aws s3 mb s3://$BUCKET_NAME --profile $AWS_PROFILE --region $AWS_REGION
./scripts/download_upload_sample_model.sh $AWS_PROFILE $BUCKET_NAME
export SM_ROLE_NAME=smem-role
./scripts/create_sagemaker_role.sh $AWS_PROFILE $SM_ROLE_NAME
./scripts/create_neo_compilation_job.sh $AWS_PROFILE $BUCKET_NAME $AWS_REGION $SM_ROLE_NAME $TARGET_DEVICE
./scripts/package_neo_model.sh $AWS_PROFILE $BUCKET_NAME $AWS_REGION $SM_ROLE_NAME
NOTE: this is done over SSH to avoid installing AWS CLI and credentials directly on the device.
./scripts/install-ggv2-ssh.sh $AWS_PROFILE $SSH_USER $SSH_HOST $AWS_REGION $IOT_THING_NAME
./scripts/download_edge_manager_package.sh $AWS_PROFILE $PLATFORM
./scripts/add_agent_artifact.sh $AWS_PROFILE $PLATFORM 0.1.0 $AWS_REGION
pip install grpcio-tools
pip install --upgrade protobuf
./scripts/compile_add_python_stub_artifacts.sh $PLATFORM aws.sagemaker.edgeManagerPythonClient 0.1.0
./scripts/create_device_fleet_register_device.sh $AWS_PROFILE $AWS_REGION $BUCKET_NAME $IOT_THING_NAME
- In all of the recipe files, replace YOUR_BUCKET_NAME with the value assigned to $BUCKET_NAME
./scripts/upload_component_version.sh $AWS_PROFILE com.model.darknet 0.1.0 $BUCKET_NAME $AWS_REGION
./scripts/upload_component_version.sh $AWS_PROFILE aws.sagemaker.edgeManagerPythonClient 0.1.0 $BUCKET_NAME $AWS_REGION
NOTE: you cannot overwrite an existing component version. To upload a new version, you will need to update the version number in the artifact directory, the recipe file name, and the version numbers in the recipe file. As an alternative, you can also delete a specific component version. For this, use the following command:
./delete_component.sh $AWS_PROFILE <COMPONENT-NAME> <COMPONENT-VERSION> $AWS_REGION
Create a new Greengrass v2 deployment, including the following components:
- com.model.darknet (v0.1.0)
- aws.greengrass.SageMakerEdgeManager (>=1.0.2)
- aws.sagemaker.edgeManagerPythonClient (v0.1.0)
Configure the aws.greengrass.SageMakerEdgeManager component, and use the following JSON as the Configuration to merge value. Be sure to update the BucketName
attribute.
{
"CaptureDataPeriodicUpload": "false",
"CaptureDataPeriodicUploadPeriodSeconds": "8",
"DeviceFleetName": "ggv2-smem-fleet",
"BucketName": "<YOUR_BUCKET_NAME>",
"CaptureDataBase64EmbedLimit": "3072",
"CaptureDataPushPeriodSeconds": "4",
"SagemakerEdgeLogVerbose": "false",
"CaptureDataBatchSize": "10",
"CaptureDataDestination": "Cloud",
"FolderPrefix": "sme-capture",
"UnixSocketName": "/tmp/sagemaker_edge_agent_example.sock",
"CaptureDataBufferSize": "30"
}
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.