Improve tutorial

This commit is contained in:
Andras Schmelczer 2022-07-12 16:00:20 +02:00
parent b1d6a09cfe
commit dc1a36edac
No known key found for this signature in database
GPG key ID: 0EA1BC97D0AB076E
3 changed files with 99 additions and 197 deletions

View file

@ -6,9 +6,9 @@
"source": [ "source": [
"# Harden and deploy your app\n", "# Harden and deploy your app\n",
"\n", "\n",
"Finally, it's time to deploy your model. But before you have to make sure you follow AI deployment [best-practices](https://se-ml.github.io/). In the past, this step was too often either the source of unexpected struggles, or worse, simply ignored.\n", "Finally, it's time to deploy your model. But before that, you have to make sure you follow AI deployment [best-practices](https://se-ml.github.io/). In the past, this step was too often either the source of unexpected struggles, or worse, simply ignored.\n",
"\n", "\n",
"With `GreatAI`, it has become a matter of 2 lines of code." "With `GreatAI`, it has become a matter of 4 lines of code."
] ]
}, },
{ {
@ -20,22 +20,22 @@
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\u001b[38;5;226m2022-07-09 22:38:56 | WARNING | Environment variable ENVIRONMENT is not set, defaulting to development mode ‼️\u001b[0m\n", "\u001b[38;5;226mEnvironment variable ENVIRONMENT is not set, defaulting to development mode ‼️\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:38:56 | WARNING | Cannot find credentials files, defaulting to using ParallelTinyDbDriver\u001b[0m\n", "\u001b[38;5;226mCannot find credentials files, defaulting to using ParallelTinyDbDriver\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:38:56 | WARNING | The selected tracing database (ParallelTinyDbDriver) is not recommended for production\u001b[0m\n", "\u001b[38;5;226mThe selected tracing database (ParallelTinyDbDriver) is not recommended for production\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:38:56 | WARNING | Cannot find credentials files, defaulting to using LargeFileLocal\u001b[0m\n", "\u001b[38;5;226mCannot find credentials files, defaulting to using LargeFileLocal\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:56 | INFO | GreatAI (v0.1.0): configured ✅\u001b[0m\n", "\u001b[38;5;39mGreatAI (v0.1.4): configured ✅\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:56 | INFO | 🔩 tracing_database: ParallelTinyDbDriver\u001b[0m\n", "\u001b[38;5;39m 🔩 tracing_database: ParallelTinyDbDriver\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:56 | INFO | 🔩 large_file_implementation: LargeFileLocal\u001b[0m\n", "\u001b[38;5;39m 🔩 large_file_implementation: LargeFileLocal\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:56 | INFO | 🔩 is_production: False\u001b[0m\n", "\u001b[38;5;39m 🔩 is_production: False\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:56 | INFO | 🔩 should_log_exception_stack: True\u001b[0m\n", "\u001b[38;5;39m 🔩 should_log_exception_stack: True\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:56 | INFO | 🔩 prediction_cache_size: 512\u001b[0m\n", "\u001b[38;5;39m 🔩 prediction_cache_size: 512\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:56 | INFO | 🔩 dashboard_table_size: 20\u001b[0m\n", "\u001b[38;5;39m 🔩 dashboard_table_size: 50\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:38:56 | WARNING | You still need to check whether you follow all best practices before trusting your deployment.\u001b[0m\n", "\u001b[38;5;226mYou still need to check whether you follow all best practices before trusting your deployment.\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:38:56 | WARNING | > Find out more at https://se-ml.github.io/practices\u001b[0m\n", "\u001b[38;5;226m> Find out more at https://se-ml.github.io/practices\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:56 | INFO | Fetching cached versions of my-domain-predictor\u001b[0m\n", "\u001b[38;5;39mFetching cached versions of my-domain-predictor\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:56 | INFO | Latest version of my-domain-predictor is 5 (from versions: 0, 1, 2, 3, 4, 5)\u001b[0m\n", "\u001b[38;5;39mLatest version of my-domain-predictor is 9 (from versions: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:56 | INFO | File my-domain-predictor-5 found in cache\u001b[0m\n" "\u001b[38;5;39mFile my-domain-predictor-9 found in cache\u001b[0m\n"
] ]
} }
], ],
@ -59,16 +59,16 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"Trace[str]({ 'created': '2022-07-09T20:38:56.394746',\n", "Trace[str]({'created': '2022-07-12T13:34:26.743292',\n",
" 'exception': None,\n", " 'exception': None,\n",
" 'feedback': None,\n", " 'feedback': None,\n",
" 'logged_values': { 'arg:sentence:length': 29,\n", " 'logged_values': { 'arg:sentence:length': 29,\n",
" 'arg:sentence:value': 'Mountains are just big rocks.'},\n", " 'arg:sentence:value': 'Mountains are just big rocks.'},\n",
" 'models': [{'key': 'my-domain-predictor', 'version': 5}],\n", " 'models': [{'key': 'my-domain-predictor', 'version': 9}],\n",
" 'original_execution_time_ms': 4.999,\n", " 'original_execution_time_ms': 6.9699,\n",
" 'output': 'geography',\n", " 'output': 'geography',\n",
" 'tags': ['predict_domain', 'online', 'development'],\n", " 'tags': ['predict_domain', 'online', 'development'],\n",
" 'trace_id': 'aad1f83d-a81f-4b8b-898e-d02f8076616f'})" " 'trace_id': 'c80bdee3-602b-49dd-a84d-6eef80127e5a'})"
] ]
}, },
"execution_count": 2, "execution_count": 2,
@ -77,8 +77,16 @@
} }
], ],
"source": [ "source": [
"predict_domain(\"Mountains are just big rocks.\")\n", "predict_domain(\"Mountains are just big rocks.\")"
"# the original return value is under the 'output' key" ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice how the original return value is under the `.output` key. Additionally, a plethora of metadata has been added which will be useful later on.\n",
"\n",
"Running your app in development-mode is as easy as executing `great-ai deploy.ipynb` from your terminal."
] ]
}, },
{ {
@ -90,33 +98,33 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\u001b[38;5;39m2022-07-09 22:38:58 | INFO | Converting notebook to Python script\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:28 | INFO | Converting notebook to Python script\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:58 | INFO | Found `predict_domain` to be the GreatAI app \u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:29 | INFO | Found `predict_domain` to be the GreatAI app \u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:38:58 | INFO | Uvicorn running on http://0.0.0.0:6060 (Press CTRL+C to quit)\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:29 | INFO | Uvicorn running on http://0.0.0.0:6060 (Press CTRL+C to quit)\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:39:00 | WARNING | Environment variable ENVIRONMENT is not set, defaulting to development mode ‼️\u001b[0m\n", "\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | Environment variable ENVIRONMENT is not set, defaulting to development mode ‼️\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:39:00 | WARNING | Cannot find credentials files, defaulting to using ParallelTinyDbDriver\u001b[0m\n", "\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | Cannot find credentials files, defaulting to using ParallelTinyDbDriver\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:39:00 | WARNING | The selected tracing database (ParallelTinyDbDriver) is not recommended for production\u001b[0m\n", "\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | The selected tracing database (ParallelTinyDbDriver) is not recommended for production\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:39:00 | WARNING | Cannot find credentials files, defaulting to using LargeFileLocal\u001b[0m\n", "\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | Cannot find credentials files, defaulting to using LargeFileLocal\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | GreatAI (v0.1.0): configured ✅\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | GreatAI (v0.1.4): configured ✅\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | 🔩 tracing_database: ParallelTinyDbDriver\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 tracing_database: ParallelTinyDbDriver\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | 🔩 large_file_implementation: LargeFileLocal\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 large_file_implementation: LargeFileLocal\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | 🔩 is_production: False\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 is_production: False\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | 🔩 should_log_exception_stack: True\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 should_log_exception_stack: True\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | 🔩 prediction_cache_size: 512\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 prediction_cache_size: 512\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | 🔩 dashboard_table_size: 20\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 dashboard_table_size: 50\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:39:00 | WARNING | You still need to check whether you follow all best practices before trusting your deployment.\u001b[0m\n", "\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | You still need to check whether you follow all best practices before trusting your deployment.\u001b[0m\n",
"\u001b[38;5;226m2022-07-09 22:39:00 | WARNING | > Find out more at https://se-ml.github.io/practices\u001b[0m\n", "\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | > Find out more at https://se-ml.github.io/practices\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | Fetching cached versions of my-domain-predictor\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | Fetching cached versions of my-domain-predictor\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | Latest version of my-domain-predictor is 5 (from versions: 0, 1, 2, 3, 4, 5)\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | Latest version of my-domain-predictor is 9 (from versions: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | File my-domain-predictor-5 found in cache\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | File my-domain-predictor-9 found in cache\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | Started server process [882179]\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | Started server process [199794]\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | Waiting for application startup.\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | Waiting for application startup.\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:00 | INFO | Application startup complete.\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:31 | INFO | Application startup complete.\u001b[0m\n",
"^C\n", "^C\n",
"\u001b[38;5;39m2022-07-09 22:39:04 | INFO | Shutting down\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:33 | INFO | Shutting down\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:04 | INFO | Waiting for application shutdown.\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:33 | INFO | Waiting for application shutdown.\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:04 | INFO | Application shutdown complete.\u001b[0m\n", "\u001b[38;5;39m2022-07-12 15:34:33 | INFO | Application shutdown complete.\u001b[0m\n",
"\u001b[38;5;39m2022-07-09 22:39:04 | INFO | Finished server process [882179]\u001b[0m\n" "\u001b[38;5;39m2022-07-12 15:34:33 | INFO | Finished server process [199794]\u001b[0m\n"
] ]
} }
], ],
@ -129,16 +137,15 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Congrats, you've just created your first GreatAI service! 🎉\n",
"\n",
"Now that you've made sure your application is hardened enough for the intended use case, it is time to deploy it. The responsibilities of GreatAI end when it wraps your inference function and model into a production-ready service. You're given the freedom and responsibility to deploy this service. Fortunately, you (or your organisation) probably already has an established routine for deploying services.\n", "Now that you've made sure your application is hardened enough for the intended use case, it is time to deploy it. The responsibilities of GreatAI end when it wraps your inference function and model into a production-ready service. You're given the freedom and responsibility to deploy this service. Fortunately, you (or your organisation) probably already has an established routine for deploying services.\n",
"\n", "\n",
"There are three main approaches to deploy a GreatAI service: For more info about them, check out [the deployment how-to](/how-to-guides/use-service)." "There are three main approaches to deploy a GreatAI service: For more info about them, check out [the deployment how-to](/how-to-guides/use-service).\n",
] "\n",
}, "For more thorough examples, see the [examples page](/examples).\n",
{ "\n",
"cell_type": "markdown", "### [Go back to the summary](/tutorial/#summary)"
"metadata": {},
"source": [
"### [Go back to the summary](/tutorial)"
] ]
} }
], ],

View file

@ -1,11 +1,11 @@
# Train and deploy a SOTA model # Train and deploy a SOTA model
Let's see GreatAI in action by going over the life-cycle of a simple service. Let's see `great-ai` in action by going over the life-cycle of a simple service.
## Objectives ## Objectives
1. You will see how the [great_ai.utilities][] can integrate into your Data Science workflow. 1. You will see how the [great_ai.utilities](/reference/utilities) can integrate into your Data Science workflow.
2. You will use [great_ai.large_file][] to version and store your trained model. 2. You will use [great_ai.large_file](/reference/large_file) to version and store your trained model.
3. You will use [GreatAI][great_ai.GreatAI] to prepare your model for a robust and responsible deployment. 3. You will use [GreatAI][great_ai.GreatAI] to prepare your model for a robust and responsible deployment.
## Overview ## Overview
@ -14,7 +14,6 @@ You are going to train a field of study (domain) classifier for scientific sente
We use the same synthetic dataset derived from the [Microsoft Academic Graph](https://www.microsoft.com/en-us/research/project/microsoft-academic-graph/). The dataset is [available here](https://github.com/allenai/scibert/tree/master/data/text_classification/mag). We use the same synthetic dataset derived from the [Microsoft Academic Graph](https://www.microsoft.com/en-us/research/project/microsoft-academic-graph/). The dataset is [available here](https://github.com/allenai/scibert/tree/master/data/text_classification/mag).
!!! success !!! success
You are ready to start the tutorial. Feel free to come back to the [summary](#summary) section once you're finished. You are ready to start the tutorial. Feel free to come back to the [summary](#summary) section once you're finished.
@ -24,19 +23,18 @@ We use the same synthetic dataset derived from the [Microsoft Academic Graph](ht
[:material-cloud-tags: Deploy it](deploy.ipynb){ .md-button .md-button--primary } [:material-cloud-tags: Deploy it](deploy.ipynb){ .md-button .md-button--primary }
</div> </div>
## Summary ## Summary
### The [training notebook](train.ipynb) ### The [training notebook](train.ipynb)
We load and preprocess the dataset while relying on [great_ai.utilities.clean][] for the heavy-lifting. Additionally, the preprocessing is parallelised using [great_ai.utilities.simple_parallel_map][] We load and preprocess the dataset while relying on [great_ai.utilities.clean][great_ai.utilities.clean.clean] for doing the heavy-lifting. Additionally, the preprocessing is parallelised using [great_ai.utilities.simple_parallel_map][]
After training and evaluating a model, it is exported using [great_ai.save_model][]. After training and evaluating a model, it is exported using [great_ai.save_model][].
??? tip "Remote storage" ??? tip "Remote storage"
To store your model remotely, you need to set your credentials before calling `save_model`. To store your model remotely, you need to set your credentials before calling `save_model`.
For example, to use [AWS S3](https://aws.amazon.com/s3/): For example, to use [AWS S3](https://aws.amazon.com/s3){ target=_blank }:
```python ```python
from great_ai.large_file import LargeFileS3 from great_ai.large_file import LargeFileS3
@ -52,6 +50,8 @@ After training and evaluating a model, it is exported using [great_ai.save_model
save_model(model, key='my-domain-predictor') save_model(model, key='my-domain-predictor')
``` ```
For more info, checkout [the configuration how-to page](/how-to-guides/configure-service).
### The [deployment notebook](deploy.ipynb) ### The [deployment notebook](deploy.ipynb)
We create an inference function that can be hardened by wrapping it in a [GreatAI][great_ai.GreatAI] instance. We create an inference function that can be hardened by wrapping it in a [GreatAI][great_ai.GreatAI] instance.
@ -68,6 +68,10 @@ def predict_domain(sentence, model):
``` ```
1. [@use_model][great_ai.use_model] loads and injects your model into the `predict_domain` function's `model` argument. 1. [@use_model][great_ai.use_model] loads and injects your model into the `predict_domain` function's `model` argument.
You can freely reference it knowing that it is always given to the function. You can freely reference it knowing that the function is always provided with it.
Finally, we test the model's inference function through the GreatAI dashboard. [The only thing left is to deploy the hardened-service.](/how-to-guides/use-service) Finally, we test the model's inference function through the GreatAI dashboard. [The only thing left is to deploy the hardened-service properly.](/how-to-guides/use-service)
<div style="display: flex; justify-content: center;" markdown>
[:material-book: Learn about more features](/how-to-guides/create-service){ .md-button .md-button--primary }
</div>

File diff suppressed because one or more lines are too long