philschmid RSS feed 09月30日
MLOps与Efsync工具介绍
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍了MLOps在机器学习生产中的应用,特别是其在DevOps基础上的连续训练(CT)组件,包括持续集成(CI)、持续交付(CD)和连续训练(CT)。同时,文章重点介绍了作者开发的MLOps工具eFSync,该工具解决了在AWS Lambda等无服务器环境中存储大型机器学习模型(如BERT)的难题。eFSync能够自动同步S3或本地文件系统中的文件到AWS EFS,并支持直接在EFS文件系统中安装依赖项,简化了无服务器机器学习部署流程。工具支持多种配置方式,包括yaml配置文件和SDK调用,覆盖了从安装Python依赖到同步模型文件的多种使用场景。

🔧 MLOps通过持续集成(CI)、持续交付(CD)和持续训练(CT)增强DevOps,支持机器学习模型在生产环境中的高效部署和管理。

💾 efsync工具解决了无服务器机器学习中存储大型模型(如BERT)的难题,通过自动同步S3或本地文件到AWS EFS,并支持在EFS中安装依赖项。

📁 efsync支持多种配置方式,包括yaml配置文件和SDK调用,覆盖了从安装Python依赖到同步模型文件的多种使用场景,简化了无服务器机器学习部署流程。

⚙️ 该工具通过AWS Lambda runtime直接在EFS文件系统中安装依赖,避免了传统方法中需要通过EC2实例上传文件的繁琐步骤,提高了效率。

🔗 efsync提供了详细的配置选项,如标准配置、pip依赖配置和S3配置,用户可以根据需求灵活调整,满足不同的使用场景。

Part of using Machine Learning successfully in production is the use of MLOps. MLOps enhances DevOps with continuoustraining (CT). The main components of MLOps therefore include continuous integration (CI), continuous delivery (CD), andcontinuous training (CT).Nvidia wrote an article about what MLOps is in detail.

My Name is Philipp and I live in Nuremberg, Germany. Currently, I am working as a machine learning engineer at atechnology incubation startup. At work, I design and implement cloud-native machine learning architectures for fin-techand insurance companies. I am a big fan of Serverless and providing machine learning models in a serverless fashion. Ialready wrote two articles about how to use Deep Learning models like BERT in a Serverless Environment like AWS Lambda.

A big hurdle to overcome in serverless machine learning with tools like AWS Lambda,Google Cloud Functions,Azure Functions was storage.Tensorflow and Pytorch are having a huge size and newer "State ofthe Art" models like BERT have a size of over 300MB.

In July this year, AWS added support forAmazon Elastic File System (EFS), ascalable and elastic NFS file system for AWS Lambda. This allows us to mount AWS EFS filesystems toAWS Lambda functions.

Until today it was very difficult to sync dependencies or model files to an AWS EFS Filesystem. You could do it withAWS Datasync or you could start an EC2instance in the same subnet and VPC and upload your files from there.

For this reason, I have built an MLOps toolkit called efsync. Efsync is a CLI/SDK tool, which syncs files from S3 orlocal filesystem automatically to AWS EFS and enables you to install dependencies with the AWS Lambda runtime directlyinto your EFS filesystem. The CLI is easy to use, you only need access to an AWS Account and an AWS EFS-filesystem upand running.


Architecture


Quick Start

    Install via pip3
    sync your pip dependencies or files to AWS EFS
# using the CLIefsync -cf efsync.yaml # using the SDKfrom efsync import efsyncefsync('efsync.yaml')

Use Cases

Efsync covers 5 use cases. On the one hand, it allows you to install the needed dependencies, on the other hand, efsynchelps you to get your models ready, be it via sync from S3 to EFS or a local upload with SCP. I created an exampleJupyter Notebooks for each use case.

The 5 use cases consist of:

    install Python dependencies with the AWS Lambda runtime directly into an EFS filesystem and use them in an AWS Lambdafunction. Examplesync files from S3 to an EFS Filesystem.Exampleupload files with SCP to an EFS Filesystem.ExampleInstall Python dependencies and sync from S3 to an EFS Filesystem.ExampleInstall Python dependencies and uploading files with SCP an EFS Filesystem.Example

Note: Each Example can be run in a Google Colab.


Implementation Configuration possibilities

