Code Monkey home page Code Monkey logo

ml-system-in-actions's Introduction

ml-system-in-actions

machine learning system examples

tl;dr

  • 本レポジトリは 2021 年 5 月翔泳社出版『AI エンジニアのための機械学習システムデザインパターン』のサンプルコード集です。
  • 本レポジトリでは機械学習のモデル学習、リリース、推論器の稼働、運用のためのコードおよび実行環境を用例ごとに提供します。
  • 「機械学習システムデザインパターン」の詳細は本書および mercari/ml-system-design-pattern をご参照ください。

img

実行環境

  • Python 3.8 以上
  • Docker
  • Docker-compose
  • (一部)Kubernetes または minikube
  • (一部)Android Studio

本レポジトリではプログラムの実行環境として Docker、Docker-compose、(一部)Kubernetes/minikube、(一部)Android Studio を使用します。 また、コマンドラインとして kubectlistioctl を使用します。 各種ミドルウェア、開発環境、コマンドラインは以下公式ドキュメントを参考にインストールしてください。

Python の実行環境

本レポジトリで用いる Python のライブラリはpipenvで指定しています。以下の手順で pipenv とともにライブラリをインストールしてください。 サンプルコードは Python3.8 以上で実行を検証しています。実行環境の Python バージョンが合わない場合、pyenv等で実行環境を整えてください。

# Pythonのバージョン
$ python -V
# 出力
Python 3.8.5

# pyenvバージョン
$ pyenv versions
# 出力
  system
* 3.8.5

# pipenvをインストールし、シェルをpipenv venvに変更
$ make dev
# 出力例
# pip install pipenv
# Requirement already satisfied: pipenv in ~/.pyenv/versions/3.8.5/lib/python3.8/site-packages (2020.11.15)
# (中略)
# Requirement already satisfied: six<2,>=1.9.0 in ~/.pyenv/versions/3.8.5/lib/python3.8/site-packages (from virtualenv->pipenv) (1.15.0)
# WARNING: You are using pip version 20.1.1; however, version 21.0.1 is available.
# You should consider upgrading via the '~/.pyenv/versions/3.8.5/bin/python3.8 -m pip install --upgrade pip' command.
# PIPENV_VENV_IN_PROJECT=true pipenv shell
# Creating a virtualenv for this project...
# Pipfile: ~/book/ml-system-in-actions/Pipfile
# Using ~/.pyenv/versions/3.8.5/bin/python3.8 (3.8.5) to create virtualenv...
# ⠧ Creating virtual environment...created virtual environment CPython3.8.5.final.0-64 in 433ms
#   creator CPython3Posix(dest=~/book/ml-system-in-actions/.venv, clear=False, no_vcs_ignore=False, global=False)
#   seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=~/Library/Application Support/virtualenv)
#     added seed packages: pip==21.0.1, setuptools==52.0.0, wheel==0.36.2
#   activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

# ✔ Successfully created virtual environment!
# Virtualenv location: ~/book/ml-system-in-actions/.venv
# Launching subshell in virtual environment...
#  . ~/book/ml-system-in-actions/.venv/bin/activate
# [21-02-27 10:03:37] your_name@your_namenoMacBook-Pro:~/book/ml-system-in-actions
# $  . ~/book/ml-system-in-actions/.venv/bin/activate
# (ml-system-in-actions) [21-02-27 10:03:37] your_name@your_namenoMacBook-Pro:~/book/ml-system-in-actions

# 依存ライブラリをインストール
$ make dev_sync
# 出力例
# pipenv sync --dev
# Installing dependencies from Pipfile.lock (a2c081)...
#   🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 93/93 — 00:02:36
# All dependencies are now up-to-date!

##################################
####### 開発、プログラムの実行 #######
##################################


# 開発、プログラムの実行が完了したらpipenv venvシェルを終了
$ exit

ただし、一部のサンプルコードでは他のライブラリを使用することがあります。当該サンプルコードのディレクトリで README を参照してください。

コード一覧

本レポジトリが提供するプログラムは以下に示す各プログラムのディレクトリで実行されることを想定して開発されています。 各プログラムを実行する際は目的のディレクトリに移動してください。 各プログラムの実行方法は各プログラムディレクトリ配下の README に示してあります。

.
├── chapter2_training
│   ├── cifar10
│   ├── iris_binary
│   ├── iris_sklearn_outlier
│   ├── iris_sklearn_rf
│   ├── iris_sklearn_svc
│   └── model_db
├── chapter3_release_patterns
│   ├── model_in_image_pattern
│   └── model_load_pattern
├── chapter4_serving_patterns
│   ├── asynchronous_pattern
│   ├── batch_pattern
│   ├── data_cache_pattern
│   ├── edge_ai_pattern
│   ├── horizontal_microservice_pattern
│   ├── prediction_cache_pattern
│   ├── prep_pred_pattern
│   ├── sync_async_pattern
│   ├── synchronous_pattern
│   └── web_single_pattern
├── chapter5_operations
│   ├── prediction_log_pattern
│   └── prediction_monitoring_pattern
└── chapter6_operation_management
   ├── circuit_breaker_pattern
   ├── condition_based_pattern
   ├── load_test_pattern
   ├── online_ab_pattern
   ├── paramater_based_pattern
   └── shadow_ab_pattern

