From db496457e66caff191938477ef86a6bd2922c1be Mon Sep 17 00:00:00 2001 From: Alexander Guschin <1aguschin@gmail.com> Date: Sun, 13 Nov 2022 00:05:55 +0000 Subject: [PATCH] Add MLEM model --- .github/workflows/deploy-model-with-mlem.yml | 49 +++++++++++++++++++ .github/workflows/gto-act-on-tags.yml | 35 ------------- .mlem.yaml | 3 ++ deploy/dev.mlem | 3 ++ deploy/prod.mlem | 3 ++ deploy/staging.mlem | 3 ++ models/churn.pkl | Bin 12 -> 319 bytes models/churn.pkl.mlem | 37 ++++++++++++++ requirements.txt | 3 +- train.py | 11 +++++ 10 files changed, 111 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/deploy-model-with-mlem.yml delete mode 100644 .github/workflows/gto-act-on-tags.yml create mode 100644 .mlem.yaml create mode 100644 deploy/dev.mlem create mode 100644 deploy/prod.mlem create mode 100644 deploy/staging.mlem create mode 100644 models/churn.pkl.mlem create mode 100644 train.py diff --git a/.github/workflows/deploy-model-with-mlem.yml b/.github/workflows/deploy-model-with-mlem.yml new file mode 100644 index 0000000..ae0e970 --- /dev/null +++ b/.github/workflows/deploy-model-with-mlem.yml @@ -0,0 +1,49 @@ +name: Deploy MLEM model after GTO Stage assignment +on: + push: + tags: + - "*" +env: + HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + +jobs: + parse-git-tag: + name: Figure out what was registered/promoted + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: "GTO: figure out what was registered/promoted and show the Registry state" + id: gto + uses: iterative/gto-action@v1 + with: + show: true + history: true + # we define the Job outputs here to let the next Job use them + outputs: + name: ${{ steps.gto.outputs.name }} + stage: ${{ steps.gto.outputs.stage }} + event: ${{ steps.gto.outputs.event }} + path: ${{ steps.gto.outputs.path }} + deploy-model: + name: Deploy a MLEM model (act on assigning a new stage) + needs: parse-git-tag + if: needs.parse-git-tag.outputs.event == 'assignment' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-python@v2 + with: + python-version: '3.10' + - name: Install dependencies + run: | + pip install --upgrade pip setuptools wheel + pip install -r requirements.txt + - name: Run `mlem deploy`` + run: | + mlem deployment run --load deploy/${{ needs.parse-git-tag.outputs.stage }} --model ${{ needs.parse-git-tag.outputs.path }} diff --git a/.github/workflows/gto-act-on-tags.yml b/.github/workflows/gto-act-on-tags.yml deleted file mode 100644 index 97211d7..0000000 --- a/.github/workflows/gto-act-on-tags.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Act on artifact registrations and promotions -on: - push: - tags: - - "*" - -jobs: - act: - name: Figure out what was registered/promoted and act on it - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: "GTO: figure out what was registered/promoted and show the Registry state" - id: gto - uses: iterative/gto-action@v1 - with: - show: true - history: true - - uses: actions/setup-python@v2 - - name: Install dependencies - run: | - pip install --upgrade pip setuptools wheel - pip install -r requirements.txt - - name: "Publish (act on registering a new version)" - if: steps.gto.outputs.event == 'registration' - run: | - echo "[$GITHUB_REF] You got version '${{ steps.gto.outputs.version }}' registered for model '${{ steps.gto.outputs.name }}' " - echo "[$GITHUB_REF] It is about time to publish it somewhere so others could use it!" - - name: "Deploy (act on assigning a new stage)" - if: steps.gto.outputs.event == 'assignment' - run: | - echo "[$GITHUB_REF] You got model '${{ steps.gto.outputs.name }}' of version '${{ steps.gto.outputs.version }}' promoted to stage '${{ steps.gto.outputs.stage }}'" - echo "[$GITHUB_REF] It is about time to deploy it somewhere!" diff --git a/.mlem.yaml b/.mlem.yaml new file mode 100644 index 0000000..827f248 --- /dev/null +++ b/.mlem.yaml @@ -0,0 +1,3 @@ +core: + state: + uri: s3://gto-mlem-example/mlem-deployment-state diff --git a/deploy/dev.mlem b/deploy/dev.mlem new file mode 100644 index 0000000..df4e97f --- /dev/null +++ b/deploy/dev.mlem @@ -0,0 +1,3 @@ +object_type: deployment +type: heroku +app_name: mlem-dev diff --git a/deploy/prod.mlem b/deploy/prod.mlem new file mode 100644 index 0000000..2fb9624 --- /dev/null +++ b/deploy/prod.mlem @@ -0,0 +1,3 @@ +object_type: deployment +type: heroku +app_name: mlem-prod diff --git a/deploy/staging.mlem b/deploy/staging.mlem new file mode 100644 index 0000000..dd9a1f8 --- /dev/null +++ b/deploy/staging.mlem @@ -0,0 +1,3 @@ +object_type: deployment +type: heroku +app_name: mlem-staging diff --git a/models/churn.pkl b/models/churn.pkl index dd26ff16dd12719c05f6a9f28d715768eaf2c7d6..29c08bc14e4054919a6b74998c71543a83381c9d 100644 GIT binary patch literal 319 zcmY+8KWoD<5XI%Su)buG((_EJ8A3n`&Ld! zpm%Wmc=zDF&-C{`VTTDwqap<(kolTs1-@U;wEwP zJVo}xsQjXEIY`|DMM`Ula)fvO=D~R`x4o|#W%#2)t`M9=H2{YX*>)Nh4m#@>H4JBE zi 1 else "no value" + + def model(data): + return value + + mlem.api.save(model, "models/churn.pkl", sample_data="string")