Skip to main content

MLflow plugin for Triton Inference Server with secure Python function execution

Project description

w-train-utils-mlflow-triton-plugin

MLflow plugin for Triton Inference Server with secure Python function execution

๐Ÿ“š ์ฃผ์š” ๊ธฐ๋Šฅ

๐Ÿ”Œ MLflow-Triton ํ†ตํ•ฉ

  • MLflow ๋ชจ๋ธ์„ Triton Inference Server๋กœ ์ž๋™ ๋ฐฐํฌ
  • Python ํ•จ์ˆ˜๋ฅผ Triton ๋ชจ๋ธ๋กœ ๋ณ€ํ™˜
  • S3/MinIO ๊ธฐ๋ฐ˜ ๋ชจ๋ธ ์ €์žฅ์†Œ ์ง€์›

๐Ÿ› ๏ธ Keynet CLI

  • Python ํ•จ์ˆ˜ ๊ฒ€์ฆ ๋ฐ ํ…Œ์ŠคํŠธ
  • ํ•จ์ˆ˜ ๋ฐฐํฌ ๋ฐ ๊ด€๋ฆฌ
  • ์ธ์ฆ ๋ฐ ์ž๊ฒฉ ์ฆ๋ช… ๊ด€๋ฆฌ
  • ๋‹ค์–‘ํ•œ Python ๋ฒ„์ „ ์ง€์› (3.9, 3.10, 3.11, 3.12)

๐Ÿš€ ์„ค์น˜

pip install wtu-mlflow-triton-plugin

๐Ÿ“– ์‚ฌ์šฉ๋ฒ•

1. Python ํ•จ์ˆ˜ ์ž‘์„ฑ

# my_function.py
from wtu_mlflow_triton_plugin.function import keynet_function

@keynet_function("my_model")
def main(args):
    """์ž…๋ ฅ์„ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜"""
    # args๋Š” ๋”•์…”๋„ˆ๋ฆฌ ํ˜•ํƒœ์˜ ์ž…๋ ฅ
    text = args.get("text", "")
    result = text.upper()

    return {
        "result": result,
        "length": len(text)
    }

2. Keynet CLI๋กœ ํ•จ์ˆ˜ ๊ฒ€์ฆ

# ํ•จ์ˆ˜ ๊ฒ€์ฆ
keynet validate my_function.py

# ์˜์กด์„ฑ๊ณผ ํ•จ๊ป˜ ๊ฒ€์ฆ
keynet validate my_function.py -r requirements.txt

# ํ…Œ์ŠคํŠธ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์‹คํ–‰
keynet test my_function.py --params '{"text": "hello world"}'

3. ํ•จ์ˆ˜ ๋ฐฐํฌ

# ๋กœ์ปฌ ํ™˜๊ฒฝ์— ๋ฐฐํฌ
keynet deploy my_function.py --name my_model

# ์›๊ฒฉ ์„œ๋ฒ„์— ๋ฐฐํฌ
keynet deploy my_function.py --name my_model --server https://api.example.com

4. MLflow์™€ ํ†ตํ•ฉ

import mlflow
from wtu_mlflow_triton_plugin import TritonPlugin

# MLflow ์„ค์ •
mlflow.set_tracking_uri("http://localhost:5001")

# Triton ํ”Œ๋Ÿฌ๊ทธ์ธ ํ™œ์„ฑํ™”
with mlflow.start_run():
    # ๋ชจ๋ธ ๋กœ๊น…
    mlflow.pyfunc.log_model(
        artifact_path="model",
        python_model=my_model,
        deployment_flavor="triton"
    )

    # Triton์œผ๋กœ ๋ฐฐํฌ
    mlflow.deployments.create_deployment(
        name="my-deployment",
        model_uri=f"runs:/{run_id}/model",
        flavor="triton"
    )

๐Ÿ”ง ํ™˜๊ฒฝ ์„ค์ •

ํ•„์ˆ˜ ํ™˜๊ฒฝ ๋ณ€์ˆ˜

ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค๋ช… ์˜ˆ์‹œ
MLFLOW_S3_ENDPOINT_URL MinIO ์—”๋“œํฌ์ธํŠธ URL http://localhost:9000
MLFLOW_TRACKING_URI MLflow ํŠธ๋ž˜ํ‚น ์„œ๋ฒ„ URI http://localhost:5001
AWS_ACCESS_KEY_ID AWS/MinIO ์•ก์„ธ์Šค ํ‚ค minio
AWS_SECRET_ACCESS_KEY AWS/MinIO ์‹œํฌ๋ฆฟ ํ‚ค miniostorage
TRITON_URL Triton gRPC ์—”๋“œํฌ์ธํŠธ http://localhost:8001
TRITON_MODEL_REPO Triton ๋ชจ๋ธ ์ €์žฅ์†Œ URL s3://bucket/models

Triton Inference Server ์‹คํ–‰

docker run --rm -p8000:8000 -p8001:8001 -p8002:8002 \
    -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
    -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
    nvcr.io/nvidia/tritonserver:24.01-py3 \
    tritonserver --model-repository=$TRITON_MODEL_REPO \
    --model-control-mode=explicit \
    --log-verbose=1

๐Ÿ“‹ Keynet CLI ๋ช…๋ น์–ด

๊ธฐ๋ณธ ๋ช…๋ น์–ด

# ํ•จ์ˆ˜ ๊ฒ€์ฆ
keynet validate <python_file> [-r requirements.txt]

# ํ•จ์ˆ˜ ํ…Œ์ŠคํŠธ
keynet test <python_file> [--params JSON] [-r requirements.txt]

