Implementation:Interpretml Interpret Powerlift RunAzureVM
| Knowledge Sources | |
|---|---|
| Domains | Benchmarking, Cloud_Infrastructure, Azure, VM_Orchestration |
| Last Updated | 2026-02-07 12:00 GMT |
Overview
Azure VM provisioning runner that creates, configures, and manages the full lifecycle of Azure Virtual Machines for executing Powerlift benchmark trials, including networking, SSH key generation, startup scripting, and RBAC permission assignment.
Description
This module implements the remote process logic invoked by the AzureVMInstance executor. It contains two main functions:
assign_contributor_permissions() -- Manages Azure RBAC role assignments for VMs using a priority queue pattern:
- Uses a min-heap to process VMs in order of creation time.
- Waits for VM creation to complete before querying the VM's managed identity principal ID.
- Assigns the Contributor role to both the VM's managed identity and the client user.
- Retries on
HttpResponseError, recreating API clients as needed.
run_azure_process() -- Orchestrates the full VM lifecycle:
- Generates an SSH key pair using
cryptography.hazmatfor secure VM access. - Creates a virtual network and subnet (named
powerlift-vnet-{location}andpowerlift-subnet-{location}). - For each runner instance, creates a network interface and provisions a VM with:
- Configurable size, OS image (publisher/offer/SKU/version), and disk type.
- System-assigned managed identity for Azure resource access.
- A base64-encoded custom data startup script injected via cloud-init.
- The startup script installs Python, creates a virtual environment, retrieves experiment configuration from the database via
psql, installs dependencies, and runs the experiment in a loop. - VMs self-delete on completion using Azure CLI (
az vm delete). - Network interfaces and OS disks have
deleteOption: Deletefor automatic cleanup.
Unlike the ACI runner, this module does not poll for container termination since VMs manage their own lifecycle through the self-delete mechanism in the startup script.
Usage
This module is not called directly by users. It is invoked by the AzureVMInstance executor via multiprocessing.Pool.apply_async(). Understanding this module is essential for debugging Azure VM provisioning or customizing VM startup behavior.
Code Reference
Source Location
- Repository: Interpretml_Interpret
- File:
python/powerlift/powerlift/run/azure_vm.py
Signature
def assign_contributor_permissions(
compute_client,
auth_client,
max_undead,
credential,
subscription_id,
client_id,
resource_group_name,
resource_uris,
vms,
):
...
def run_azure_process(
experiment_id,
n_instances,
uri,
resource_uris,
timeout,
azure_json,
credential,
location,
vm_size,
image_publisher,
image_offer,
image_sku,
image_version,
disk_type,
max_undead,
delete_on_complete,
batch_id,
):
...
Import
from powerlift.run.azure_vm import run_azure_process, assign_contributor_permissions
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| experiment_id | int | Yes | Experiment identifier to run trials for |
| n_instances | int | Yes | Number of VMs to create |
| uri | str | Yes | Database connection URI (embedded in startup script) |
| resource_uris | List[str] | No | Azure resource URIs to grant contributor permissions |
| timeout | float | Yes | Timeout in seconds per trial execution |
| azure_json | dict | Yes | Azure credentials (tenant_id, client_id, client_secret, subscription_id, resource_group) |
| credential | object | No | Pre-built Azure credential object |
| location | str | No | Azure region; defaults to resource group location |
| vm_size | str | Yes | Azure VM size (e.g., "Standard_B16s_v2") |
| image_publisher | str | Yes | OS image publisher (e.g., "canonical") |
| image_offer | str | Yes | OS image offer (e.g., "ubuntu-24_04-lts") |
| image_sku | str | Yes | OS image SKU (e.g., "server") |
| image_version | str | Yes | OS image version (e.g., "latest") |
| disk_type | str | Yes | Disk storage type (e.g., "Standard_LRS") |
| max_undead | int | Yes | Maximum unprocessed VMs during initialization |
| delete_on_complete | bool | Yes | Whether VMs self-delete after trial completion |
| batch_id | int | Yes | Random batch identifier for naming VMs and NICs |
Outputs
| Name | Type | Description |
|---|---|---|
| assign_contributor_permissions return | Tuple | Updated (compute_client, auth_client) tuple |
| run_azure_process return | None | Function completes when all VMs are provisioned and permissions assigned |
Usage Examples
# This module is invoked internally by AzureVMInstance executor.
# Direct usage is not recommended. See AzureVMInstance for the public API.
from powerlift.executors.azure_vm import AzureVMInstance
executor = AzureVMInstance(
store=store,
azure_tenant_id="...",
subscription_id="...",
azure_client_id="...",
azure_client_secret="...",
n_instances=2,
vm_size="Standard_NC24ads_A100_v4",
)
# submit() internally calls run_azure_process via multiprocessing
executor.submit(experiment_id=1, timeout=7200)
executor.join()
Related Pages
- Interpretml_Interpret_Powerlift_AzureVMInstance -- Executor class that invokes this module
- Interpretml_Interpret_Powerlift_RunAzureCI -- Parallel implementation for Azure Container Instance provisioning
- Interpretml_Interpret_Powerlift_RunTrials -- Trial execution logic invoked inside the VMs
- Interpretml_Interpret_Powerlift_Schema -- Database models accessed by the startup script via psql