From e081f72e1481548d07f72424c5e724d079ac65a3 Mon Sep 17 00:00:00 2001 From: Cengguang Zhang Date: Tue, 23 Aug 2022 10:02:27 +0800 Subject: [PATCH 1/7] feat: add save and load model doc to pytorch estimator quickstart. --- .../QuickStart/orca-pytorch-quickstart.md | 14 +++++++++ .../QuickStart/orca-tf2keras-quickstart.md | 8 ++--- .../quickstart/pytorch_lenet_mnist.ipynb | 30 +++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md b/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md index 73bad54af7f..3081f84cf2c 100644 --- a/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md +++ b/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md @@ -132,4 +132,18 @@ for r in result: print(r, ":", result[r]) ``` +### **Step 5: Save and Load the Model ** + +Save the Estimator state (including model and optimizer) to the provided model path. + +```python +est.save("mnist_model") +``` + +Load the Estimator state (model and possibly with optimizer) from provided model path. + +```python +est.load("mnist_model") +``` + **Note:** You should call `stop_orca_context()` when your application finishes. diff --git a/docs/readthedocs/source/doc/Orca/QuickStart/orca-tf2keras-quickstart.md b/docs/readthedocs/source/doc/Orca/QuickStart/orca-tf2keras-quickstart.md index c460ef674d4..c1fd8f136fa 100644 --- a/docs/readthedocs/source/doc/Orca/QuickStart/orca-tf2keras-quickstart.md +++ b/docs/readthedocs/source/doc/Orca/QuickStart/orca-tf2keras-quickstart.md @@ -130,20 +130,20 @@ You could also save the model to Keras H5 format by passingĀ `save_format='h5'` ```python # save model in SavedModel format -estimator.save("/tmp/cifar10_model") +est.save("/tmp/cifar10_model") # load model -estimator.load("/tmp/cifar10_model") +est.load("/tmp/cifar10_model") ``` **2. HDF5 format** ```python # save model in H5 format -estimator.save("/tmp/cifar10_model.h5", save_format='h5') +est.save("/tmp/cifar10_model.h5", save_format='h5') # load model -estimator.load("/tmp/cifar10_model.h5") +est.load("/tmp/cifar10_model.h5") ``` That's it, the same code can run seamlessly in your local laptop and to distribute K8s or Hadoop cluster. diff --git a/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb b/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb index 0b6b1a733cb..dd47b12c482 100644 --- a/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb +++ b/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb @@ -465,6 +465,36 @@ "The accuracy of this model has reached 98%." ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "qhLhJ4vWc-95" + }, + "source": [ + "### **Step 5: Save the Model**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DmmtHcPodLA3" + }, + "source": [ + "Save the Estimator state (including model and optimizer) to the provided model path.\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "WUbsriiBdprT" + }, + "source": [ + "est.save(\"mnist_model\")" + ], + "execution_count": null, + "outputs": [] + }, { "cell_type": "code", "metadata": { From b716ed6ac2f3333c045a2f7478aaf65cf2e4444d Mon Sep 17 00:00:00 2001 From: Cengguang Zhang Date: Tue, 23 Aug 2022 10:34:26 +0800 Subject: [PATCH 2/7] fix: fix typo. --- .../source/doc/Orca/QuickStart/orca-pytorch-quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md b/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md index 3081f84cf2c..4a5048ffecb 100644 --- a/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md +++ b/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md @@ -140,7 +140,7 @@ Save the Estimator state (including model and optimizer) to the provided model p est.save("mnist_model") ``` -Load the Estimator state (model and possibly with optimizer) from provided model path. +Load the Estimator state (model and possibly with optimizer) from the provided model path. ```python est.load("mnist_model") From b73f4b72c5534faec56ee5b5b81e18e5e16ea6c8 Mon Sep 17 00:00:00 2001 From: Cengguang Zhang Date: Tue, 23 Aug 2022 11:47:47 +0800 Subject: [PATCH 3/7] fix: fix typo --- .../source/doc/Orca/QuickStart/orca-pytorch-quickstart.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md b/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md index 4a5048ffecb..0bfce47e7de 100644 --- a/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md +++ b/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-quickstart.md @@ -132,15 +132,15 @@ for r in result: print(r, ":", result[r]) ``` -### **Step 5: Save and Load the Model ** +### **Step 5: Save and Load the Model** -Save the Estimator state (including model and optimizer) to the provided model path. +Save the Estimator states (including model and optimizer) to the provided model path. ```python est.save("mnist_model") ``` -Load the Estimator state (model and possibly with optimizer) from the provided model path. +Load the Estimator states (model and possibly with optimizer) from the provided model path. ```python est.load("mnist_model") From 2f64c2289ff29f7b33f90ed86a2f796158a9d6d0 Mon Sep 17 00:00:00 2001 From: Cengguang Zhang Date: Tue, 23 Aug 2022 11:48:55 +0800 Subject: [PATCH 4/7] fix: fix typo. --- python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb b/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb index dd47b12c482..3cdbc9bdada 100644 --- a/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb +++ b/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb @@ -480,7 +480,7 @@ "id": "DmmtHcPodLA3" }, "source": [ - "Save the Estimator state (including model and optimizer) to the provided model path.\n", + "Save the Estimator states (including model and optimizer) to the provided model path.\n", "\n" ] }, From 07438e62feec6c68f57a5382a44624fd20cbf472 Mon Sep 17 00:00:00 2001 From: Cengguang Zhang Date: Tue, 23 Aug 2022 13:20:29 +0800 Subject: [PATCH 5/7] feat: add doc to ray backend quickstart --- .../pytorch_distributed_lenet_mnist.ipynb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/python/orca/colab-notebook/quickstart/pytorch_distributed_lenet_mnist.ipynb b/python/orca/colab-notebook/quickstart/pytorch_distributed_lenet_mnist.ipynb index b68df39197a..8a2db378e82 100644 --- a/python/orca/colab-notebook/quickstart/pytorch_distributed_lenet_mnist.ipynb +++ b/python/orca/colab-notebook/quickstart/pytorch_distributed_lenet_mnist.ipynb @@ -426,6 +426,35 @@ "The accuracy of this model has reached 98%." ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "uL9QMvCRLjae" + }, + "source": [ + "### **Step 5: Save the model**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "icshLUG2LlR6" + }, + "source": [ + "Save the Estimator states (including model and optimizer) to the provided model path." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "sQjoelcfL-Mv" + }, + "outputs": [], + "source": [ + "est.save(\"mnist_model\")" + ] + }, { "cell_type": "code", "execution_count": null, From 046956c0cb95ca27e1ee2ed5f369ee9b929374db Mon Sep 17 00:00:00 2001 From: Cengguang Zhang Date: Tue, 23 Aug 2022 13:36:31 +0800 Subject: [PATCH 6/7] fix: fix typo. --- .../orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb b/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb index 3cdbc9bdada..350fc05c6f4 100644 --- a/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb +++ b/python/orca/colab-notebook/quickstart/pytorch_lenet_mnist.ipynb @@ -480,8 +480,7 @@ "id": "DmmtHcPodLA3" }, "source": [ - "Save the Estimator states (including model and optimizer) to the provided model path.\n", - "\n" + "Save the Estimator states (including model and optimizer) to the provided model path." ] }, { From e7f9b453cb47ad55c4b524c11b8fd9336a8a8a0c Mon Sep 17 00:00:00 2001 From: Cengguang Zhang Date: Tue, 23 Aug 2022 13:22:04 +0800 Subject: [PATCH 7/7] feat: add doc to ray backend quickstart --- .../orca-pytorch-distributed-quickstart.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-distributed-quickstart.md b/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-distributed-quickstart.md index 2dbf38d2fc6..3a20bfebbbe 100644 --- a/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-distributed-quickstart.md +++ b/docs/readthedocs/source/doc/Orca/QuickStart/orca-pytorch-distributed-quickstart.md @@ -130,4 +130,18 @@ for r in result: print(r, ":", result[r]) ``` +### **Step 5: Save and Load the Model** + +Save the Estimator states (including model and optimizer) to the provided model path. + +```python +est.save("mnist_model") +``` + +Load the Estimator states (model and possibly with optimizer) from provided model path. + +```python +est.load("mnist_model") +``` + **Note:** You should call `stop_orca_context()` when your application finishes.