ml-system-in-actions's People

Contributors

erniogi avatar haebuk avatar shibuiwilliam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ml-system-in-actions's Issues

main.py: error: unrecognized arguments: \

お忙しいところすみません。
Cifar10におけるmake trainコマンドの実行時に
main.py: error: unrecognized arguments:
といったエラーが出てしまいます。他ページで打開策を探しているものの「\」の解決策を見つけることができません。何か初歩的なミスをしてしまっているのかもしれず大変申し訳ないのですが、お力をお貸しいただけると幸いです。よろしくお願いいたします。

chapter2_training/model_db listening but not worked

I tried to following code chapter2_training here

I built docker and docker-compose up, and it seems no error, but I can't connect localhost:8000/docs

I run code below steps:
~/model_db$ make build

docker build \
		-t cwryu6252/ml-system-design-pattern:model_db_0.0.1 \
		-f Dockerfile \
		.

skipping ...

 => => naming to docker.io/cwryu6252/ml-system-design-pattern:model_db_0.0.1

~/model_db$ make c_up

docker-compose \
		-f ./docker-compose.yml \
		up -d
Creating network "model_db_default" with the default driver
Creating postgres ... done
Creating model_db ... done

then docker logs -f {my_container_id}


Attaching to model_db, postgres

postgres    | The files belonging to this database system will be owned by user "postgres".
postgres    | This user must also own the server process.
postgres    | 
postgres    | The database cluster will be initialized with locale "en_US.utf8".
postgres    | The default text search configuration will be set to "english".
postgres    | 
postgres    | Data page checksums are disabled.
postgres    | 
postgres    | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgres    | creating subdirectories ... ok
postgres    | selecting dynamic shared memory implementation ... posix
postgres    | selecting default max_connections ... 100
postgres    | selecting default shared_buffers ... 128MB
postgres    | selecting default time zone ... Etc/UTC
postgres    | creating configuration files ... ok
postgres    | running bootstrap script ... ok
postgres    | performing post-bootstrap initialization ... ok
postgres    | initdb: warning: enabling "trust" authentication for local connections
postgres    | You can change this by editing pg_hba.conf or using the option -A, or
postgres    | --auth-local and --auth-host, the next time you run initdb.
postgres    | syncing data to disk ... ok
postgres    | 
postgres    | 
postgres    | Success. You can now start the database server using:
postgres    | 
postgres    |     pg_ctl -D /var/lib/postgresql/data -l logfile start
postgres    | 
postgres    | waiting for server to start....2022-05-15 14:39:37.000 UTC [48] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres    | 2022-05-15 14:39:37.001 UTC [48] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres    | 2022-05-15 14:39:37.007 UTC [49] LOG:  database system was shut down at 2022-05-15 14:39:36 UTC
postgres    | 2022-05-15 14:39:37.012 UTC [48] LOG:  database system is ready to accept connections
postgres    |  done
postgres    | server started
postgres    | CREATE DATABASE
postgres    | 
postgres    | 
postgres    | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
postgres    | 
postgres    | waiting for server to shut down....2022-05-15 14:39:37.206 UTC [48] LOG:  received fast shutdown request
postgres    | 2022-05-15 14:39:37.207 UTC [48] LOG:  aborting any active transactions
postgres    | 2022-05-15 14:39:37.208 UTC [48] LOG:  background worker "logical replication launcher" (PID 55) exited with exit code 1
postgres    | 2022-05-15 14:39:37.209 UTC [50] LOG:  shutting down
postgres    | 2022-05-15 14:39:37.219 UTC [48] LOG:  database system is shut down
postgres    |  done
postgres    | server stopped
postgres    | 
postgres    | PostgreSQL init process complete; ready for start up.
postgres    | 
postgres    | 2022-05-15 14:39:37.318 UTC [1] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres    | 2022-05-15 14:39:37.318 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres    | 2022-05-15 14:39:37.318 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres    | 2022-05-15 14:39:37.320 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres    | 2022-05-15 14:39:37.322 UTC [76] LOG:  database system was shut down at 2022-05-15 14:39:37 UTC
postgres    | 2022-05-15 14:39:37.325 UTC [1] LOG:  database system is ready to accept connections
model_db    | [2022-05-15 14:39:46 +0000] [9] [INFO] Starting gunicorn 20.0.4
model_db    | [2022-05-15 14:39:46 +0000] [9] [INFO] Listening at: http://127.0.0.1:8000 (9)
model_db    | [2022-05-15 14:39:46 +0000] [9] [INFO] Using worker: sync
model_db    | [2022-05-15 14:39:46 +0000] [11] [INFO] Booting worker with pid: 11
  • localhost:8000/docs not worked. how i resolve this?

