Skip to content

Commit

Permalink
update tutorials and add a demo notebook for the KFP option
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaquinRivesGambin committed Apr 15, 2024
1 parent 483579d commit 1bf9fe3
Show file tree
Hide file tree
Showing 9 changed files with 1,093 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "ef37a9bc",
"metadata": {},
"outputs": [],
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-13T09:16:14.457318Z",
"start_time": "2024-04-13T09:16:14.094491Z"
}
},
"source": [
"@component(\n",
" base_image=\"python:3.9\",\n",
Expand All @@ -800,6 +803,7 @@
" from kserve import V1beta1InferenceServiceSpec\n",
" from kserve import V1beta1PredictorSpec\n",
" from kserve import V1beta1SKLearnSpec\n",
" from kubernetes.client import V1ResourceRequirements\n",
" import logging\n",
" \n",
" deploy_model_component_landmark = 'KFP_component'\n",
Expand All @@ -815,25 +819,45 @@
" api_version = constants.KSERVE_GROUP + '/' + kserve_version\n",
"\n",
" isvc = V1beta1InferenceService(\n",
" api_version=api_version,\n",
" kind=constants.KSERVE_KIND,\n",
" metadata=client.V1ObjectMeta(\n",
" name=model_name,\n",
" namespace=namespace,\n",
" annotations={'sidecar.istio.io/inject':'false'}\n",
" api_version = api_version,\n",
" kind = constants.KSERVE_KIND,\n",
" metadata = client.V1ObjectMeta(\n",
" name = model_name,\n",
" namespace = namespace,\n",
" annotations = {'sidecar.istio.io/inject':'false'}\n",
" ),\n",
" spec=V1beta1InferenceServiceSpec(\n",
" spec = V1beta1InferenceServiceSpec(\n",
" predictor=V1beta1PredictorSpec(\n",
" service_account_name=\"kserve-sa\",\n",
" min_replicas=1,\n",
" max_replicas = 1,\n",
" sklearn=V1beta1SKLearnSpec(\n",
" storage_uri=model_uri\n",
" )\n",
" storage_uri=model_uri,\n",
" resources=V1ResourceRequirements(\n",
" requests={\"cpu\": \"100m\", \"memory\": \"512Mi\"},\n",
" limits={\"cpu\": \"300m\", \"memory\": \"512Mi\"}\n",
" )\n",
" ),\n",
" )\n",
" )\n",
" )\n",
" KServe = KServeClient()\n",
" KServe.create(isvc)"
]
],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'component' is not defined",
"output_type": "error",
"traceback": [
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[0;31mNameError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[0;32mIn[1], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m \u001B[38;5;129m@component\u001B[39m(\n\u001B[1;32m 2\u001B[0m base_image\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mpython:3.9\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[1;32m 3\u001B[0m packages_to_install\u001B[38;5;241m=\u001B[39m[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mkserve=0.12.0\u001B[39m\u001B[38;5;124m\"\u001B[39m],\n\u001B[1;32m 4\u001B[0m output_component_file\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mcomponents/deploy_model_component.yaml\u001B[39m\u001B[38;5;124m'\u001B[39m,\n\u001B[1;32m 5\u001B[0m )\n\u001B[1;32m 6\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mdeploy_model\u001B[39m(model_name: \u001B[38;5;28mstr\u001B[39m, storage_uri: \u001B[38;5;28mstr\u001B[39m):\n\u001B[1;32m 7\u001B[0m \u001B[38;5;250m \u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 8\u001B[0m \u001B[38;5;124;03m Deploy the model as a inference service with Kserve.\u001B[39;00m\n\u001B[1;32m 9\u001B[0m \u001B[38;5;124;03m \"\"\"\u001B[39;00m\n\u001B[1;32m 10\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mkubernetes\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m client\n",
"\u001B[0;31mNameError\u001B[0m: name 'component' is not defined"
]
}
],
"execution_count": 1
},
{
"cell_type": "markdown",
Expand All @@ -853,10 +877,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "b90d1839",
"metadata": {},
"outputs": [],
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-13T09:16:14.719526Z",
"start_time": "2024-04-13T09:16:14.679920Z"
}
},
"source": [
"@component(\n",
" base_image=\"python:3.9\", # kserve on python 3.10 comes with a dependency that fails to get installed\n",
Expand Down Expand Up @@ -1025,7 +1052,21 @@
" if response.status_code != 200:\n",
" raise RuntimeError(f\"HTTP status code '{response.status_code}': {response.json()}\")\n",
" logger.info(f\"\\nPrediction response:\\n{response.text}\\n\")"
]
],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'component' is not defined",
"output_type": "error",
"traceback": [
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[0;31mNameError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[0;32mIn[2], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m \u001B[38;5;129m@component\u001B[39m(\n\u001B[1;32m 2\u001B[0m base_image\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mpython:3.9\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;66;03m# kserve on python 3.10 comes with a dependency that fails to get installed\u001B[39;00m\n\u001B[1;32m 3\u001B[0m packages_to_install\u001B[38;5;241m=\u001B[39m[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mkserve\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mscikit-learn~=1.0.2\u001B[39m\u001B[38;5;124m\"\u001B[39m],\n\u001B[1;32m 4\u001B[0m output_component_file\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mcomponents/inference_component.yaml\u001B[39m\u001B[38;5;124m'\u001B[39m,\n\u001B[1;32m 5\u001B[0m )\n\u001B[1;32m 6\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21minference\u001B[39m(\n\u001B[1;32m 7\u001B[0m model_name: \u001B[38;5;28mstr\u001B[39m\n\u001B[1;32m 8\u001B[0m ):\n\u001B[1;32m 9\u001B[0m \u001B[38;5;250m \u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 10\u001B[0m \u001B[38;5;124;03m Test inference.\u001B[39;00m\n\u001B[1;32m 11\u001B[0m \u001B[38;5;124;03m \"\"\"\u001B[39;00m\n\u001B[1;32m 12\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mkserve\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m KServeClient\n",
"\u001B[0;31mNameError\u001B[0m: name 'component' is not defined"
]
}
],
"execution_count": 2
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -1311,7 +1352,7 @@
"If not, removing the cluster and reinstalling everything is usually easier. A more surgical approach is to use kubectl to check the logs of pods in the given namespace and configure used YAMLs to fix the issue. When the modified YAMLs have been saved, just apply them and then rollout restart the pods. It is recommended to stop any dashboards before doing this. The required commands cluster removal, and kubectl fixing are:\n",
"\n",
"Cluster removal:\n",
"- Cluster deletion = kind delete cluster --name kind-ep\n",
"- Cluster deletion = kind delete cluster --name mlops-platform\n",
"- Registry deletion = docker rm -f $(docker ps -aqf \"name=kind-registry\")\n",
"\n",
"Optional docker clean up:\n",
Expand Down
Loading

0 comments on commit 1bf9fe3

Please sign in to comment.