Registry / azure / azureml-train-restclients-hyperdrive

azureml-train-restclients-hyperdrive

JSON →
library1.62.0pypypiunverified

This package contains internal classes and REST clients crucial for creating and managing HyperDriveRuns within the Azure Machine Learning SDK. It acts as an underlying dependency for the `azureml-core` package, specifically enabling the HyperDrive functionality for hyperparameter tuning. The current version is 1.62.0, and its release cadence follows the broader Azure ML SDK updates.

pip install azureml-train-restclients-hyperdrive
INSTALL
IMPORT
SIG · AZUREML-TRAIN-REST
A
azureml-train-restclients-hyperdrive
azurepythonv1.62.0
Install
10.2s avg
Import
Disk
117MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.62.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 0.000s · 43.8MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 10.2s · import 0.000s · 44MB
117MB installed
● package 117MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HyperDriveConfig
from azureml.train.hyperdrive import HyperDriveConfig
from azureml.train.hyperdrive import HyperDriveConfig

This quickstart demonstrates how to set up and submit a HyperDrive experiment for hyperparameter tuning using the Azure Machine Learning V1 SDK. It includes workspace loading, compute target creation, environment definition, script configuration, hyperparameter sampling, and the HyperDrive configuration itself. Note that a `train.py` script is generated on the fly for demonstration purposes.

import os from azureml.core import Workspace, Experiment, Environment from azureml.core.compute import AmlCompute, ComputeTarget from azureml.core.script_run_config import ScriptRunConfig from azureml.train.hyperdrive import HyperDriveConfig, RandomParameterSampling, primary_metric_goal from azureml.core.conda_dependencies import CondaDependencies # NOTE: Replace with your actual workspace details or ensure config.json is present # For quickstart, using dummy values for environment variables if not set subscription_id = os.environ.get('AZUREML_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID') resource_group = os.environ.get('AZUREML_RESOURCE_GROUP', 'YOUR_RESOURCE_GROUP') workspace_name = os.environ.get('AZUREML_WORKSPACE_NAME', 'YOUR_WORKSPACE_NAME') # Create a dummy train.py for the example if it doesn't exist # In a real scenario, this would be your actual training script with open('train.py', 'w') as f: f.write(""" import argparse import os from azureml.core import Run parser = argparse.ArgumentParser() parser.add_argument('--learning_rate', type=float, default=0.01, help='Learning rate for training') parser.add_argument('--momentum', type=float, default=0.9, help='Momentum for training') args = parser.parse_args() run = Run.get_context() # Simulate training and log a metric accuracy = 0.5 + args.learning_rate * 100 - args.momentum * 0.2 # Dummy calculation run.log('accuracy', accuracy) print(f"Run finished with accuracy: {accuracy}") """) try: ws = Workspace(subscription_id=subscription_id, resource_group=resource_group, workspace_name=workspace_name) print("Workspace loaded successfully.") except Exception as e: print(f"Could not load workspace. Please ensure your config.json is correct or environment variables are set. Error: {e}") print("Attempting to create a dummy workspace for demonstration purposes only (will fail without real creds).") # This part is illustrative, it won't actually create a workspace without proper authentication ws = None # In a real scenario, you'd handle this or use Workspace.create() if ws: # Create or get a compute target cluster_name = 'cpu-cluster-hd' try: compute_target = ComputeTarget(workspace=ws, name=cluster_name) print(f"Found existing compute target: {cluster_name}") except Exception: print(f"Creating new compute target: {cluster_name}") compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_DS3_V2', max_nodes=2) compute_target = ComputeTarget.create(ws, cluster_name, compute_config) compute_target.wait_for_completion(show_output=True) # Define the environment conda_dep = CondaDependencies() conda_dep.add_pip_package('azureml-sdk') # Required for Run.get_context() env = Environment(name='hyperdrive-env') env.python.conda_dependencies = conda_dep env.docker.enabled = True # Use a docker base image env.register(workspace=ws) # Create a ScriptRunConfig for the training script src = ScriptRunConfig(source_directory='.', script='train.py', compute_target=compute_target, environment=env, arguments=['--learning_rate', 0.01, '--momentum', 0.9]) # Initial values # Define hyperparameter sampling space param_sampling = RandomParameterSampling({ '--learning_rate': [0.005, 0.01, 0.02, 0.05], '--momentum': [0.8, 0.9, 0.99] }) # Configure HyperDrive hyperdrive_config = HyperDriveConfig(run_config=src, hyperparameter_sampling=param_sampling, primary_metric_name='accuracy', primary_metric_goal=primary_metric_goal.MAXIMIZE, max_total_runs=5, max_concurrent_runs=2) # Submit the HyperDrive run experiment = Experiment(workspace=ws, name='hyperdrive-example-run') hyperdrive_run = experiment.submit(hyperdrive_config) print(f"Submitted HyperDrive run: {hyperdrive_run.get_portal_url()}") hyperdrive_run.wait_for_completion(show_output=True) best_run = hyperdrive_run.get_best_run_by_primary_metric() print(f"Best run ID: {best_run.id}, Metrics: {best_run.get_metrics()}") else: print("Skipping HyperDrive run submission due to failed workspace setup.")
Debug
Known issues
gotchaThe `azureml-train-restclients-hyperdrive` package is primarily an internal dependency of the Azure ML SDK. End-users typically install `azureml-core` or `azureml-sdk` and import HyperDrive-related classes (like `HyperDriveConfig`) from `azureml.train.hyperdrive`. Direct imports from `azureml.train.restclients.hyperdrive` are uncommon and may lead to missing functionality or unexpected behavior.
fix
Always install `pip install azureml-core[train]` and import from `azureml.train.hyperdrive` for user-facing HyperDrive functionality.
affects: All versions
deprecatedThe V1 SDK (`azureml.*`) approach for HyperDrive, which this package supports, is being superseded by the V2 SDK (`azure.ai.ml`). While V1 is still supported, Microsoft encourages using V2 for new projects, which leverages `MLClient.sweep()` for hyperparameter tuning workflows.
fix
For new projects, consider migrating to the V2 SDK (`azure.ai.ml`) and using `MLClient.sweep()` for hyperparameter tuning. Existing V1 projects can continue to use `azureml.train.hyperdrive` but should plan for eventual migration.
affects: All versions (future V1 deprecation)
breakingThere are significant API differences between Azure ML SDK V1 (`azureml.*`) and V2 (`azure.ai.ml`). Code written for V1 is not directly compatible with V2, requiring a migration path. This specific `azureml-train-restclients-hyperdrive` package is part of the V1 SDK.
fix
Carefully review the migration guide from V1 to V2 if you plan to upgrade your Azure ML SDK usage. Ensure consistency in using either V1 (`azureml.train.hyperdrive`) or V2 (`azure.ai.ml.sweep`) components within your application.
affects: Transition from V1 to V2 SDK
Upgrade
Version history
1.62.0latest on PyPI · released Feb 25, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
azureml-train-restclients-hyperdrive — pip install azureml-train-restclients-hyperdrive · libregistry