ImportError: cannot import name 'SupportsIndex' from 'typing_extensions' (//anaconda3/lib/python3.7/site-packages/typing_extensions.py)

python3.7.3
Mac OS Mojave
pyenv使用
の元で、$make train実行時に以下のエラーが出ました。

mlflow run . --no-conda
Notice: failed to import Git (the git executable is probably not on your PATH), so Git SHA is not available. Error: cannot import name 'SupportsIndex' from 'typing_extensions' (//anaconda3/lib/python3.7/site-packages/typing_extensions.py)
2021/10/04 22:57:33 WARNING mlflow.tracking.context.git_context: Failed to import Git (the Git executable is probably not on your PATH), so Git SHA is not available. Error: cannot import name 'SupportsIndex' from 'typing_extensions' (//anaconda3/lib/python3.7/site-packages/typing_extensions.py)
Traceback (most recent call last):
  File "//anaconda3/bin/mlflow", line 8, in <module>
    sys.exit(cli())
  File "//anaconda3/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "//anaconda3/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "//anaconda3/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "//anaconda3/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "//anaconda3/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "//anaconda3/lib/python3.7/site-packages/mlflow/cli.py", line 181, in run
    run_id=run_id,
  File "//anaconda3/lib/python3.7/site-packages/mlflow/projects/__init__.py", line 304, in run
    synchronous=synchronous,
  File "//anaconda3/lib/python3.7/site-packages/mlflow/projects/__init__.py", line 99, in _run
    experiment_id,
  File "//anaconda3/lib/python3.7/site-packages/mlflow/projects/backend/local.py", line 52, in run
    run_id, project_uri, experiment_id, work_dir, version, entry_point, params
  File "//anaconda3/lib/python3.7/site-packages/mlflow/projects/utils.py", line 221, in get_or_create_run
    return _create_run(uri, experiment_id, work_dir, version, entry_point, parameters)
  File "//anaconda3/lib/python3.7/site-packages/mlflow/projects/utils.py", line 252, in _create_run
    repo_url = _get_git_repo_url(work_dir)
  File "//anaconda3/lib/python3.7/site-packages/mlflow/projects/utils.py", line 69, in _get_git_repo_url
    from git import Repo
  File "//anaconda3/lib/python3.7/site-packages/git/__init__.py", line 8, in <module>
    from git.exc import *                       # @NoMove @IgnorePep8
  File "//anaconda3/lib/python3.7/site-packages/git/exc.py", line 15, in <module>
    from git.types import PathLike
  File "//anaconda3/lib/python3.7/site-packages/git/types.py", line 13, in <module>
    from typing_extensions import (Final, Literal, SupportsIndex,                           # noqa: F401
ImportError: cannot import name 'SupportsIndex' from 'typing_extensions' (//anaconda3/lib/python3.7/site-packages/typing_extensions.py)
make: *** [train] Error 1

typingExtensionsとSupportIndexに関するエラーに見えますがpythonのバージョンなど関係あるでしょうか。。
まだ解消できてないですが報告します。

Conflict between starlette and fastapi

When I followed README.md and did make build on the model_db of chapter2, I got the error

ERROR: Cannot install -r requirements.txt (line 1) and starlette==0.13.6 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested starlette==0.13.6
    fastapi 0.66.0 depends on starlette==0.14.2
    The user requested starlette==0.13.6
    fastapi 0.65.3 depends on starlette==0.14.2
    The user requested starlette==0.13.6
    fastapi 0.65.2 depends on starlette==0.14.2

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict```

kubectl exec [POD] [COMMAND] is DEPRECATED というメッセージ

6章を読んでいますが、大変参考になっています。ありがとうございます。

手を動かしながら読んでいたところ、kubectl execコマンド実行でdeprecatedと表示されることに気づきましたので、共有します

環境

  • macOS Mojave
  • kubectl (client) 1.22
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:31:32Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"darwin/amd64"}

事象

kubectl -n shadow-ab exec -it pod/client bash を実行したところ、以下のメッセージが表示されました

kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.

提案

kubectl -n shadow-ab exec -it pod/client -- bash への変更を提案します。

ざっと見たところchapter6でkubectl execを使っているようですので、--を使ったコマンドに書き直すのがよさそうです。

参考

https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec

https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/#getting-a-shell-to-a-container

Note: The double dash (--) separates the arguments you want to pass to the command from the kubectl arguments.

kubectlのどのバージョンからdouble dashを推奨するようになったのかは調べきれていません

Warning: using deprecated setting "mirrorPercent", use "mirrorPercentage" instead

shadow ab test patternを試したところ、warningメッセージが表示されましたので共有します。
shadow ab test patternは手元の環境で問題なく動作しました

環境

  • macOS Mojave
  • minikube version: v1.23.2
  • kubectl (client) 1.22
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:31:32Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"darwin/amd64"}
$ istioctl version
client version: 1.11.4
control plane version: 1.11.4
data plane version: 1.11.4 (1 proxies)

事象

make deployを実行したところ、表題のwarningが表示されました

提案

VirtualServiceの定義のうち以下の箇所を

mirror:
host: iris
subset: rf
mirror_percent: 100

以下のように変更することでwarningは出なくなりました

 mirror: 
   host: iris 
   subset: rf 
 mirrorPercentage:
    value: 100

参考

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.