Skip to content

Commit

Permalink
Custom server container registry (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
saeid93 authored Sep 12, 2022
1 parent 7717b1c commit b7dfe51
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
56 changes: 25 additions & 31 deletions docs/examples/custom/README.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,29 @@
"from jax import random\n",
"from numpyro.infer import MCMC, NUTS\n",
"\n",
"DATASET_URL = 'https://raw.githubusercontent.com/rmcelreath/rethinking/master/data/WaffleDivorce.csv'\n",
"dset = pd.read_csv(DATASET_URL, sep=';')\n",
"DATASET_URL = \"https://raw.githubusercontent.com/rmcelreath/rethinking/master/data/WaffleDivorce.csv\"\n",
"dset = pd.read_csv(DATASET_URL, sep=\";\")\n",
"\n",
"standardize = lambda x: (x - x.mean()) / x.std()\n",
"\n",
"dset['AgeScaled'] = dset.MedianAgeMarriage.pipe(standardize)\n",
"dset['MarriageScaled'] = dset.Marriage.pipe(standardize)\n",
"dset['DivorceScaled'] = dset.Divorce.pipe(standardize)\n",
"dset[\"AgeScaled\"] = dset.MedianAgeMarriage.pipe(standardize)\n",
"dset[\"MarriageScaled\"] = dset.Marriage.pipe(standardize)\n",
"dset[\"DivorceScaled\"] = dset.Divorce.pipe(standardize)\n",
"\n",
"\n",
"def model(marriage=None, age=None, divorce=None):\n",
" a = numpyro.sample('a', dist.Normal(0., 0.2))\n",
" M, A = 0., 0.\n",
" a = numpyro.sample(\"a\", dist.Normal(0.0, 0.2))\n",
" M, A = 0.0, 0.0\n",
" if marriage is not None:\n",
" bM = numpyro.sample('bM', dist.Normal(0., 0.5))\n",
" bM = numpyro.sample(\"bM\", dist.Normal(0.0, 0.5))\n",
" M = bM * marriage\n",
" if age is not None:\n",
" bA = numpyro.sample('bA', dist.Normal(0., 0.5))\n",
" bA = numpyro.sample(\"bA\", dist.Normal(0.0, 0.5))\n",
" A = bA * age\n",
" sigma = numpyro.sample('sigma', dist.Exponential(1.))\n",
" sigma = numpyro.sample(\"sigma\", dist.Exponential(1.0))\n",
" mu = a + M + A\n",
" numpyro.sample('obs', dist.Normal(mu, sigma), obs=divorce)\n",
" numpyro.sample(\"obs\", dist.Normal(mu, sigma), obs=divorce)\n",
"\n",
"\n",
"# Start from this source of randomness. We will split keys for subsequent operations.\n",
"rng_key = random.PRNGKey(0)\n",
Expand All @@ -85,7 +87,9 @@
"# Run NUTS.\n",
"kernel = NUTS(model)\n",
"mcmc = MCMC(kernel, num_warmup=num_warmup, num_samples=num_samples)\n",
"mcmc.run(rng_key_, marriage=dset.MarriageScaled.values, divorce=dset.DivorceScaled.values)\n",
"mcmc.run(\n",
" rng_key_, marriage=dset.MarriageScaled.values, divorce=dset.DivorceScaled.values\n",
")\n",
"mcmc.print_summary()"
]
},
Expand Down Expand Up @@ -113,9 +117,9 @@
"serialisable = {}\n",
"for k, v in samples.items():\n",
" serialisable[k] = np.asarray(v).tolist()\n",
" \n",
"\n",
"model_file_name = \"numpyro-divorce.json\"\n",
"with open(model_file_name, 'w') as model_file:\n",
"with open(model_file_name, \"w\") as model_file:\n",
" json.dump(serialisable, model_file)"
]
},
Expand Down Expand Up @@ -309,14 +313,7 @@
"\n",
"x_0 = [28.0]\n",
"inference_request = {\n",
" \"inputs\": [\n",
" {\n",
" \"name\": \"marriage\",\n",
" \"shape\": [1],\n",
" \"datatype\": \"FP32\",\n",
" \"data\": x_0\n",
" }\n",
" ]\n",
" \"inputs\": [{\"name\": \"marriage\", \"shape\": [1], \"datatype\": \"FP32\", \"data\": x_0}]\n",
"}\n",
"\n",
"endpoint = \"http://localhost:8080/v2/models/numpyro-divorce/infer\"\n",
Expand Down Expand Up @@ -410,21 +407,14 @@
"\n",
"x_0 = [28.0]\n",
"inference_request = {\n",
" \"inputs\": [\n",
" {\n",
" \"name\": \"marriage\",\n",
" \"shape\": [1],\n",
" \"datatype\": \"FP32\",\n",
" \"data\": x_0\n",
" }\n",
" ]\n",
" \"inputs\": [{\"name\": \"marriage\", \"shape\": [1], \"datatype\": \"FP32\", \"data\": x_0}]\n",
"}\n",
"\n",
"endpoint = \"http://localhost:8080/v2/models/numpyro-divorce/infer\"\n",
"response = requests.post(endpoint, json=inference_request)\n",
"\n",
"print(response)\n",
"print(response.text)\n"
"print(response.text)"
]
},
{
Expand All @@ -448,6 +438,10 @@
"There is a large number of tools out there to deploy images.\n",
"However, for our example, we will focus on deploying it to a cluster running [Seldon Core](https://docs.seldon.io/projects/seldon-core/en/latest/).\n",
"\n",
"```{note}\n",
"Also consider that depending on your Kubernetes installation Seldon Core might expect to get the container image from a public container registry like [Docker hub](https://hub.docker.com/) or [Google Container Registry](https://cloud.google.com/container-registry). For that you need to do an extra step of pushing the container to the registry using `docker tag <image name> <container registry>/<image name>` and `docker push <container registry>/<image name>` and also updating the `image` section of the yaml file to `<container registry>/<image name>`. \n",
"```\n",
"\n",
"For that, we will need to create a `SeldonDeployment` resource which instructs Seldon Core to deploy a model embedded within our custom image and compliant with the [V2 Inference Protocol](https://github.com/kserve/kserve/tree/master/docs/predict-api/v2).\n",
"This can be achieved by _applying_ (i.e. `kubectl apply`) a `SeldonDeployment` manifest to the cluster, similar to the one below:"
]
Expand Down
4 changes: 4 additions & 0 deletions docs/examples/custom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ Now that we've built a custom image and verified that it works as expected, we c
There is a large number of tools out there to deploy images.
However, for our example, we will focus on deploying it to a cluster running [Seldon Core](https://docs.seldon.io/projects/seldon-core/en/latest/).

```{note}
Also consider that depending on your Kubernetes installation Seldon Core might excpect to get the container image from a public container registry like [Docker hub](https://hub.docker.com/) or [Google Container Registry](https://cloud.google.com/container-registry). For that you need to do an extra step of pushing the container to the registry using `docker tag <image name> <container registry>/<image name>` and `docker push <container registry>/<image name>` and also updating the `image` section of the yaml file to `<container registry>/<image name>`.
```

For that, we will need to create a `SeldonDeployment` resource which instructs Seldon Core to deploy a model embedded within our custom image and compliant with the [V2 Inference Protocol](https://github.com/kserve/kserve/tree/master/docs/predict-api/v2).
This can be achieved by _applying_ (i.e. `kubectl apply`) a `SeldonDeployment` manifest to the cluster, similar to the one below:

Expand Down

0 comments on commit b7dfe51

Please sign in to comment.