hydro-serving-integrations
This repository contains implementations of integrations with AWS Sagemaker.
Installation
$ pip install hydro-integrations
Before you start
To create shadowing resources we utilize CloudFormation templates. To proceed with the stack creation, make sure that you have the following rights on your AWS IAM user/role.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"lambda:CreateFunction",
"iam:GetRole",
"lambda:InvokeFunction",
"lambda:ListVersionsByFunction",
"iam:CreateRole",
"iam:DeleteRole",
"lambda:GetFunctionConfiguration",
"iam:PutRolePolicy",
"cloudformation:DescribeStacks",
"lambda:PutFunctionConcurrency",
"iam:PassRole",
"cloudformation:DescribeStackEvents",
"lambda:AddPermission",
"cloudformation:CreateStack",
"cloudformation:UpdateStack",
"iam:DeleteRolePolicy",
"cloudformation:DeleteStack",
"lambda:DeleteFunction",
"lambda:PublishVersion",
"lambda:RemovePermission",
"iam:GetRolePolicy"
],
"Resource": [
"arn:aws:cloudformation:*:*:stack/*/*",
"arn:aws:lambda:*:*:function:*",
"arn:aws:iam::*:role/*"
]
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"s3:PutBucketNotification",
"s3:CreateBucket",
"s3:GetBucketNotification",
"s3:GetBucketLocation",
"s3:DeleteBucket",
"s3:GetObject"
],
"Resource": "*"
}
]
}
Usage
from hydro_integrations.aws.sagemaker import TrafficShadowing
from sagemaker.model import Model
from sagemaker.model_monitor.data_capture_config import DataCaptureConfig
# Create Sagemaker Model
model = Model(...)
# Define data capture config
data_capture_config = DataCaptureConfig(
enable_capture=True,
sampling_percentage=100,
destination_s3_uri="s3://bucket/data/captured"
)
# Deploy Sagemaker model with the specified
# data capture config
predictor = model.deploy(
initial_instance_count=1,
instance_type='ml.m4.xlarge',
endpoint_name='model-shadowing-example',
data_capture_config=data_capture_config
)
# Deploy TrafficShadowing CloudFormation stack.
shadowing = TrafficShadowing(
hydrosphere_endpoint="https://<hydrosphere>",
s3_data_training_uri="s3://bucket/data/training",
data_capture_config=data_capture_config,
)
shadowing.deploy()
How it works
Once you've enabled data capturing on your AWS Sagemaker Endpoint, you can deploy TrafficShadowing CloudFormation stack, which contains AWS Lambda function responsible for shadowing traffic from configured S3 bucket to Hydrosphere for analysis.
Note, by default destination_s3_uri parameter, specified in the DataCaptureConfig, represents a prefix where your requests will be stored. In the example above, we've deployed a model with the endpoint name model-shadowing-example. This means that all requests collected from that model endpoint will be placed under s3://bucket/data/captured/model-shadowing-example path. The Lambda function, deployed as part of the TrafficShadowing stack, expects that training data is organized in the same way, i.e., data used for training the model-shadowing-example model is placed under s3://bucket/data/training/model-shadowing-example path. Lambda function then finds the biggest .csv file under that directory and uploads it to the Hydrosphere platform for building profiles for your model.
Release files for hydro-integrations 2.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hydro_integrations-2.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / hydro_integrations-2.3.0-py3-none-any.whl
| Download URL | hydro_integrations-2.3.0-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
959198c74a977b6a7eecc436b22660c6d80a6a5b3d35da17d5ae17a9388d35f6
|
|
BLAKE2b-256 checksum How to use checksums |
5616e6c905edcebd5839c105eecdb743e92e34f2cd43962c06a88fc9260fb3f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.10
|