CloudBrum
CloudBrum · Cloud decision-support platform
Azure AI and machine learning

Azure Machine LearningLast reviewedReading time~12 minLevelBeginner to advanced

Microsoft Azure · AI and machine learning · Model training and hosting

A workspace where machine learning work gets organised. In Azure ML you create a workspace, attach or rent compute, run training as jobs, register the result as a model and publish it on an endpoint. The service itself isn’t the expensive part. What you pay for is the compute underneath: clusters that scale to zero when idle, a compute instance you forgot to stop, and the endpoint’s virtual machines.

On this page (17 sections)

    Mind map: Azure Machine Learning at a glance

    Azure Machine Learning mind map Azure Machine Learning at a glance: Workspace: Studio portal, Storage, Key Vault, ACR, Roles and identities; Compute: Compute instance, Cluster (scale to zero), Serverless compute; Jobs: Command and sweep, Pipelines, Automated ML; Data & assets: Datastores, Data assets, MLTable, Environments; Deploy: Managed online endpoint, Batch endpoint, Blue-green traffic split; MLOps: MLflow tracking, Model registry, Registries across teams; Responsible AI: Explanations, Error analysis, Fairness checks; Pricing: Pay for compute, Endpoints bill while up, Reservations, spot. Azure Machine Learning at a glance Workspaces, compute, jobs and endpoints on Azure: the main building blocks and decisions CloudBrum Cloud decision-support platform CloudBrum Studio portal Storage, Key Vault, ACR Roles and identities Workspace Compute instance Cluster (scale to zero) Serverless compute Compute Command and sweep Pipelines Automated ML Jobs Datastores Data assets, MLTable Environments Data & assets Managed online endpoint Batch endpoint Blue-green traffic split Deploy MLflow tracking Model registry Registries across teams MLOps Explanations Error analysis Fairness checks Responsible AI Pay for compute Endpoints bill while up Reservations, spot Pricing Azure ML17-point analysis CloudBrum· 17-point cloud service analysis cloudbrum.com
    CloudBrum Azure ML at a glance · 17-point analysis Workspace Studio portal Storage, Key Vault, ACR Roles and identities Compute Compute instance Cluster (scale to zero) Serverless compute Jobs Command and sweep Pipelines Automated ML Data & assets Datastores Data assets, MLTable Environments Deploy Managed online endpoint Batch endpoint Blue-green traffic split MLOps MLflow tracking Model registry Registries across teams Responsible AI Explanations Error analysis Fairness checks Pricing Pay for compute Endpoints bill while up Reservations, spot CloudBrum · cloudbrum.com

    Free to share. The downloaded image includes the CloudBrum link.

    Key features (summary)

    • A workspace for everythingOne resource holds your experiments, jobs, models, endpoints and settings, next to a storage account, a key vault, a container registry and Application Insights. Teams usually get one per project or environment.
    • Three kinds of computeA compute instance is your personal dev machine. A compute cluster is a pool that grows with the queue and shrinks to nothing. Serverless compute lets a job ask for machines without you creating a cluster first.
    • Jobs you can repeatA command job runs a script in an environment on some compute. Sweep jobs tune hyperparameters, pipeline jobs chain steps, and every run is tracked with its code, inputs, metrics and outputs.
    • Automated MLGive it a table, a target column and a time limit, and it tries algorithms and settings, then ranks the models. Handy for a first baseline.
    • Managed endpointsA managed online endpoint hosts a model on VMs that Azure patches and scales. Several deployments can sit behind one endpoint with a traffic split, which is how blue-green rollouts work. Batch endpoints score files in bulk.
    • MLflow built inThe workspace speaks MLflow for tracking and the model registry, so code written for open source MLflow works with little change, and MLflow models deploy without a scoring script.
    • Registries for sharingA registry lets several workspaces share models, environments and components, so a model trained in dev can be promoted to prod without copying files by hand.
    • Responsible AI toolsDashboards for model explanations, error analysis, fairness and counterfactuals help you look at a model before people rely on it.

    Basic concepts

    Workspace
    The top-level resource for a project. It stores run history and assets, and it points at its storage account, key vault, container registry and Application Insights.
    Compute instance
    A single cloud workstation for one person, with Jupyter, VS Code and a terminal. It bills while it’s running.
    Compute cluster
    A set of identical VMs that scales between a minimum and a maximum node count. With a minimum of zero it costs nothing when idle.
    Serverless compute
    On-demand compute chosen per job. You state the VM size and count in the job, and Azure ML creates and removes the machines.
    Job
    One tracked run of code: a command, a sweep, a pipeline or an AutoML task. Its inputs, outputs, logs and metrics are saved.
    Environment
    The software a job or deployment runs in: a base image plus a conda or pip file. Curated environments come ready-made.
    Datastore and data asset
    A datastore is a saved connection to storage such as Blob or Data Lake. A data asset is a named, versioned pointer to files or a table.
    Model
    A registered, versioned artifact. MLflow-format models carry their own signature and dependencies.
    Managed online endpoint
    A stable HTTPS URL for real-time scoring. Behind it sit one or more deployments, each with its own VM size, count and model.
    Deployment
    One version of a model running on a set of VMs inside an endpoint, commonly named blue and green.
    Batch endpoint
    An endpoint that starts a job to score a folder or table asynchronously, on a cluster, and writes the results to storage.
    Component
    A reusable pipeline step with declared inputs, outputs and an environment, which can be shared through a registry.
    Registry
    A shared catalogue, separate from any workspace, that holds models, components and environments for many workspaces to use.
    MLflow
    An open source tracking and model format. Azure ML workspaces work as MLflow tracking servers.

    How to create & configure it

    Create a workspace, a cluster and your first endpoint in the Azure portal

    1. Check the Region and quotaPick a Region close to your data (Central India for many Indian teams). In Quotas, look at the VM family you want. GPU families often need a request, and low-priority quota is separate from dedicated quota.
    2. Create the workspaceSearch for Azure Machine Learning, choose Create, then a resource group, a name and a Region. Let it create the storage account, key vault, Application Insights and container registry, or point it at existing ones. You can’t swap them later.
    3. Open the studioLaunch the studio from the workspace page. It’s a separate web app where you’ll see jobs, models, endpoints and compute.
    4. Create a compute clusterUnder Compute, make a cluster with a small CPU size, minimum nodes 0, maximum 2 and a short idle time before scale down (the default is 120 seconds). The minimum of zero is what keeps the bill at nothing between runs.
    5. Add your dataUpload a CSV to the workspace’s default blob store, then register it as a data asset so jobs refer to it by name and version.
    6. Run a jobCreate a command job: your script, an environment, the data asset as an input, the cluster as compute. Watch the logs and metrics as it runs. Have the script log the model with MLflow.
    7. Register the modelFrom the finished job, choose Register model and keep the MLflow format. The model gets a name and a version number.
    8. Deploy to an online endpointCreate a managed online endpoint, add a deployment with a VM size and instance count, and send all traffic to it. Because the model is MLflow, no scoring script or environment is needed.
    9. Test, watch and set limitsUse the Test tab with a sample row, open the endpoint’s metrics, set up autoscale, and add a budget alert. Delete the endpoint when you’re done experimenting.

    Tip: the portal is fine for a first look. For real work, define the same objects in YAML for the az ml command or in code with the Python SDK (see the code references), so a teammate can recreate your setup from a file.

    Common issues after configuration

    SymptomLikely causeWhat to check / fix
    A job sits in Queued or Preparing for a long timeNot enough quota or capacity for that VM size, or the cluster is still creating nodesCheck the cluster’s allocation state and the quota for that VM family in the Region. Try another size or Region, or use serverless compute with a different SKU.
    The cluster never scales to zeroThe minimum node count isn’t zero, or something keeps a job activeSet minimum nodes to 0 and check the idle-time-before-scale-down setting. A stuck or queued job keeps nodes alive, so cancel it.
    Environment build failsA package version conflict, a bad conda file or a base image that can’t be pulledRead the build log in the job’s Outputs and logs tab. Pin versions, test the conda file locally, and prefer a curated environment as a starting point.
    Deployment fails or the endpoint shows UnhealthyThe container crashed, the scoring script threw an error at start-up, or the model didn’t loadRun az ml online-deployment get-logs for the deployment and read the container log. Test the scoring script locally before you push it.
    401 or 403 when you call the endpointThe wrong key or token, or the caller lacks permissionFetch the current key with az ml online-endpoint get-credentials, send it as a Bearer token, or switch to Microsoft Entra token authentication and assign the right role.
    A 424 or a model error in the responseThe request body doesn’t match what the model expectsFor MLflow models the body is {"input_data": {...}} with the columns the model was trained on. Compare it with the model’s signature.
    The deployment is stuck waiting for quotaEndpoint VMs count against your VM quota, and rolling updates need spare capacityRequest more quota, or reduce instance count during the update. Blue-green needs room for both deployments at once.
    Cannot reach storage from a job in a private networkMissing private endpoints, or a datastore using a key the workspace can’t readAdd private endpoints for the storage account, or use the workspace’s managed virtual network, and give the workspace identity access to the data.
    Everything worked in v1 and now it doesn’tSDK v1 and CLI v1 code is retired or retiring and the objects changedMove to the v2 CLI and the azure-ai-ml SDK. The names are different (command jobs instead of ScriptRunConfig, online endpoints instead of web services).
    The bill is high with no jobs runningA compute instance left on, or an endpoint with instances runningList compute instances and endpoints, set idle shutdown on instances, and delete test endpoints. Use Cost Analysis filtered by the workspace’s resource group.
    Run history and assets vanished after deleting a resourceThe workspace’s linked storage or key vault was deletedTreat the associated resources as part of the workspace. Put a delete lock on them, and turn on soft delete for the key vault and storage.

    Use cases: when and where to use it

    Good fit

    • Teams that need tracked, repeatable training runs and a clear path to a hosted model
    • Elastic training capacity that disappears when the queue is empty
    • Putting a scikit-learn, PyTorch or MLflow model behind a secured endpoint with a safe rollout
    • Organisations already on Azure that want Entra ID, private networking and Azure Policy around their ML work
    • A shared model registry across dev, test and prod workspaces
    • Scoring big files on a schedule with batch endpoints

    Consider something else

    • Building apps on hosted language models and agents → Microsoft Foundry and Azure OpenAI, not a training workspace
    • Prebuilt vision, speech and language services with nothing to train → the Azure AI services
    • Data engineering at scale before the features exist → Azure Synapse, Fabric or Databricks
    • A model small enough to run in a function → Azure Functions, without an endpoint of its own
    • The same job on other clouds → compare Amazon SageMaker and Gemini Enterprise Agent Platform (Vertex AI)

    Pros: why consider it?

    Why teams choose it

    • No separate fee for the service itself: you pay for the compute and the resources beside it
    • Clusters that scale to zero and serverless jobs keep idle cost low
    • MLflow support means little lock-in on tracking and model format
    • Safe rollouts through multiple deployments behind one endpoint and a traffic split
    • Strong fit with Entra ID, Azure Policy, private endpoints and managed identities
    • Registries make promotion between environments a first-class thing

    Trade-offs to weigh

    • Naming and portals have shifted (studio, Foundry, hubs and projects), so tutorials from different years disagree
    • A managed online endpoint keeps at least one VM running, so it’s not pay-per-request
    • The workspace’s four linked resources can’t be changed afterwards
    • Quota per VM family and Region trips up new subscriptions
    • Version 1 of the SDK and CLI is gone or going, and older samples don’t match
    • Private networking setups are fiddly and take a few tries

    Common threats, vulnerabilities & risks

    RiskSeverityWhy it mattersMitigation
    A compute instance or endpoint left runningHighVMs bill by the hour whether they’re busy or not, and GPUs add up fast.Idle shutdown on instances, schedules, budgets and alerts, and an owner tag on everything.
    Workspace storage and key vault exposedHighThey hold data, run outputs and secrets, and are easy to leave open to the internet.Disable public access, use private endpoints, and give access through managed identities rather than keys.
    Over-broad rolesHighContributor on the workspace lets someone run arbitrary code on your compute and read its data.Use the built-in data scientist and compute operator roles, separate dev from prod, and review assignments.
    Endpoint keys shared or leakedMediumA key is a bearer secret, and rotating it breaks callers that copied it.Prefer Entra token authentication, store keys in Key Vault and rotate on a schedule.
    Model changes without reviewMediumA model registered from a laptop can reach production quickly if nothing checks it.Gate deployments behind a pipeline, require a reviewed version in the registry and keep the job ID with each model.
    Silent model driftMediumReal-world inputs change, and the endpoint keeps answering.Collect inference data, monitor drift and quality, and alert when they move.
    Unvetted packages in environmentsMediumConda and pip pull whatever is current, including broken or malicious releases.Freeze versions, build in a pipeline, and scan the images that end up in the registry.
    Unfair or opaque predictionsLow–MedA model can disadvantage a group without anyone intending it.Run the Responsible AI dashboard before release, and keep the findings with the model.
    Data leaving the regionLow–MedTraining in a convenient Region can break data residency rules.Pick the Region deliberately, use Azure Policy to restrict locations, and note it in the design.

    Performance optimisation

    • Match the VM size to the job. Try a CPU size for tree models, and use GPU sizes only when the framework really uses them.
    • Keep data in the same Region as compute, and use a mounted or direct-read input mode for large files rather than copying them into every job.
    • Set the cluster’s minimum nodes above zero only when start-up delay hurts, for example during working hours, because zero is the cheap setting.
    • Use distributed training (PyTorch distributed, MPI) with multi-node clusters for large models, with a fast interconnect on the VM sizes that offer one.
    • Use sweep jobs with early termination so poor hyperparameter trials stop early.
    • Scale endpoints with autoscale rules on CPU, memory or request count, and test the rules under load before launch.
    • Pick batch endpoints for large scoring jobs: they split work across cluster nodes with settings for mini-batch size and parallelism.
    • Reduce model size with quantisation or ONNX export to cut latency and VM size.

    Reduce monthly cost

    FinOps is the habit of managing cloud spend together with engineering. These are the FinOps checks that matter most for Azure Machine Learning.

    • Set cluster minimum nodes to 0, and keep idle time before scale down short (the default is 120 seconds) for experimental work.
    • Use low-priority or spot VMs for training that can restart, and write checkpoints so interruptions are cheap.
    • Turn on idle shutdown and schedules for compute instances, and stop them at the end of the day.
    • Prefer serverless compute for occasional jobs, so no cluster has to exist.
    • Delete test online endpoints the same day. Endpoint VMs bill all the time, and an endpoint needs at least one running.
    • Use batch endpoints for scheduled scoring rather than an always-on endpoint.
    • Look at Azure Reservations or savings plans for steady baseline VM use once the pattern is clear.
    • Right-size by watching CPU, GPU and memory metrics, and move to a smaller VM when utilisation is low.
    • Use tags on workspaces, compute and endpoints (managed online endpoints need tags to show up properly in cost views), and set budgets.
    • Remember the neighbours: storage, container registry, Key Vault, Application Insights and network egress all bill separately.

    Prices and offers here are examples drawn from Microsoft's public pages. VM size, Region and time all change them, so check the live figures first (see Pricing).

    Security optimisation

    • Use managed identities for the workspace, compute and endpoints, and avoid account keys and connection strings in code.
    • Give people the least role they need: the built-in AzureML Data Scientist and Compute Operator roles cover most work without full contributor rights.
    • Put the workspace behind private endpoints or the managed virtual network, and turn public network access off where you can.
    • Use customer-managed keys where policy requires them, and turn on soft delete and purge protection for the key vault.
    • Authenticate endpoint callers with Microsoft Entra tokens where possible, and keep endpoint keys in Key Vault.
    • Restrict outbound traffic from training and deployment with the managed network’s outbound rules.
    • Build custom environments in a pipeline from frozen package versions, and scan what lands in the container registry.
    • Use Azure Policy to enforce private networking, approved regions, tags and customer-managed keys.
    • Send diagnostic logs and the activity log to Log Analytics and review who created compute and endpoints.
    • Run the Responsible AI dashboard before release and keep its output with the registered model.

    Governance & compliance

    Guardrails

    • Policy that denies workspaces and endpoints with public network access, and requires tags (owner, project, data class, cost centre)
    • Approved VM sizes and Regions, with anything else raised as an exception
    • A template pipeline that every team starts from, so training, evaluation, registration and release follow one route
    • A rule that only the pipeline’s identity can create production deployments

    Continuous checks (Azure Policy and Defender for Cloud)

    • “Azure Machine Learning workspaces should disable public network access”
    • “Azure Machine Learning workspaces should use private link”
    • “Azure Machine Learning computes should be in a virtual network”
    • “Azure Machine Learning compute instances should be recreated to get the latest software updates”
    • A custom rule for compute instances that have run longer than a set time

    Use the Activity log and Azure Monitor to see who created or changed compute and endpoints, Azure Policy for the rules above, Microsoft Defender for Cloud for posture checks, and Microsoft Purview for data catalogue and lineage. The Service Trust Portal has compliance reports. Responsibility is split: Microsoft runs the platform, and you are accountable for the data, what the model does, who has access and how changes are approved.

    Reduce carbon footprint

    • Train less often. Retrain when the data has moved, not on a calendar habit.
    • Begin with a small model or AutoML baseline. If a simple model is good enough, a large one only adds energy use.
    • Let clusters scale to zero and stop compute instances, so no VM sits idle.
    • Use spot or low-priority nodes, which use capacity that would otherwise sit unused.
    • Choose a Region with a cleaner grid for training that no one is waiting on, within your data rules.
    • Shrink a model (quantise it or distil it) before you deploy, so each prediction runs on a smaller VM.
    • The Microsoft Emissions Impact Dashboard gives account-level estimates. See what it covers for Azure ML before you quote a number from it.

    Pricing

    Purchase options

    The service No separate fee

    Microsoft doesn’t charge for Azure Machine Learning itself. You pay for the compute and the resources it uses.

    Compute instances and clusters Per VM-hour

    Billed by VM size for the time nodes are running. Clusters at zero nodes cost nothing for compute. Low-priority and spot VMs are cheaper and can be taken back.

    Online endpoints Per VM-hour

    A managed online endpoint bills for the VMs behind every deployment while it exists, plus networking, whether or not requests arrive.

    Everything alongside Separate meters

    Storage, container registry, Key Vault, Application Insights and data transfer are billed as their own Azure services.

    What you actually pay for

    • Virtual machine time for compute instances, clusters, serverless jobs and endpoint deployments, by size and hour
    • Storage for data, run outputs, models and logs
    • Container Registry for the images your environments and deployments build
    • Application Insights, Key Vault and network traffic (egress, private endpoints)
    • Optional extras: reservations, GPU sizes, managed network egress, and hosted model usage billed separately

    Prices vary by Region and VM size and change over time. Check the official Azure Machine Learning pricing page and the Azure pricing calculator for current figures, and read the Azure free account page for credits that new accounts get.

    Important code references

    This example trains a churn model from a CSV, registers it and publishes it on a managed online endpoint. The Azure CLI and Python tabs do each step (the model is logged with MLflow, so the deployment needs no scoring script). The Terraform tab builds the workspace and a cluster that scales to zero, and the C# tab calls the finished endpoint. Names, the subscription and the data path are examples. Remember to delete the endpoint afterwards, since billing continues while it exists.

    # Needs the ml extension:  az extension add -n ml
    # Names are examples; the resource group and workspace must exist (see the Terraform tab)
    az configure --defaults group=rg-ml workspace=mlw-churn
    
    # A cluster that costs nothing while idle
    az ml compute create --name cpu-cluster --type amlcompute --size Standard_DS3_v2 \
      --min-instances 0 --max-instances 2 --idle-time-before-scale-down 120
    
    # conda.yml lists python, pip, mlflow, scikit-learn and pandas; job.yml runs src/train.py on the cluster,
    # and the script logs the model with MLflow
    cat > job.yml <<'EOF'
    $schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
    display_name: churn-train
    experiment_name: churn
    code: ./src
    command: python train.py --data ${{inputs.churn}}
    inputs:
      churn:
        type: uri_file
        path: azureml://datastores/workspaceblobstore/paths/churn/train.csv
    environment:
      image: mcr.microsoft.com/azureml/openmpi4.1.2-ubuntu20.04:latest
      conda_file: ./conda.yml
    compute: azureml:cpu-cluster
    EOF
    
    JOB=$(az ml job create -f job.yml --query name -o tsv)
    az ml job stream --name $JOB
    
    # Register the MLflow model the job produced
    az ml model create --name churn-model --type mlflow_model \
      --path azureml://jobs/$JOB/outputs/artifacts/paths/model/
    
    # An endpoint with one deployment ("blue"); an MLflow model needs no scoring script
    cat > endpoint.yml <<'EOF'
    $schema: https://azuremlschemas.azureedge.net/latest/managedOnlineEndpoint.schema.json
    name: churn-ep
    auth_mode: key
    EOF
    
    cat > blue.yml <<'EOF'
    $schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json
    name: blue
    endpoint_name: churn-ep
    model: azureml:churn-model@latest
    instance_type: Standard_DS3_v2
    instance_count: 1
    EOF
    
    az ml online-endpoint create -f endpoint.yml
    az ml online-deployment create -f blue.yml --all-traffic
    
    # Score one customer
    echo '{"input_data": {"columns": ["tenure","support_calls","monthly_charge","contract"], "data": [[34, 2, 79.5, 1]]}}' > sample.json
    az ml online-endpoint invoke --name churn-ep --request-file sample.json
    
    # Stop the meter
    az ml online-endpoint delete --name churn-ep --yes --no-wait
    # Workspace and a cluster that scales to zero. Assumes azurerm provider version 3 or later.
    # Managed online endpoints are created with the CLI or SDK tabs (or the azapi provider).
    provider "azurerm" {
      features {}
    }
    
    variable "location" { default = "centralindia" }
    
    data "azurerm_client_config" "current" {}
    
    resource "azurerm_resource_group" "ml" {
      name     = "rg-ml"
      location = var.location
    }
    
    resource "azurerm_storage_account" "ml" {
      name                     = "stmlchurn001"        # 3-24 lowercase letters and digits, unique in Azure
      location                 = azurerm_resource_group.ml.location
      resource_group_name      = azurerm_resource_group.ml.name
      account_tier             = "Standard"
      account_replication_type = "LRS"
    }
    
    resource "azurerm_key_vault" "ml" {
      name                = "kv-mlchurn-001"
      location            = azurerm_resource_group.ml.location
      resource_group_name = azurerm_resource_group.ml.name
      tenant_id           = data.azurerm_client_config.current.tenant_id
      sku_name            = "standard"
      purge_protection_enabled = true
    }
    
    resource "azurerm_application_insights" "ml" {
      name                = "appi-mlchurn"
      location            = azurerm_resource_group.ml.location
      resource_group_name = azurerm_resource_group.ml.name
      application_type    = "web"
    }
    
    resource "azurerm_machine_learning_workspace" "ml" {
      name                    = "mlw-churn"
      location                = azurerm_resource_group.ml.location
      resource_group_name     = azurerm_resource_group.ml.name
      application_insights_id = azurerm_application_insights.ml.id
      key_vault_id            = azurerm_key_vault.ml.id
      storage_account_id      = azurerm_storage_account.ml.id
    
      identity {
        type = "SystemAssigned"
      }
    }
    
    resource "azurerm_machine_learning_compute_cluster" "cpu" {
      name                          = "cpu-cluster"
      location                      = azurerm_resource_group.ml.location
      machine_learning_workspace_id = azurerm_machine_learning_workspace.ml.id
      vm_priority                   = "Dedicated"        # "LowPriority" for interruptible, cheaper nodes
      vm_size                       = "Standard_DS3_v2"
    
      scale_settings {
        min_node_count                       = 0
        max_node_count                       = 2
        scale_down_nodes_after_idle_duration = "PT2M"    # two minutes, ISO 8601 duration
      }
    
      identity {
        type = "SystemAssigned"
      }
    }
    # pip install azure-ai-ml azure-identity
    # conda.yml (next to this file) lists python, pip, mlflow, scikit-learn and pandas for the training environment
    # ---- run.py: submit the job, register the model, deploy and test ----
    from azure.ai.ml import MLClient, Input, command
    from azure.ai.ml.constants import AssetTypes
    from azure.ai.ml.entities import (AmlCompute, Environment, ManagedOnlineDeployment,
                                      ManagedOnlineEndpoint, Model)
    from azure.identity import DefaultAzureCredential
    
    ml = MLClient(DefaultAzureCredential(), "<subscription-id>", "rg-ml", "mlw-churn")
    
    # A cluster that scales to zero when idle
    ml.compute.begin_create_or_update(AmlCompute(
        name="cpu-cluster", size="Standard_DS3_v2",
        min_instances=0, max_instances=2, idle_time_before_scale_down=120,
    )).result()
    
    job = command(
        code="./src",
        command="python train.py --data ${{inputs.churn}}",
        inputs={"churn": Input(type=AssetTypes.URI_FILE,
                               path="azureml://datastores/workspaceblobstore/paths/churn/train.csv")},
        environment=Environment(image="mcr.microsoft.com/azureml/openmpi4.1.2-ubuntu20.04:latest",
                                conda_file="./conda.yml"),
        compute="cpu-cluster",
        display_name="churn-train",
        experiment_name="churn",
    )
    run = ml.jobs.create_or_update(job)
    ml.jobs.stream(run.name)
    
    # Register the MLflow model the job logged
    model = ml.models.create_or_update(Model(
        name="churn-model", type=AssetTypes.MLFLOW_MODEL,
        path=f"azureml://jobs/{run.name}/outputs/artifacts/paths/model/",
    ))
    
    # One endpoint, one deployment called "blue", all traffic to it
    endpoint = ManagedOnlineEndpoint(name="churn-ep", auth_mode="key")
    ml.online_endpoints.begin_create_or_update(endpoint).result()
    ml.online_deployments.begin_create_or_update(ManagedOnlineDeployment(
        name="blue", endpoint_name="churn-ep", model=model,
        instance_type="Standard_DS3_v2", instance_count=1,
    )).result()
    endpoint.traffic = {"blue": 100}
    ml.online_endpoints.begin_create_or_update(endpoint).result()
    
    # sample.json: {"input_data": {"columns": [...], "data": [[34, 2, 79.5, 1]]}}
    print(ml.online_endpoints.invoke(endpoint_name="churn-ep", request_file="sample.json"))
    
    # Delete the endpoint when you've finished testing: it bills while it exists
    # ml.online_endpoints.begin_delete(name="churn-ep").result()
    
    
    # ---- src/train.py: fit a model and log it in MLflow format ----
    # import argparse, mlflow, pandas as pd
    # from sklearn.ensemble import GradientBoostingClassifier
    # from sklearn.model_selection import train_test_split
    #
    # p = argparse.ArgumentParser(); p.add_argument("--data"); args = p.parse_args()
    # df = pd.read_csv(args.data)
    # X, y = df.drop(columns=["churned"]), df["churned"]
    # X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
    # mlflow.sklearn.autolog()
    # with mlflow.start_run():
    #     model = GradientBoostingClassifier().fit(X_train, y_train)
    #     mlflow.log_metric("accuracy", model.score(X_test, y_test))
    #     mlflow.sklearn.log_model(model, artifact_path="model")
    // Program.cs: call a managed online endpoint (the endpoint itself was created with the CLI or Python tab)
    // Set AML_SCORING_URI and AML_KEY from the endpoint's details page, or with:
    //   az ml online-endpoint show --name churn-ep --query scoring_uri
    //   az ml online-endpoint get-credentials --name churn-ep
    using System.Net.Http.Headers;
    using System.Text;
    
    var scoringUri = Environment.GetEnvironmentVariable("AML_SCORING_URI")
        ?? throw new InvalidOperationException("Set AML_SCORING_URI");
    var key = Environment.GetEnvironmentVariable("AML_KEY")
        ?? throw new InvalidOperationException("Set AML_KEY");
    
    using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
    http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", key);
    
    // The columns the model was trained on, in the MLflow "input_data" shape
    const string body = """
    { "input_data": { "columns": ["tenure","support_calls","monthly_charge","contract"], "data": [[34, 2, 79.5, 1]] } }
    """;
    
    // Retry a few times: an endpoint that is updating or scaling can answer 5xx for a moment
    for (var attempt = 1; attempt <= 3; attempt++)
    {
        using var reply = await http.PostAsync(scoringUri, new StringContent(body, Encoding.UTF8, "application/json"));
        var text = await reply.Content.ReadAsStringAsync();
        if (reply.IsSuccessStatusCode)
        {
            Console.WriteLine($"Prediction: {text}");
            break;
        }
        Console.WriteLine($"Attempt {attempt}: {(int)reply.StatusCode} {text}");
        if (attempt == 3) throw new HttpRequestException($"Scoring failed with {(int)reply.StatusCode}");
        await Task.Delay(TimeSpan.FromSeconds(2 * attempt));
    }

    Best videos to explore

    Short walkthrough videos for this service are being prepared. They will appear here and load only when you press play. Until then, follow CloudBrum on YouTube for new videos.

    Introduction to Azure Machine LearningVideo coming soon · Beginner
    Compute clusters and jobs in Azure MLVideo coming soon · Intermediate
    Deploying a model to a managed online endpointVideo coming soon · Intermediate
    Azure ML MLOps with registries and pipelinesVideo coming soon · Advanced

    Interview questions

    BasicWhat is Azure Machine Learning?

    It’s Microsoft’s managed platform for the machine learning lifecycle. You create a workspace, run training as tracked jobs on compute that Azure manages, register the result as a model and deploy it to an endpoint. The service has no separate charge; you pay for the compute and the neighbouring resources.

    BasicWhat is a workspace and what does it depend on?

    The workspace is the top-level resource for a project. It keeps run history, models, endpoints and settings, and it is linked to a storage account, a key vault, Application Insights and a container registry. Those links are fixed when the workspace is created.

    BasicWhat is the difference between a compute instance and a compute cluster?

    An instance is one VM for one person to develop on, and it bills while it runs. A cluster is a pool of VMs that jobs share. It grows with the queue and, with a minimum of zero nodes, drops to nothing when idle.

    IntermediateHow do you keep training costs down in Azure ML?

    Set cluster minimum nodes to zero with a short idle timeout, use low-priority or spot VMs for jobs that can restart, use serverless compute for occasional runs, and set idle shutdown on compute instances. Tag everything and set budgets so a forgotten resource shows up early.

    IntermediateHow does a blue-green rollout work on a managed online endpoint?

    Create a second deployment, say green, under the same endpoint, and test it by calling it directly. Then move a small share of traffic to it, for example 90 to blue and 10 to green, watch the metrics, and shift the rest when it looks right. Traffic weights must add up to 100. Roll back by setting them back.

    IntermediateWhy would you deploy an MLflow model instead of a custom one?

    An MLflow model carries its signature and dependencies, so Azure ML can build the environment and serving code for you, with no scoring script. A custom model gives you full control over pre-processing and the response, at the cost of writing and testing that script and environment.

    AdvancedYour security team wants the workspace to have no public access. What do you configure?

    Disable public network access on the workspace and on its storage account and key vault, then add private endpoints or use the workspace’s managed virtual network with outbound rules. Make sure the compute, the container registry and any data sources are reachable through those private paths. Use managed identities and Azure Policy so it stays that way.

    AdvancedA deployment fails with a container crash and the logs are empty in the portal. What do you do?

    Pull the logs from the command line with the deployment get-logs command, which shows the container output. Run the image and scoring script locally with the same inputs, check that the model path and environment match, and give the container more memory if it is being killed while loading the model.

    AdvancedHow would you promote a model from dev to prod across workspaces?

    Share it through a registry. Register the model in the registry from the dev workspace, then have the prod pipeline deploy it from there with its own identity. Keep the job ID, metrics and approval record with the version, and require a reviewed pipeline run to create the prod deployment.

    AdvancedThe business wants predictions only twice a day over 50 million rows. What architecture do you pick?

    A batch endpoint on a cluster that scales to zero, started on a schedule from a pipeline or Data Factory. It splits the input across nodes and writes results to storage, and costs nothing between runs. An online endpoint would pay for VMs all day for no reason.

    Similar or alternative services on other clouds

    CapabilityAWSAzureGoogle Cloud
    ServiceAmazon SageMakerAzure Machine LearningVertex AI (Gemini Enterprise Agent Platform)
    The top-level containerA Studio domain and your AWS accountA workspace with four linked resourcesA Google Cloud project, with Vertex AI enabled in it
    Your own dev machineStudio spaceCompute instanceWorkbench instance
    Shared pool that shrinks to zeroTraining jobs create and remove instances per runCompute cluster with a minimum of zero, or serverless computeCustom jobs create machines per run
    Reusable training stepPipeline stepComponent in a pipeline jobPipeline component (Kubeflow Pipelines style)
    Tracked experimentsExperiments, backed by managed MLflowMLflow tracking built into the workspaceVertex AI Experiments
    Rolling out a new versionDeployment guardrails with canary or linear shiftingSeveral deployments per endpoint with a traffic splitTraffic split between deployed models on an endpoint
    Scoring a big fileBatch transformBatch endpointBatch prediction

    Azure ML is for building and operating your own models. To use a hosted large language model you would go to Microsoft Foundry or Azure OpenAI, and for ready-made vision or speech you would use the Azure AI services. Training data often sits in Azure Blob Storage, and a small model can be served from Azure Functions.

    Did you find this article helpful?

    Your answer helps us improve this page for the next reader.

    Sources and further reading

    CloudBrum wrote this page in its own words, using the provider’s public documentation listed below as the reference. Features, limits, names and prices change, so confirm anything that matters on the provider’s own pages before you decide.