Skip to content

Commit d60e775

Browse files
authored
Merge branch 'develop' into update_unit_tests
2 parents e051d63 + a46118a commit d60e775

File tree

2 files changed

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

2 files changed

+37
-1
lines changed

ads/ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export OCI_PYTHON_SDK_NO_SERVICE_IMPORTS=1
2-
python -m ads.cli "$@"
2+
python3 -m ads.cli "$@"

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,42 @@ 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 based on the size of your model artifact and the size of your GPU shape. Finally, 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. `Learn more about the Model Deployment Service here. <https://docs.oracle.com/en-us/iaas/data-science/using/model_dep_create.htm>`_
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+
3773
load_model
3874
~~~~~~~~~~
3975

0 commit comments

Comments
 (0)