HydroSDK integrations
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hydro_integrations-2.3.0-py3-none-any.whl.
File metadata
- Download URL: hydro_integrations-2.3.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
959198c74a977b6a7eecc436b22660c6d80a6a5b3d35da17d5ae17a9388d35f6
|
|
| MD5 |
71917c7d6ed11d144fd7cbba3d708bbe
|
|
| BLAKE2b-256 |
5616e6c905edcebd5839c105eecdb743e92e34f2cd43962c06a88fc9260fb3f4
|