There are 4 different ways to use efsync in your project:

    You can create a yaml configuration and use the SDK.You can create a python dict and use the SDK.You can create a yaml configuration and use the CLI.You can use the CLI with parameters.

You can find examples for each configuration in theGithub Repository. I also included configurationexamples for the different use cases.

Note: If you sync a file with SCP from a local directory (e.g. model/bert) to efs (my_efs_model) efsync willsync the model to my_efs_model/bert that happens because scp uploads the files recursively.


Examples

The following example shows how to install Python dependencies to the EFS Filesystem and sync files from S3 to the EFSFilesystem, afterwards. For configuration purpose, we have to create an efsync.yaml and a requirements.txt filewhich holds our dependencies and configuration.

1. Install efsync

2. Create a requirements.txt with the dependencies

3. Create an efsync.yaml with all required configuration

#standard configurationefs_filesystem_id: fs-2226b27a # aws efs filesystem id (moint point)subnet_Id: subnet-17f97a7d # subnet of which the efs is running inec2_key_name: efsync-asd913fjgq3 # required key name for starting the ec2 instanceclean_efs: all # Defines if the EFS should be cleaned up before. values: `'all'`,`'pip'`,`'file'` uploading# aws profile configurationaws_profile: schueler-vz # aws iam profile with required permission configured in .aws/credentialsaws_region: eu-central-1 # the aws region where the efs is running # pip packages configurationsefs_pip_dir: lib # pip directory on ec2python_version: 3.8 # python version used for installing pip packages -> should be used as lambda runtime afterwadsrequirements: requirements.txt # path + file to requirements.txt which holds the installable pip packages# s3 configs3_bucket: efsync-test-bucket # s3 bucket name from files should be downloadeds3_keyprefix: distilbert # s3 keyprefix for the filesfile_dir_on_ec2: ml # Name of the directory where your S3 files will be saved

The efsync.yaml contains all configuration, such as:

Standard Configuration

    efs_filesystem_id: the AWS EFS filesystem id (mount point).subnet_Id: the Subnet Id of the EFS filesystem, which is running in.ec2_key_name: A required key name for starting the EC2 instance.aws_profile: the IAM profile with required permission configured in .aws/credentials.aws_region: the AWS region where the EFS filesystem is running.

Pip Dependencies Configurations

    efs_pip_dir: the pip directory on EC2, where dependencies will be installed.

    python_version: Python version used for installing pip packages -> should be used as lambda runtime.

    requirements: Path + file to requirements.txt which holds the installable pip dependencies.

    S3 Configurations

    s3_bucket: S3 bucket name from files should be downloaded.

    s3_keyprefix: S3 keyprefix for the directory/files

    file_dir_on_ec2: Name of the directory where your S3 files will be saved

4. Run efsync wit efsync.yaml

from efsync import efsync efsync('./efsync.yaml') #--------------------------Result--------------------------# #2020-10-25 20:12:33,747 - efsync - starting....#2020-10-25 20:12:33,748 - efsync - loading config#2020-10-25 20:12:33,772 - efsync - creating security group#2020-10-25 20:12:34,379 - efsync - loading default security group#2020-10-25 20:12:39,444 - efsync - creating ssh key for scp in memory#2020-10-25 20:12:40,005 - efsync - starting ec2 instance with security group sg-0ff6539317d7e48da and subnet_Id subnet-17f97a7d#2020-10-25 20:18:46,430 - efsync - stopping ec2 instance with instance id i-020e3f3cc4b3d690b#2020-10-25 20:19:17,159 - efsync - deleting iam profile#2020-10-25 20:19:18,354 - efsync - deleting ssh key#2020-10-25 20:19:18,604 - efsync - deleting security group#2020-10-25 20:19:18,914 - efsync - #################### finished after 6.752833333333333 minutes ####################

Summary

With efsync you can easily sync files from S3 or local filesystem automatically to AWS EFS and enables you to installdependencies with the AWS Lambda runtime directly into your EFS filesystem. Installing and syncing files from S3 takesaround 6 minutes, only installing dependencies around 4–5 minutes and only syncing files around 2 minutes.


Thanks for reading. If you have any questions, feel free to contact me or comment on this article. You can also connectwith me on Twitter orLinkedIn.

You can find the library on Github. Feel free to create Pull Request or Issuesif you have any questions or improvements.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

MLOps eFSync AWS Lambda 无服务器计算 机器学习部署
相关文章