Debug jobs and monitor training progress

Machine learning model training is an iterative process that requires significant experimentation. By using the Azure Machine Learning interactive job experience, data scientists can use the Azure Machine Learning Python SDK, Azure Machine Learning CLI, or Azure Machine Learning studio to access the container where their job is running. Once users access the job container, they can iterate on training scripts, monitor training progress, and debug the job remotely, just as they typically do on their local machines. You can interact with jobs through different training applications, including JupyterLab, TensorBoard, VS Code, or by connecting to the job container directly via SSH.

Azure Machine Learning supports interactive training on Azure Machine Learning Compute Clusters and Azure Arc-enabled Kubernetes Cluster.

Prerequisites

  • Review getting started with training on Azure Machine Learning.
  • For more information, see VS Code to set up the Azure Machine Learning extension.
  • Make sure your job environment has the openssh-server and ipykernel ~=6.0 packages installed. All Azure Machine Learning curated training environments have these packages installed by default.
  • You can't enable interactive applications on distributed training runs where the distribution type is anything other than PyTorch, TensorFlow, or MPI. Custom distributed training setup (configuring multinode training without using the preceding distribution frameworks) isn't currently supported.
  • To use SSH, you need an SSH key pair. Use the ssh-keygen -f "<filepath>" command to generate a public and private key pair.
  • To attach a debugger to a running job, install debugpy in your job environment. See Attach a debugger to a job.

Interact with your job container

By specifying interactive applications at job creation, you can connect directly to the container on the compute node where your job is running. Once you have access to the job container, you can test or debug your job in the exact same environment where it runs. You can also use VS Code to attach to the running process and debug as you would locally.

Enable during job submission

  1. Create a new job from the left pane in the studio portal.

  2. Select Compute cluster or Attached compute (Kubernetes) as the compute type. Select the compute target, and specify how many nodes you need in Instance count.

Screenshot of selecting a compute location for a job.

  1. Follow the wizard to choose the environment you want to start the job.

  2. In the Training script step, add your training code (and input/output data) and reference it in your command to make sure it's mounted to your job.

Screenshot of reviewing a drafted job and completing the creation.

To specify the amount of time you want to reserve the compute resource, add sleep <specific time> at the end of your command. The format follows:

  • sleep 1s
  • sleep 1m
  • sleep 1h
  • sleep 1d

You can also use the sleep infinity command that keeps the job alive indefinitely.

Note

If you use sleep infinity, you must manually cancel the job to release the compute resource and stop billing.

  1. In Compute settings, expand the option for Training applications. Select at least one training application you want to use to interact with the job. If you don't select an application, the debug feature isn't available.

Screenshot of selecting a training application for the user to use for a job.

  1. Review and create the job.

Connect to endpoints

To interact with your running job, select Debug and monitor on the job details page.

Screenshot of interactive jobs debug and monitor panel location.

When you select the applications in the panel, you open a new tab for the applications. You can access the applications only when they're in Running status and only the job owner is authorized to access the applications. If you're training on multiple nodes, you can pick the specific node you want to interact with.

Screenshot of interactive jobs right panel information. Information content varies depending on the user's data.

It might take a few minutes to start the job and the training applications specified during job creation.

Interact with the applications

When you select the endpoints to interact with your job, you're taken to the user container under your working directory. You can access your code, inputs, outputs, and logs. If you run into any issues while connecting to the applications, you can find the interactive capability and applications logs in system_logs->interactive_capability under the Outputs + logs tab.

Screenshot of interactive jobs interactive logs panel location.

  • You can open a terminal from Jupyter Lab and start interacting within the job container. You can also directly iterate on your training script by using Jupyter Lab.

    Screenshot of interactive jobs Jupyter lab content panel.

  • You can also interact with the job container within VS Code. To attach a debugger to a job during job submission and pause execution, navigate here.

    Note

    Private link-enabled workspaces aren't currently supported when interacting with the job container by using VS Code.

    Screenshot of interactive jobs VS Code panel when first opened. This shows the sample python file that was created to print two lines.

  • If you log TensorFlow events for your job, you can use TensorBoard to monitor the metrics while your job is running.

    Screenshot of interactive jobs tensorboard panel when first opened. This information varies depending upon customer data

End job

When you're done with the interactive training, you can go to the job details page to cancel the job. Canceling the job releases the compute resource. Alternatively, use az ml job cancel --name <your job name> --resource-group <your resource group name> --workspace-name <your workspace name> in the CLI or ml_client.jobs.begin_cancel("<job name>") in the SDK.

Screenshot of interactive jobs cancel job option and its location for user selection

Attach a debugger to a job

To submit a job with a debugger attached and the execution paused, use debugpy and VS Code. You must install debugpy in your job environment.

Note

Private link-enabled workspaces aren't currently supported when attaching a debugger to a job in VS Code.

  1. During job submission (either through the UI, the CLI, or the SDK), use the debugpy command to run your Python script. For example, the following screenshot shows a sample command that uses debugpy to attach the debugger for a TensorFlow script (tfevents.py can be replaced with the name of your training script).

Screenshot of interactive jobs configuration of debugpy

  1. After you submit the job, connect to the VS Code and select the built-in debugger.

    Screenshot of interactive jobs location of open debugger on the left side panel

  2. Use the Remote Attach debug configuration to attach to the submitted job and pass in the path and port you configured in your job submission command. You can also find this information on the job details page.

    Screenshot of interactive jobs completed jobs

    Screenshot of interactive jobs add a remote attach button

  3. Set breakpoints and walk through your job execution as you would in your local debugging workflow.

    Screenshot of location of an example breakpoint that is set in the Visual Studio Code editor

Note

If you use debugpy to start your job, your job doesn't execute unless you attach the debugger in VS Code and execute the script. If you don't attach the debugger, the compute is reserved until the job is cancelled.

Next steps