Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mlflow modules #5

Merged
merged 21 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

=======

## UNRELEASED

### **Added**

- added `mlflow-image` and `mlflow-fargate` modules
- added `sagemaker-endpoint` module

### **Changed**

### **Removed**

=======
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The modules in this repository are decoupled from each other and can be aggregat

The modules in this repository are / must be generic for reuse without affiliation to any one particular project in Machine Learning Operations domain.

All modules in this repository adhere to the module strutucture defined in the the [SeedFarmer Guide](https://seed-farmer.readthedocs.io/en/latest)
All modules in this repository adhere to the module structure defined in the the [SeedFarmer Guide](https://seed-farmer.readthedocs.io/en/latest)

- [Project Structure](https://seed-farmer.readthedocs.io/en/latest/project_development.html)
- [Module Development](https://seed-farmer.readthedocs.io/en/latest/module_development.html)
Expand All @@ -22,6 +22,13 @@ All modules in this repository adhere to the module strutucture defined in the t
|-----------------------------------------------------------------------------|-------------------------------------------------|
| [SageMaker Endpoint Module](modules/sagemaker/sagemaker-endpoint/README.md) | Creates SageMaker real-time inference endpoint. |

### Mlflow Modules

| Type | Description |
|-------------------------------------------------------------------------|---------------------------------|
| [Mlflow Image Module](modules/mlflow/mlflow-image/README.md) | Creates Mlflow container image. |
| [Mlflow on AWS Fargate Module](modules/mlflow/mlflow-fargate/README.md) | Runs Mlflow on AWS Fargate. |

### Industry Data Framework (IDF) Modules

The modules in this repository are compatible with [Industry Data Framework (IDF) Modules](https://github.com/awslabs/idf-modules) and can be used together within the same deployment. Refer to `examples/manifests` for examples.
6 changes: 6 additions & 0 deletions manifests/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ forceDependencyRedeploy: true
groups:
- name: networking
path: manifests/networking-modules.yaml
- name: storage
path: manifests/storage-modules.yaml
- name: sagemaker-studio
path: manifests/sagemaker-studio-modules.yaml
- name: images
path: manifests/images-modules.yaml
- name: mlflow
path: manifests/mlflow-modules.yaml
targetAccountMappings:
- alias: primary
accountId:
Expand Down
9 changes: 9 additions & 0 deletions manifests/images-modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: mlflow-image
path: modules/mlflow/mlflow-image
parameters:
- name: ecr-repository-name
valueFrom:
moduleMetadata:
group: storage
name: ecr-mlflow
key: EcrRepositoryName
27 changes: 27 additions & 0 deletions manifests/mlflow-modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: mlflow-fargate
path: modules/mlflow/mlflow-fargate
parameters:
- name: vpc-id
valueFrom:
moduleMetadata:
group: networking
name: networking
key: VpcId
- name: subnet-ids
valueFrom:
moduleMetadata:
group: networking
name: networking
key: PrivateSubnetIds
- name: ecr-repository-name
valueFrom:
moduleMetadata:
group: storage
name: ecr-mlflow
key: EcrRepositoryName
- name: artifacts-bucket-name
valueFrom:
moduleMetadata:
group: storage
name: buckets
key: ArtifactsBucketName
2 changes: 1 addition & 1 deletion manifests/sagemaker-studio-modules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ path: git::https://github.com/awslabs/idf-modules.git//modules/ml/sagemaker-stud
targetAccount: primary
parameters:
- name: studio_domain_name
value: mlops
value: mlops-studio
- name: vpc_id
valueFrom:
moduleMetadata:
Expand Down
15 changes: 15 additions & 0 deletions manifests/storage-modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: ecr-mlflow
path: git::https://github.com/awslabs/idf-modules.git//modules/storage/ecr?ref=release/1.3.0&depth=1
parameters:
- name: repository_name
value: "ecr-mlflow"
---
name: buckets
path: git::https://github.com/awslabs/idf-modules.git//modules/storage/buckets?ref=release/1.3.0&depth=1
targetAccount: primary
targetRegion: us-east-1
parameters:
- name: encryption-type
value: SSE
- name: retention-type
value: RETAIN
83 changes: 83 additions & 0 deletions modules/mlflow/mlflow-fargate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Mlflow on Fargate module

## Description

This module runs Mlflow on AWS Fargate.

By default, uses EFS for backend storage.

### Architecture

![Mlflow on AWS Fargate Module Architecture](docs/_static/mlflow-fargate-module-architecture.png "Mlflow on AWS Fargate Module Architecture")

## Inputs/Outputs

### Input Parameters

#### Required

- `vpc-id`: The VPC-ID that the ECS cluster will be created in.
- `subnet-ids`: The subnets that the Fargate task will use.
- `ecr-repository-name`: The name of the ECR repository to pull the image from.
- `artifacts-bucket-name`: Name of the artifacts store bucket

#### Optional

- `ecs-cluster-name`: Name of the ECS cluster.
- `service-name`: Name of the service.
- `task-cpu-units`: The number of cpu units used by the Fargate task.
- `task-memory-limit-mb`: The amount (in MiB) of memory used by the Fargate task.
- `lb-access-logs-bucket-name`: Name of the bucket to store load balancer access logs
- `lb-access-logs-bucket-prefix`: Prefix for load balancer access logs

### Sample manifest declaration

```yaml
name: mlflow-fargate
path: modules/mlflow/mlflow-fargate
parameters:
- name: vpc-id
valueFrom:
moduleMetadata:
group: networking
name: networking
key: VpcId
- name: subnet-ids
valueFrom:
moduleMetadata:
group: networking
name: networking
key: PrivateSubnetIds
- name: ecr-repository-name
valueFrom:
moduleMetadata:
group: storage
name: ecr-mlflow
key: EcrRepositoryName
- name: artifacts-bucket-name
valueFrom:
moduleMetadata:
group: storage
name: buckets
key: ArtifactsBucketName
```

### Module Metadata Outputs

- `ECSClusterName`: Name of the ECS cluster.
- `ServiceName`: Name of the service.
- `LoadBalancerDNSName`: Load balancer DNS name.
- `LoadBalancerAccessLogsBucketArn`: Load balancer access logs bucket arn
- `EFSFileSystemId`: EFS file system id.

#### Output Example

```
{
"ECSClusterName": "mlops-mlops-mlflow-mlflow-fargate-EcsCluster97242B84-xxxxxxxxxxxx",
"ServiceName": "mlops-mlops-mlflow-mlflow-fargate-MlflowLBServiceEBACC043-xxxxxxxxxxxx",
"LoadBalancerDNSName": "xxxxxxxxxxxx.elb.us-east-1.amazonaws.com",
"LoadBalancerAccessLogsBucketArn": "arn:aws:s3:::xxxxxxxxxxxx",
"EFSFileSystemId": "fs-xxxxxxxxxxx",
}
```
93 changes: 93 additions & 0 deletions modules/mlflow/mlflow-fargate/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

import json
import os

import aws_cdk

from stack import MlflowFargateStack


def _param(name: str) -> str:
return f"SEEDFARMER_PARAMETER_{name}"


project_name = os.getenv("SEEDFARMER_PROJECT_NAME", "")
deployment_name = os.getenv("SEEDFARMER_DEPLOYMENT_NAME", "")
module_name = os.getenv("SEEDFARMER_MODULE_NAME", "")
app_prefix = f"{project_name}-{deployment_name}-{module_name}"

DEFAULT_ECS_CLUSTER_NAME = None
DEFAULT_SERVICE_NAME = None
DEFAULT_TASK_CPU_UNITS = 4 * 1024
DEFAULT_TASK_MEMORY_LIMIT_MB = 8 * 1024
DEFAULT_AUTOSCALE_MAX_CAPACITY = 2
DEFAULT_LB_ACCESS_LOGS_BUCKET_NAME = None
DEFAULT_LB_ACCESS_LOGS_BUCKET_PREFIX = None

environment = aws_cdk.Environment(
account=os.environ["CDK_DEFAULT_ACCOUNT"],
region=os.environ["CDK_DEFAULT_REGION"],
)

vpc_id = os.getenv(_param("VPC_ID"))
subnet_ids = json.loads(os.getenv(_param("SUBNET_IDS"), "[]"))
ecs_cluster_name = os.getenv(_param("ECS_CLUSTER_NAME"), DEFAULT_ECS_CLUSTER_NAME)
service_name = os.getenv(_param("SERVICE_NAME"), DEFAULT_SERVICE_NAME)
ecr_repo_name = os.getenv(_param("ECR_REPOSITORY_NAME"))
task_cpu_units = os.getenv(_param("TASK_CPU_UNITS"), DEFAULT_TASK_CPU_UNITS)
task_memory_limit_mb = os.getenv(_param("TASK_MEMORY_LIMIT_MB"), DEFAULT_TASK_MEMORY_LIMIT_MB)
autoscale_max_capacity = os.getenv(_param("AUTOSCALE_MAX_CAPACITY"), DEFAULT_AUTOSCALE_MAX_CAPACITY)
artifacts_bucket_name = os.getenv(_param("ARTIFACTS_BUCKET_NAME"))
lb_access_logs_bucket_name = os.getenv(_param("LB_ACCESS_LOGS_BUCKET_NAME"), DEFAULT_LB_ACCESS_LOGS_BUCKET_NAME)
lb_access_logs_bucket_prefix = os.getenv(_param("LB_ACCESS_LOGS_BUCKET_PREFIX"), DEFAULT_LB_ACCESS_LOGS_BUCKET_PREFIX)

if not vpc_id:
raise ValueError("Missing input parameter vpc-id")

if not ecr_repo_name:
raise ValueError("Missing input parameter ecr-repository-name")

if not artifacts_bucket_name:
raise ValueError("Missing input parameter artifacts-bucket-name")


app = aws_cdk.App()
stack = MlflowFargateStack(
scope=app,
id=app_prefix,
app_prefix=app_prefix,
vpc_id=vpc_id,
subnet_ids=subnet_ids,
ecs_cluster_name=ecs_cluster_name,
service_name=service_name,
ecr_repo_name=ecr_repo_name,
task_cpu_units=int(task_cpu_units),
task_memory_limit_mb=int(task_memory_limit_mb),
autoscale_max_capacity=int(autoscale_max_capacity),
artifacts_bucket_name=artifacts_bucket_name,
lb_access_logs_bucket_name=lb_access_logs_bucket_name,
lb_access_logs_bucket_prefix=lb_access_logs_bucket_prefix,
env=aws_cdk.Environment(
account=os.environ["CDK_DEFAULT_ACCOUNT"],
region=os.environ["CDK_DEFAULT_REGION"],
),
)


aws_cdk.CfnOutput(
scope=stack,
id="metadata",
value=stack.to_json_string(
{
"ECSClusterName": stack.cluster.cluster_name,
"ServiceName": stack.service.service.service_name,
"LoadBalancerDNSName": stack.service.load_balancer.load_balancer_dns_name,
"LoadBalancerAccessLogsBucketArn": stack.lb_access_logs_bucket.bucket_arn,
"EFSFileSystemId": stack.fs.file_system_id,
}
),
)

app.synth()
3 changes: 3 additions & 0 deletions modules/mlflow/mlflow-fargate/coverage.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit =
tests/*
35 changes: 35 additions & 0 deletions modules/mlflow/mlflow-fargate/deployspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
publishGenericEnvVariables: true
deploy:
phases:
install:
commands:
- npm install -g aws-cdk@2.128.0
- pip install -r requirements.txt
pre_build:
commands:
- echo "Prebuild stage"
build:
commands:
- cdk deploy --require-approval never --progress events --app "python app.py" --outputs-file ./cdk-exports.json
# Export metadata
- seedfarmer metadata convert -f cdk-exports.json || true
post_build:
commands:
- echo "Build successful"
destroy:
phases:
install:
commands:
- npm install -g aws-cdk@2.128.0
- pip install -r requirements.txt
pre_build:
commands:
- echo "Prebuild stage"
build:
commands:
- cdk destroy --force --app "python app.py"
post_build:
commands:
- echo "Destroy successful"

build_type: BUILD_GENERAL1_SMALL
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile modified="2024-02-16T16:21:46.131Z" host="design-inspector.a2z.com" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36" etag="8RrXlRqHpwgGKitaxPPN" version="10.1.8" type="device"><diagram id="MkE2kDHcsj_W3wBg-wOKL" name="Page-1">7V1bd5s4EP41eVSOBOL26NhJN7vtbk/Spu1TjgBh02DwARzb+fU74mIDxsRp7BgS2pzEGoSuo5lPnwZ8Jg+ny08hm02+BDb3ziRsL8/k0ZkkGSqF30KwS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j7ki/6KciXw3h22m3PfuD3d/Wevec3en7jRfyG/D74jaM/9NxxfuN7dICvNWBW5i2eBRJF57gNJPLd+3zqDZIi9yAakv5eMOthnICMukdU67mIAgqp5VJOxRYQUjlHqXmvl1zDFqhHZwvkbmOKA1u01mCKZ9w50y0F27aNGDN0RHWLI0aYhRRmKA7smSnXDjwyLSALOr2VTm1yv3vu3O75bnJ39/D34NMP5XYJeOW/H4M7+i9Sj/f6rtqvLMyv/MFXFrY/nmLHENc8Ztrh7yxs0qMO+N/m5rfN/z63r2jWuK7vj9r3BXDvfkPek0jvjkRq2ab+8kp8zdFj4M2nr49X4E50H8UMBi2094I7/XveO/RWsP497/u8Fay4BE759YVq5V1g8psHkjSjoa5C0/7Joe4ghT6Q5H2zX2Xw0rNgb4Y2xagFQVzI+kmozhexVEH4Pw==</diagram></mxfile>
35 changes: 35 additions & 0 deletions modules/mlflow/mlflow-fargate/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[tool.black]
line-length = 120
target-version = ["py36", "py37", "py38"]
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| \.env
| _build
| buck-out
| build
| dist
| codeseeder.out
)/
'''

[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 120
py_version = 36
skip_gitignore = false

[tool.pytest.ini_options]
addopts = "-v --cov=. --cov-report term --cov-config=coverage.ini --cov-fail-under=80"
pythonpath = [
"."
]
Loading
Loading