Skip to main content

Matilo (C) Deep-Learning Model Serving Worker Module

Project description

Matilo Model Serving Worker (mmsw)

Environment

Name Desc
APP_ENV 운영 환경 (local/dev/test/prod)
PROJECT_NAME 프로젝트 이름
LOG_LEVEL 로그 레벨 (default: "Info")
DB_ECHO 쿼리를 콘솔에 출력 할지 여부 (default: "False")
DB_SCHEME SQLAlchemy DB 스키마 (mysql+pymysql)
DB_HOST DB 서버 호스트 (IP)
DB_PORT DB 서버 포트
DB_USER DB 사용자 ID
DB_PWD DB 암호
DB_NAME DB 명
IDLE_TIME DB 폴링 대기 텀 (default: "3")
MODEL_NAME 서빙 할 모델의 고유 이름
MODEL_WORKER 서빙 할 모델 워커의 고유 이름
IMAGE_ROOT 모델 실행 결과에 이미지가 포함된 경우 이미지를 저장 할 루트 패스
ex) /var/www/2025/12/ 와 같이 전달된 경우 /var/www/2025/12/m1_1_01.png 형태로 저장
여기서 m1 은 모델명, 1 은 모델 실행 요청 ID, 01 은 이미지가 여러개 일 경우 순서
IMAGE_HOST 모델 실행 결과에 이미지가 포함된 경우 JSON 형태로 결과를 반환시 호스팅 되는 서버의 호스트 정보
ex) http://192.168.0.1:8080/2025/12/ 와 같이 전달된 경우 http://192.168.0.1:8080/2025/12/m1_1_01.png 형태로 JSON 결과에 포함
RESULT_URL 모델 구동 결과를 Webhook 으로 호출할 URL
SLACK_URL 오류 발생시 메시지를 전달 할 Slack URL

Module Integration Guide

  • Module Setup
$ pipenv install mmsw
  • Module Integration
import json

from mmsw.mmsw import MMSWParams, MMSWResult, ModelStatus, run_worker


"""
**모델이 실행될 콜백 함수**

MMSWParams class 정의 (모델이 실행될 콜백 함수)

- **params: MMSWParams**: 모델 구동에 필요한 인자 정보
  - **id**: 모델 실행 요청 ID
  - **model_name**: 모델명
  - **model_params**: 모델 실행을 위한 매개 변수 (JSON 문자열 형태)
  - **image_root**: 모델 실행 결과에 이미지가 포함된 경우 이미지를 저장 할 루트 패스
    ex) /var/www/2025/12/ 와 같이 전달된 경우 /var/www/2025/12/m1_1_01.png 형태로 저장
    여기서 m1 은 모델명, 1 은 모델 실행 요청 ID, 01 은 이미지가 여러개 일 경우 순서
  - **image_host**: 모델 실행 결과에 이미지가 포함된 경우 JSON 형태로 결과를 반환시 호스팅 되는 서버의 호스트 정보
    ex) http://192.168.0.1:8080/2025/12/ 와 같이 전달된 경우 http://192.168.0.1:8080/2025/12/m1_1_01.png 형태로 JSON 결과에 포함

    
MMSWResult class 정의 (모델 서빙 결과 반환 정보)

- **status**: 모델의 실행 결과의 상태 (ModelStatus enum 사용)
- **model_result**: 모델 실행 결과가 저장된 변수 (JSON 문자열 형태)


ModelStatus enum 정의 (모델 서빙의 상태 정보)

- READY : 모델 서빙 대기
- RUN : 모델 구동 중
- FAIL : 모델 구동 실패
- BADPARAM : 잘못된 매개변수
- TIMEOUT : 모델 구동 타임아웃
- CANCEL : 모델 구동 취소
- COMPLETE : 모델 구동 완료
"""
def run_model(model_params: MMSWParams) -> MMSWResult:

    # TODO: 1. 모델 매개변수의 유효성 체크 (예시)

    try:
        json_params = json.loads(model_params)
        gen_size = json_params["gen_size"]
        scaffold = json_params["scaffold"]
        
        if gen_size is None or gen_size < 0 or gen_size > 100 or scaffold is None:
            # 모델 매개변수가 요효하지 않다면 다음과 같이 매개변수 오류를 반환
            return MMSWResult(status=ModelStatus.BADPARAM, model_result=json.dumps({"result": "Bad Param"}, ensure_ascii=False))
    except Exception:
        return MMSWResult(status=ModelStatus.BADPARAM, model_result=json.dumps({"result": "Bad Model Param - JSON Format"}, ensure_ascii=False))
    

    # TODO: 2. 모델 실행 코드 연동

    
    # TODO: 3. 모델의 출력 결과를 JSON 정보를 저장 (예시)
    model_result = ["data1", "data2"]


    # TODO: 4. 모델 실행 결과의 상태와 출력 정보를 JSON 문자열로 전달
    return MMSWResult(status=ModelStatus.COMPLETE, model_result=json.dumps({"result": model_result}, ensure_ascii=False))


if __name__ == '__main__':

    run_worker(fnRunModel=run_model)

Module Distribution

  • New Stype
# Pre install
$ pip install build

# Do build & upload
$ python -m build
$ python -m twine upload dist/*
  • Old Stype
# Pre install
$ pip install setuptools wheel

# Do build & upload
$ python setup.py sdist bdist_wheel
$ python -m twine upload dist/*

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

mmsw-0.0.25.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

mmsw-0.0.25-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file mmsw-0.0.25.tar.gz.

File metadata

  • Download URL: mmsw-0.0.25.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for mmsw-0.0.25.tar.gz
Algorithm Hash digest
SHA256 33de762c98eef4762b2161f8a7b9ce4401cb4d56b80c09ce4d4e5a940ccdcc1f
MD5 f06d67cb5b55260cfed09427b7b989e4
BLAKE2b-256 2f4f6afae9b1d32373a8be70887d588675c86728a4a59877ffd1193e704c8138

See more details on using hashes here.

File details

Details for the file mmsw-0.0.25-py3-none-any.whl.

File metadata

  • Download URL: mmsw-0.0.25-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for mmsw-0.0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 3c27a03d6ac12228d126533e78e885fd1435c02ca4f1ed3c3f6ac888bd04595f
MD5 352bdd132a94a3f5c7d80ddbec6cc735
BLAKE2b-256 72fd8ef43a104aaa6c00da888cb897d764b18f2b397fe50ca87be6c99bd6b0c5

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