-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mlops-club/feat/sidebar
Feat/sidebar
- Loading branch information
Showing
14 changed files
with
387 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# BentoML Sklearn Example: Linear Regression | ||
|
||
0. Install dependencies: | ||
|
||
```bash | ||
pip install -r ./requirements.txt | ||
``` | ||
|
||
1. Train a linear regression model | ||
|
||
```bash | ||
python ./train.py | ||
``` | ||
|
||
2. Run the service: | ||
|
||
```bash | ||
bentoml serve service.py:svc | ||
``` | ||
|
||
3. Send test request | ||
|
||
``` | ||
curl -X POST -H "content-type: application/json" --data "[[5, 3]]" http://127.0.0.1:3000/predict | ||
``` | ||
|
||
4. Build Bento | ||
|
||
``` | ||
bentoml build | ||
``` | ||
|
||
5. Build docker image | ||
|
||
``` | ||
bentoml containerize linear_regression:latest | ||
``` |
5 changes: 5 additions & 0 deletions
5
bentoml-playground-workspace/linear_regression/bentofile.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
service: "service.py:svc" | ||
include: | ||
- "service.py" | ||
python: | ||
requirements_txt: "./requirements.txt" |
2 changes: 2 additions & 0 deletions
2
bentoml-playground-workspace/linear_regression/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bentoml>=1.0.0 | ||
scikit-learn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import bentoml | ||
from bentoml.io import NumpyNdarray | ||
|
||
reg_runner = bentoml.sklearn.get("linear_reg:latest").to_runner() | ||
|
||
svc = bentoml.Service("linear_regression", runners=[reg_runner]) | ||
|
||
input_spec = NumpyNdarray(dtype="int", shape=(-1, 2)) | ||
|
||
|
||
@svc.api(input=input_spec, output=NumpyNdarray()) | ||
async def predict(input_arr): | ||
return await reg_runner.predict.async_run(input_arr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from sklearn import linear_model | ||
|
||
import bentoml | ||
|
||
if __name__ == "__main__": | ||
reg = linear_model.LinearRegression() | ||
reg.fit([[0, 0], [1, 1], [2, 2]], [0, 1, 2]) | ||
|
||
print("coef: ", reg.coef_) | ||
bento_model = bentoml.sklearn.save_model("linear_reg", reg) | ||
print(f"Model saved: {bento_model}") | ||
|
||
# Test running inference with BentoML runner | ||
test_runner = bentoml.sklearn.get("linear_reg:latest").to_runner() | ||
test_runner.init_local() | ||
assert test_runner.predict.run([[1, 1]]) == reg.predict([[1, 1]]) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as vscode from 'vscode'; | ||
import { Model, SimpleModel, Bento } from './models'; | ||
import { runShellCommand } from '../shell'; | ||
import { getPathToActivePythonInterpreter, promptIfPythonInterpreterIsNotConfigured } from '../python'; | ||
|
||
|
||
export async function getModels() { | ||
const interpreterFpath = (await getPathToActivePythonInterpreter()) as string; | ||
const response = await runShellCommand(interpreterFpath, ["-m","bentoml", "models", "list", "--output", "json"]); | ||
console.log(`getModels() response: ${response.logs}`); | ||
return JSON.parse(response.logs) as SimpleModel[]; | ||
} | ||
|
||
export async function getBentos() { | ||
const interpreterFpath = (await getPathToActivePythonInterpreter()) as string; | ||
const response = await runShellCommand(interpreterFpath, ["-m","bentoml", "list", "--output", "json"]); | ||
console.log(`getBentos() response: ${response.logs}`); | ||
return JSON.parse(response.logs) as Bento[]; | ||
} | ||
|
||
export async function deleteModel(object: SimpleModel){ | ||
const interpreterFpath = (await getPathToActivePythonInterpreter()) as string; | ||
const response = await runShellCommand(interpreterFpath, ["-m","bentoml", "models","delete", object.tag, "-y"]); | ||
console.log(response.logs); | ||
return response.logs; | ||
} | ||
|
||
export async function deleteBento(object: Bento){ | ||
const interpreterFpath = (await getPathToActivePythonInterpreter()) as string; | ||
const response = await runShellCommand(interpreterFpath, ["-m","bentoml", "delete", object.tag, "-y"]); | ||
console.log(response.logs); | ||
return response.logs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.