Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(MLflow)[KLV-30]: Support mlflow #140

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/MLflow-model/model/MLmodel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
artifact_path: model
flavors:
python_function:
env: conda.yaml
loader_module: mlflow.sklearn
model_path: model.pkl
python_version: 3.6.12
sklearn:
pickled_model: model.pkl
serialization_format: cloudpickle
sklearn_version: 0.19.1
run_id: 850277c51810451fab9b06976cf6cf84
utc_time_created: '2020-10-19 13:08:18.484317'
11 changes: 11 additions & 0 deletions examples/MLflow-model/model/conda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
channels:
- defaults
- conda-forge
dependencies:
- python=3.6.12
- scikit-learn=0.19.1
- pip
- pip:
- mlflow
- cloudpickle==1.6.0
name: mlflow-env
Binary file added examples/MLflow-model/model/model.pkl
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/MLflow-model/ormbfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
author: "c1 <wangsiyuan.wangsy@bytedance.com>"
format: "MLflow"
21 changes: 21 additions & 0 deletions pkg/model/format.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand All @@ -23,6 +24,7 @@ const (
FormatTensorRT Format = "TensorRT"
FormatSKLearn Format = "SKLearn"
FormatXGBoost Format = "XGBoost"
FormatMLflow Format = "MLflow"
FormatOthers Format = "Others"
)

Expand Down Expand Up @@ -62,7 +64,12 @@ func (f Format) ValidateDirectory(rootPath string) error {
err = f.validateForSKLearn(modelFilePath, fileList)
case FormatXGBoost:
err = f.validateForXGBoost(modelFilePath, fileList)
case FormatMLflow:
err = f.validateForMLflow(modelFilePath, fileList)
default:
err = errors.New("unrecognized model format, please check the ormbfile.yaml")
}

if err != nil {
return err
}
Expand Down Expand Up @@ -252,3 +259,17 @@ func (f Format) validateForXGBoost(modelPath string, files []os.FileInfo) error
}
return nil
}

func (f Format) validateForMLflow(modelPath string, files []os.FileInfo) error {
var isMLflowFile bool
for _, file := range files {
if file.Name() == "MLmodel" {
// assuming that user would not fool the tool
isMLflowFile = true
}
}
if !isMLflowFile {
return fmt.Errorf("there are no MLmodel file in %v, directory", modelPath)
}
return nil
}
12 changes: 12 additions & 0 deletions pkg/model/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,16 @@ var _ = Describe("Format", func() {
err := xgboostFormat.ValidateDirectory("../../examples/XGBoost-model")
Expect(err).To(BeNil())
})

It("Should validate MLmodel format successfully", func() {
mlmodelFormat := model.FormatMLflow
err := mlmodelFormat.ValidateDirectory("../../examples/MLflow-model")
Expect(err).To(BeNil())
})

It("Should validate fail for corruptted format", func() {
others := model.FormatOthers
err := others.ValidateDirectory("../../test/Corrupt")
Expect(err).Should(HaveOccurred())
})
})
8 changes: 8 additions & 0 deletions test/Corrupt/model/corrupt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env -S scheme --script

(define ode-to-a-nightingale "\'Tis not through envy of thy happy lot, but being too happy in thine happiness.")

(define (main)
(display ode-to-a-nightingale))

(main)
2 changes: 2 additions & 0 deletions test/Corrupt/ormbfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
author: "c1 <wangsiyuan.wangsy@bytedance.com>"
format: "corruptted :)"