Project Icon

mlops-python-package

MLOps Python工具包,简化机器学习工程实践

这是一个集成多种MLOps最佳实践的Python代码库,旨在优化机器学习工程流程。该工具包提供了模型注册、实验跟踪和实时推理等核心功能,同时支持自动化任务、CI/CD集成、配置管理和数据处理等辅助功能。通过灵活且稳健的设计,这个工具包可以帮助开发者更高效地构建和部署MLOps项目,简化整个机器学习生命周期管理。

MLOps Python Package

check.yml publish.yml Documentation License Release

This repository contains a Python code base with best practices designed to support your MLOps initiatives.

The package leverages several tools and tips to make your MLOps experience as flexible, robust, productive as possible.

You can use this package as part of your MLOps toolkit or platform (e.g., Model Registry, Experiment Tracking, Realtime Inference, ...).

Related Resources:

Table of Contents

Install

This section details the requirements, actions, and next steps to kickstart your MLOps project.

Prerequisites

Installation

  1. Clone this GitHub repository on your computer
# with ssh (recommended)
$ git clone git@github.com:fmind/mlops-python-package
# with https
$ git clone https://github.com/fmind/mlops-python-package
  1. Run the project installation with poetry
$ cd mlops-python-package/
$ poetry install
  1. Adapt the code base to your desire

Next Steps

Going from there, there are dozens of ways to integrate this package to your MLOps platform.

For instance, you can use Databricks or AWS as your compute platform and model registry.

It's up to you to adapt the package code to the solution you target. Good luck champ!

Usage

This section explains how configure the project code and execute it on your system.

Configuration

You can add or edit config files in the confs/ folder to change the program behavior.

# confs/training.yaml
job:
  KIND: TrainingJob
  inputs:
    KIND: ParquetReader
    path: data/inputs_train.parquet
  targets:
    KIND: ParquetReader
    path: data/targets_train.parquet

This config file instructs the program to start a TrainingJob with 2 parameters:

  • inputs: dataset that contains the model inputs
  • targets: dataset that contains the model target