# ํ•จ์ˆ˜ ๋ฐฐํฌ
keynet deploy <python_file> --name <model_name> [--server URL]

์ธ์ฆ ๊ด€๋ฆฌ

# ์ž๊ฒฉ ์ฆ๋ช… ๋“ฑ๋ก
keynet login https://api.example.com

# ํŠน์ • ์„œ๋ฒ„์—์„œ ๋กœ๊ทธ์•„์›ƒ
keynet logout --server api.example.com

# ๋ชจ๋“  ์„œ๋ฒ„์—์„œ ๋กœ๊ทธ์•„์›ƒ
keynet logout --all

๊ณ ๊ธ‰ ์˜ต์…˜

# Python ๋ฒ„์ „ ์ง€์ •
keynet validate my_function.py --python 3.11

# ํƒ€์ž„์•„์›ƒ ์„ค์ •
keynet test my_function.py --import-timeout 60 --execution-timeout 120

# ์ƒ์„ธ ๋กœ๊ทธ ์ถœ๋ ฅ
keynet validate my_function.py -v

# ์บ์‹œ ์ •๋ฆฌ
keynet cache clear

๐Ÿ—๏ธ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ

wtu_mlflow_triton_plugin/
โ”œโ”€โ”€ auth/               # ์ธ์ฆ ๋ฐ ์ž๊ฒฉ ์ฆ๋ช… ๊ด€๋ฆฌ
โ”œโ”€โ”€ function/           # ํ•จ์ˆ˜ ๋นŒ๋” ๋ฐ CLI
โ”‚   โ”œโ”€โ”€ cli.py         # Keynet CLI ๊ตฌํ˜„
โ”‚   โ”œโ”€โ”€ client.py      # API ํด๋ผ์ด์–ธํŠธ
โ”‚   โ”œโ”€โ”€ models.py      # ๋ฐ์ดํ„ฐ ๋ชจ๋ธ
โ”‚   โ”œโ”€โ”€ validator.py   # ํ•จ์ˆ˜ ๊ฒ€์ฆ๊ธฐ
โ”‚   โ””โ”€โ”€ venv_manager.py # ๊ฐ€์ƒํ™˜๊ฒฝ ๊ด€๋ฆฌ
โ”œโ”€โ”€ plugin.py          # MLflow ํ”Œ๋Ÿฌ๊ทธ์ธ
โ”œโ”€โ”€ storage.py         # S3/MinIO ์ €์žฅ์†Œ ๊ด€๋ฆฌ
โ””โ”€โ”€ config.py          # ์„ค์ • ๊ด€๋ฆฌ

๐Ÿ”’ ๋ณด์•ˆ ๊ธฐ๋Šฅ ์ƒ์„ธ

์ฝ”๋“œ ๊ฒ€์ฆ

  • AST ๊ธฐ๋ฐ˜ ๊ตฌ๋ฌธ ๋ถ„์„
  • ํ•„์ˆ˜ ํ•จ์ˆ˜ ์‹œ๊ทธ๋‹ˆ์ฒ˜ ๊ฒ€์‚ฌ
  • ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ ๊ฒ€์ฆ

์‹คํ–‰ ๊ฒฉ๋ฆฌ

  • ๋…๋ฆฝ๋œ ๊ฐ€์ƒํ™˜๊ฒฝ์—์„œ ์‹คํ–‰
  • ์‹œ์Šคํ…œ ๋ฆฌ์†Œ์Šค ์ ‘๊ทผ ์ œํ•œ
  • ํƒ€์ž„์•„์›ƒ ๊ธฐ๋ฐ˜ ์‹คํ–‰ ์ œ์–ด

๋ฉ”๋ชจ๋ฆฌ ๋ณดํ˜ธ

  • ์ตœ๋Œ€ 512MB ๋ฉ”๋ชจ๋ฆฌ ์ œํ•œ
  • ๋ฉ”๋ชจ๋ฆฌ ํญํƒ„ ๋ฐฉ์ง€
  • ๋ฆฌ์†Œ์Šค ๊ณ ๊ฐˆ ๋ฐฉ์ง€

๐Ÿค ๊ธฐ์—ฌํ•˜๊ธฐ

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ ๋ผ์ด์„ ์Šค

MIT License - ์ž์„ธํ•œ ๋‚ด์šฉ์€ LICENSE ํŒŒ์ผ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๐Ÿ”— ์ฐธ๊ณ  ์ž๋ฃŒ

๐Ÿ“ž ์ง€์›

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wtu_mlflow_triton_plugin-0.0.17.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wtu_mlflow_triton_plugin-0.0.17-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file wtu_mlflow_triton_plugin-0.0.17.tar.gz.

File metadata

File hashes

Hashes for wtu_mlflow_triton_plugin-0.0.17.tar.gz
Algorithm Hash digest
SHA256 be6504fac6a61b410682893ad7235c201b434a8c6f7809f2d81f9be2bd8539ea
MD5 01db0ad249956e261d8cb03fccb582cc
BLAKE2b-256 5fd1ae809d1427137cde077aaf9a93287ec9be79ea56922cb35dcc46069c8f99

See more details on using hashes here.

File details

Details for the file wtu_mlflow_triton_plugin-0.0.17-py3-none-any.whl.

File metadata

File hashes

Hashes for wtu_mlflow_triton_plugin-0.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 a9ad01b828a25eddb48a330f789c170b38bf869b45f560390f5d42ce00a02635
MD5 23ba8988bb7a4cf0ff5b0a45ea5e57b7
BLAKE2b-256 54511ec244593c7435f9b964337ae9d36c1562e2815dc2970ab22e348f5282f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page