You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"source": "### Exercise 4. Prepare training script\nNow you will need to create your training script. In this tutorial, the training script is already provided for you at `pytorch_train.py`. In practice, you should be able to take any custom training script as is and run it with AML without having to modify your code.\n\nHowever, if you would like to use AML's [tracking and metrics](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#metrics) capabilities, you will have to add a small amount of AML code inside your training script. \n\nIn `pytorch_train.py`, we will log some metrics to our AML run. To do so, we will access the AML run object within the script:\n```Python\nfrom azureml.core.run import Run\nrun = Run.get_context()\n```\nFurther within `pytorch_train.py`, we log the learning rate and momentum parameters, the best validation accuracy the model achieves, and the number of classes in the model:\n```Python\nrun.log('lr', np.float(learning_rate))\nrun.log('momentum', np.float(momentum))\nrun.log('num_classes', num_classes)\n\nrun.log('best_val_acc', np.float(best_acc))\n```\n\nIf you downloaded the data, you can start to train the model locally (note that it will take long if you don't have a GPU -- 21 min. on a Core i7 CPU).\n\n**This step requires Pytorch to be installed locally -- find instructions [here](https://pytorch.org/#pip-install-pytorch)**\n"
"source": "## Train model on the remote compute\nNow that you have your data and training script prepared, you are ready to train on your remote compute cluster. You can take advantage of Azure compute to leverage GPUs to cut down your training time. "
21
+
},
22
+
{
23
+
"metadata": {},
24
+
"cell_type": "markdown",
25
+
"source": "### Create an experiment\nCreate an [Experiment](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#experiment) to track all the runs in your workspace for this transfer learning PyTorch tutorial. "
"source": "### Create a PyTorch estimator\nThe AML SDK's PyTorch estimator enables you to easily submit PyTorch training jobs for both single-node and distributed runs. The following code will define a single-node PyTorch job.\n\nThe estimator also takes a `framework_version` parameter -- if no version is provided, the estimator will default to the latest version supported by AzureML. Use `PyTorch.get_supported_versions()` to get a list of all versions supported by your current SDK version or see the [SDK documentation](https://docs.microsoft.com/en-us/python/api/azureml-train-core/azureml.train.dnn?view=azure-ml-py) for the versions supported in the most current release. For more information on the PyTorch estimator, refer [here](https://docs.microsoft.com/azure/machine-learning/service/how-to-train-pytorch)."
"source": "The `script_params` parameter is a dictionary containing the command-line arguments to your training script `entry_script`. Please note the following:\n- We passed our training data reference `ds_data` to our script's `--data_dir` argument. This will 1) mount our datastore on the remote compute and 2) provide the path to the training data `breeds` on our datastore.\n- We specified the output directory as `./outputs`. The `outputs` directory is specially treated by AML in that all the content in this directory gets uploaded to your workspace as part of your run history. The files written to this directory are therefore accessible even once your remote run is over. In this tutorial, we will save our trained model to this output directory.\n\nThe `_use_framework_images` parameter is in private preview. When `_use_framework_images = True`, pre-built framework images are used to run AMLCompute jobs or as intermediate images to make constructing an estimator more efficient by either eliminating or greatly reducing image build time.\n\nTo leverage the Azure VM's GPU for training, we set `use_gpu=True`."
56
+
},
57
+
{
58
+
"metadata": {},
59
+
"cell_type": "markdown",
60
+
"source": "### Submit job\nRun your experiment by submitting your estimator object. Note that this call is asynchronous."
"source": "### Monitor your run\nYou can monitor the progress of the run with a Jupyter widget. Like the run submission, the widget is asynchronous and provides live updates every 10-15 seconds until the job completes."
"source": "### What happens during a run?\nIf you are running this for the first time, the compute target will need to pull the docker image, which will take about 2 minutes. This gives us the time to go over how a **Run** is executed in Azure Machine Learning. \n\nNote: had we not created the workspace with an existing ACR, we would have also had to wait for the image creation to be performed -- that takes and extra 10-20 minutes for big GPU images like this one. This is a one-time cost for a given python configuration, and subsequent runs will then be faster. We are working on ways to make this image creation faster.\n\n"
0 commit comments