Skip to content

Commit

Permalink
Merge pull request #178 from cliveseldon/misc_master_tests
Browse files Browse the repository at this point in the history
Rerun examples and add aio deploy_local/remote
  • Loading branch information
axsaucedo authored Aug 2, 2021
2 parents 29e08c4 + e674fee commit 9e3028c
Show file tree
Hide file tree
Showing 45 changed files with 2,689 additions and 2,754 deletions.
2 changes: 2 additions & 0 deletions conda/tempo-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ dependencies:
- pytest-asyncio==0.14.0
- pandas==1.0.1
- numpyro==0.6.0
- jax==0.2.10
- jaxlib==0.1.62
1 change: 1 addition & 0 deletions docs/api/tempo.insights.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Submodules
.. toctree::
:maxdepth: 6

tempo.insights.cloudevents
tempo.insights.manager
tempo.insights.worker
tempo.insights.wrapper
1 change: 1 addition & 0 deletions docs/api/tempo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Subpackages
tempo.kfserving
tempo.seldon
tempo.serve
tempo.state

Submodules
----------
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ all: $(EXAMPLES_MD)
.ipynb.md:
jupyter nbconvert \
$< \
--ClearOutputPreprocessor.enabled=True \
--ClearOutputPreprocessor.enabled=False \
--to markdown \
--output $(notdir $@)

Expand Down
135 changes: 101 additions & 34 deletions docs/examples/asyncio/README.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "alert-surge",
"metadata": {
"scrolled": true
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[01;34m.\u001b[00m\r\n",
"├── \u001b[01;34martifacts\u001b[00m\r\n",
"│   ├── \u001b[01;34mclassifier\u001b[00m\r\n",
"│   ├── \u001b[01;34msklearn\u001b[00m\r\n",
"│   └── \u001b[01;34mxgboost\u001b[00m\r\n",
"└── \u001b[01;34msrc\u001b[00m\r\n",
" ├── constants.py\r\n",
" ├── data.py\r\n",
" ├── tempo.py\r\n",
" └── train.py\r\n",
"\r\n",
"5 directories, 4 files\r\n"
]
}
],
"source": [
"!tree -P \"*.py\" -I \"__init__.py|__pycache__\" -L 2"
]
Expand All @@ -65,7 +84,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "equipped-silence",
"metadata": {},
"outputs": [],
Expand All @@ -79,24 +98,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "reported-hurricane",
"metadata": {
"code_folding": [
0
]
"code_folding": []
},
"outputs": [],
"source": [
"# %load src/train.py\n",
"import joblib\n",
"import os\n",
"\n",
"import joblib\n",
"from sklearn.linear_model import LogisticRegression\n",
"from xgboost import XGBClassifier\n",
"\n",
"from src.data import IrisData\n",
"from src.constants import SKLearnFolder, XGBoostFolder\n",
"from src.data import IrisData\n",
"from xgboost import XGBClassifier\n",
"\n",
"\n",
"def train_sklearn(data: IrisData):\n",
Expand All @@ -118,10 +134,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "lesser-reply",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[18:05:52] WARNING: ../src/learner.cc:1095: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'multi:softprob' was changed from 'merror' to 'mlogloss'. Explicitly set eval_metric if you'd like to restore the old behavior.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/clive/anaconda3/envs/tempo-examples/lib/python3.7/site-packages/xgboost/sklearn.py:1146: UserWarning: The use of label encoder in XGBClassifier is deprecated and will be removed in a future release. To remove this warning, do the following: 1) Pass option use_label_encoder=False when constructing XGBClassifier object; and 2) Encode your labels (y) as integers starting with 0, i.e. 0, 1, 2, ..., [num_class - 1].\n",
" warnings.warn(label_encoder_deprecation_msg, UserWarning)\n"
]
}
],
"source": [
"from src.data import IrisData\n",
"from src.train import train_sklearn, train_xgboost\n",
Expand All @@ -145,7 +177,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "smoking-tribe",
"metadata": {},
"outputs": [],
Expand All @@ -155,22 +187,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "regular-balance",
"metadata": {
"code_folding": [
0
]
"code_folding": []
},
"outputs": [],
"source": [
"# %load src/tempo.py\n",
"import numpy as np\n",
"from src.constants import ClassifierFolder, SKLearnFolder, XGBoostFolder\n",
"\n",
"from tempo import ModelFramework, PipelineModels\n",
"from tempo.aio import pipeline, Model\n",
"\n",
"from src.constants import ClassifierFolder, SKLearnFolder, XGBoostFolder\n",
"from tempo.aio import Model, pipeline\n",
"\n",
"SKLearnModel = Model(\n",
" name=\"test-iris-sklearn\",\n",
Expand Down Expand Up @@ -214,20 +243,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "considered-terminology",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"artifacts/classifier/conda.yaml\r\n"
]
}
],
"source": [
"!cat artifacts/classifier/conda.yaml"
"!ls artifacts/classifier/conda.yaml"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "rural-mathematics",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting packages...\n",
"Packing environment at '/home/clive/anaconda3/envs/tempo-330c15d8-a189-45a6-abc3-a27f39b6a7c5' to '/home/clive/work/mlops/fork-tempo/docs/examples/asyncio/artifacts/classifier/environment.tar.gz'\n",
"[########################################] | 100% Completed | 11.2s\n"
]
}
],
"source": [
"import tempo\n",
"\n",
Expand All @@ -246,40 +293,60 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "56037cc4",
"metadata": {},
"outputs": [],
"source": [
"from tempo.aio import deploy\n",
"remote_model = deploy(classifier)"
"from tempo.aio import deploy_local\n",
"remote_model = deploy_local(classifier)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "cb489575",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"array([2.], dtype=float32)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"await remote_model.predict(np.array([[1, 2, 3, 4]]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "dc6c0829",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1.]\n",
"[[0.97329617 0.02412145 0.00258233]]\n"
]
}
],
"source": [
"print(await remote_model.predict(np.array([[0, 0, 0,0]])))\n",
"print(await remote_model.predict(np.array([[5.964,4.006,2.081,1.031]])))"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "6fa56a63",
"metadata": {},
"outputs": [],
Expand Down
Loading

0 comments on commit 9e3028c

Please sign in to comment.