You can find all the parameters of your program in the src/[package]/jobs/*.py files.

You can also print the full schema supported by this package using poetry run bikes --schema.

Execution

The project code can be executed with poetry during your development:

$ poetry run [package] confs/tuning.yaml
$ poetry run [package] confs/training.yaml
$ poetry run [package] confs/promotion.yaml
$ poetry run [package] confs/inference.yaml
$ poetry run [package] confs/evaluations.yaml
$ poetry run [package] confs/explanations.yaml

In production, you can build, ship, and run the project as a Python package:

poetry build
poetry publish # optional
python -m pip install [package]
[package] confs/inference.yaml

You can also install and use this package as a library for another AI/ML project:

from [package] import jobs

job = jobs.TrainingJob(...)
with job as runner:
    runner.run()

Additional tips:

  • You can pass extra configs from the command line using the --extras flag
    • Use it to pass runtime values (e.g., a result from previous job executions)
  • You can pass several config files in the command-line to merge them from left to right
    • You can define common configurations shared between jobs (e.g., model params)
  • The right job task will be selected automatically thanks to Pydantic Discriminated Unions
    • This is a great way to run any job supported by the application (training, tuning, ....

Automation

This project includes several automation tasks to easily repeat common actions.

You can invoke the actions from the command-line or VS Code extension.

# execute the project DAG
$ inv projects
# create a code archive
$ inv packages
# list other actions
$ inv --list

Available tasks:

  • checks.all (checks) - Run all check tasks.
  • checks.code - Check the codes with ruff.
  • checks.coverage - Check the coverage with coverage.
  • checks.format - Check the formats with ruff.
  • checks.poetry - Check poetry config files.
  • checks.security - Check the security with bandit.
  • checks.test - Check the tests with pytest.
  • checks.type - Check the types with mypy.
  • cleans.all (cleans) - Run all tools and folders tasks.
  • cleans.cache - Clean the cache folder.
  • cleans.coverage - Clean the coverage tool.
  • cleans.dist - Clean the dist folder.
  • cleans.docs - Clean the docs folder.
  • cleans.environment - Clean the project environment file.
  • cleans.folders - Run all folders tasks.
  • cleans.mlruns - Clean the mlruns folder.
  • cleans.mypy - Clean the mypy tool.
  • cleans.outputs - Clean the outputs folder.
  • cleans.poetry - Clean poetry lock file.
  • cleans.pytest - Clean the pytest tool.
  • cleans.projects - Run all projects tasks.
  • cleans.python - Clean python caches and bytecodes.
  • cleans.requirements - Clean the project requirements file.
  • cleans.reset - Run all tools, folders, and sources tasks.
  • cleans.ruff - Clean the ruff tool.
  • cleans.sources - Run all sources tasks.
  • cleans.tools - Run all tools tasks.
  • cleans.venv - Clean the venv folder.
  • commits.all (commits) - Run all commit tasks.
  • commits.bump - Bump the version of the package.
  • commits.commit - Commit all changes with a message.
  • commits.info - Print a guide for messages.
  • containers.all (containers) - Run all container tasks.
  • containers.build - Build the container image with the given tag.
  • containers.compose - Start up docker compose.
  • containers.run - Run the container image with the given tag.
  • docs.all (docs) - Run all docs tasks.
  • docs.api - Document the API with pdoc using the given format and output directory.
  • docs.serve - Serve the API docs with pdoc using the given format and computer port.
  • formats.all - (formats) Run all format tasks.
  • formats.imports - Format python imports with ruff.
  • formats.sources - Format python sources with ruff.
  • installs.all (installs) - Run all install tasks.
  • installs.poetry - Install poetry packages.
  • installs.pre-commit - Install pre-commit hooks on git.
  • mlflow.all (mlflow) - Run all mlflow tasks.
  • mlflow.doctor - Run mlflow doctor to diagnose issues.
  • mlflow.serve - Start mlflow server with the given host, port, and backend uri.
  • packages.all (packages) - Run all package tasks.
  • packages.build - Build a python package with the given format.
  • projects.all (projects) - Run all project tasks.
  • projects.environment - Export the project environment file.
  • projects.requirements - Export the project requirements file.
  • projects.run - Run an mlflow project from MLproject file.

Workflows

This package supports two GitHub Workflows in .github/workflows:

  • check.yml: validate the quality of the package on each Pull Request
  • publish.yml: build and publish the docs and packages on code release.

You can use and extend these workflows to automate repetitive package management tasks.

Tools

This sections motivates the use of developer tools to improve your coding experience.

Automation

Pre-defined actions to automate your project development.

Commits: Commitizen

  • Motivations:
    • Format your code commits
    • Generate a standard changelog
    • Integrate well with SemVer and PEP 440
  • Limitations:
    • Learning curve for new users
  • Alternatives:
    • Do It Yourself (DIY)

Git Hooks: Pre-Commit

  • Motivations:
    • Check your code locally before a commit
    • Avoid wasting resources on your CI/CD
    • Can perform extra actions (e.g., file cleanup)
  • Limitations:
    • Add overhead before your commit
  • Alternatives:

Tasks: PyInvoke

  • Motivations:
    • Automate project workflows
    • Sane syntax compared to alternatives
    • Good trade-off between power/simplicity
  • Limitations:
    • Not familiar to most developers
  • Alternatives:
    • Make: most popular, but awful syntax

CI/CD

Execution of automated workflows on code push and releases.

Runner: GitHub Actions

  • Motivations:
    • Native on GitHub
    • Simple workflow syntax
    • Lots of configs if needed
  • Limitations:
    • SaaS Service
  • Alternatives:
    • GitLab: can be installed on-premise

CLI

Integrations with the Command-Line Interface (CLI) of your system.

Parser: Argparse

  • Motivations:
    • Provide CLI arguments
    • Included in Python runtime
    • Sufficient for providing configs
  • Limitations:
    • More verbose for advanced parsing
  • Alternatives:
    • Typer: code typing for the win
    • Fire: simple but no typing
    • Click: more verbose

Logging: Loguru

  • Motivations:
    • Show progress to the user
    • Work fine out of the box
    • Saner logging syntax
  • Limitations:
    • Doesn't let you deviate from the base usage
  • Alternatives:
    • Logging: available by default, but feel dated

Code

Edition, validation, and versioning of your project source code.

Coverage: Coverage

  • Motivations:
    • Report code covered by tests
    • Identify code path to test
    • Show maturity
项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

吐司

探索Tensor.Art平台的独特AI模型,免费访问各种图像生成与AI训练工具,从Stable Diffusion等基础模型开始,轻松实现创新图像生成。体验前沿的AI技术,推动个人和企业的创新发展。

Project Cover

SubCat字幕猫

SubCat字幕猫APP是一款创新的视频播放器,它将改变您观看视频的方式!SubCat结合了先进的人工智能技术,为您提供即时视频字幕翻译,无论是本地视频还是网络流媒体,让您轻松享受各种语言的内容。

Project Cover

美间AI

美间AI创意设计平台,利用前沿AI技术,为设计师和营销人员提供一站式设计解决方案。从智能海报到3D效果图,再到文案生成,美间让创意设计更简单、更高效。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号