Skip to content

Commit 84f3a5a

Browse files
authored
Add GPU Deployments section to score.rst
1 parent 85326a9 commit 84f3a5a

File tree

1 file changed

+37
-0
lines changed
  • docs/source/user_guide/model_registration/_template

1 file changed

+37
-0
lines changed

docs/source/user_guide/model_registration/_template/score.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,43 @@ Refer Cusotmization section for how to change and verify the model artifacts.
3434

3535
The ``score.py`` consists of multiple functions among which the ``load_model`` and ``predict`` are most important.
3636

37+
GPU Deployments
38+
~~~~~~~~~~~~~~~~
39+
When deploying your TensorFlow or PyTorch models onto a GPU shape, the ADS generated score.py manages GPU integration for you. It will automatically transfer your data to the GPU (or multiple GPUs) and perform the inference on that GPU. When using ADS 2.8.4 or later, any TensorFlow or PyTorch model artifact can be deployed efficiently on either CPU or GPU regardless of how it was trained.
40+
41+
The Model Deployment Service handles parallelization for you. Whether you have a single or multi GPU deployment, the Model Deployment Service will determine how many replicas of your model can be supported, and the auto-generated score.py will randomly assign those replicas across the GPU(s). The following code example registers a PyTorch Model tuned and deployed on GPUs.
42+
43+
.. code-block:: python3
44+
45+
import torch
46+
import torchvision
47+
from ads.common.model_metadata import UseCaseType
48+
from ads.model.framework.pytorch_model import PyTorchModel
49+
50+
model = torchvision.models.resnet18(pretrained=True)
51+
model.to("cuda:0")
52+
53+
# Tune your model
54+
fake_input = torch.Tensor(np.zeros((1, 3, 224, 224))).to("cuda:0")
55+
model.forward(fake_input)
56+
57+
# Prepare and Register your model
58+
model.eval()
59+
pytorch_model = PyTorchModel("pytorch_model_artifact", artifact_dir=artifact_dir)
60+
pytorch_model.prepare(
61+
inference_conda_env="pytorch110_p38_gpu_v1",
62+
training_conda_env="pytorch110_p38_gpu_v1",
63+
use_case_type=UseCaseType.IMAGE_CLASSIFICATION,
64+
force_overwrite=True,
65+
use_torch_script=True,
66+
)
67+
pytorch_model.save()
68+
pytorch_model.deploy(deployment_instance_shape="VM.GPU3.2")
69+
70+
pytorch_model.predict(fake_input.to_numpy())
71+
72+
`Learn more about the Model Deployment Service here. <https://docs.oracle.com/en-us/iaas/data-science/using/model_dep_create.htm>`_
73+
3774
load_model
3875
~~~~~~~~~~
3976

0 commit comments

Comments
 (0)