mlops-python-package

mlops-python-package

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

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

MLOpsPython包GitHub Actions软件开发实践自动化工具Github开源项目

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

编辑推荐精选

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

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

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

下拉加载更多