|
192 | 192 | "cell_type": "markdown", |
193 | 193 | "metadata": {}, |
194 | 194 | "source": [ |
195 | | - "### Create or Attach a Remote Linux DSVM" |
| 195 | + "### Create or Attach an AmlCompute cluster" |
196 | 196 | ] |
197 | 197 | }, |
198 | 198 | { |
|
201 | 201 | "metadata": {}, |
202 | 202 | "outputs": [], |
203 | 203 | "source": [ |
204 | | - "dsvm_name = 'mydsvmb'\n", |
| 204 | + "from azureml.core.compute import AmlCompute\n", |
| 205 | + "from azureml.core.compute import ComputeTarget\n", |
205 | 206 | "\n", |
206 | | - "try:\n", |
207 | | - " while ws.compute_targets[dsvm_name].provisioning_state == 'Creating':\n", |
208 | | - " time.sleep(1)\n", |
209 | | - " \n", |
210 | | - " dsvm_compute = DsvmCompute(ws, dsvm_name)\n", |
211 | | - " print('Found existing DVSM.')\n", |
212 | | - "except:\n", |
213 | | - " print('Creating a new DSVM.')\n", |
214 | | - " dsvm_config = DsvmCompute.provisioning_configuration(vm_size = \"Standard_D2_v2\")\n", |
215 | | - " dsvm_compute = DsvmCompute.create(ws, name = dsvm_name, provisioning_configuration = dsvm_config)\n", |
216 | | - " dsvm_compute.wait_for_completion(show_output = True)\n", |
217 | | - " print(\"Waiting one minute for ssh to be accessible\")\n", |
218 | | - " time.sleep(90) # Wait for ssh to be accessible" |
| 207 | + "# Choose a name for your cluster.\n", |
| 208 | + "amlcompute_cluster_name = \"cpucluster\"\n", |
| 209 | + "\n", |
| 210 | + "found = False\n", |
| 211 | + "\n", |
| 212 | + "# Check if this compute target already exists in the workspace.\n", |
| 213 | + "\n", |
| 214 | + "cts = ws.compute_targets\n", |
| 215 | + "if amlcompute_cluster_name in cts and cts[amlcompute_cluster_name].type == 'AmlCompute':\n", |
| 216 | + " found = True\n", |
| 217 | + " print('Found existing compute target.')\n", |
| 218 | + " compute_target = cts[amlcompute_cluster_name]\n", |
| 219 | + "\n", |
| 220 | + "if not found:\n", |
| 221 | + " print('Creating a new compute target...')\n", |
| 222 | + " provisioning_config = AmlCompute.provisioning_configuration(vm_size = \"STANDARD_D2_V2\", # for GPU, use \"STANDARD_NC6\"\n", |
| 223 | + " #vm_priority = 'lowpriority', # optional\n", |
| 224 | + " max_nodes = 6)\n", |
| 225 | + "\n", |
| 226 | + " # Create the cluster.\\n\",\n", |
| 227 | + " compute_target = ComputeTarget.create(ws, amlcompute_cluster_name, provisioning_config)\n", |
| 228 | + "\n", |
| 229 | + " # Can poll for a minimum number of nodes and for a specific timeout.\n", |
| 230 | + " # If no min_node_count is provided, it will use the scale settings for the cluster.\n", |
| 231 | + " compute_target.wait_for_completion(show_output = True, min_node_count = None, timeout_in_minutes = 20)\n", |
| 232 | + "\n", |
| 233 | + " # For a more detailed view of current AmlCompute status, use get_status()." |
219 | 234 | ] |
220 | 235 | }, |
221 | 236 | { |
|
227 | 242 | "from azureml.core.runconfig import RunConfiguration\n", |
228 | 243 | "from azureml.core.conda_dependencies import CondaDependencies\n", |
229 | 244 | "\n", |
| 245 | + "# create a new RunConfig object\n", |
230 | 246 | "conda_run_config = RunConfiguration(framework=\"python\")\n", |
231 | 247 | "\n", |
232 | | - "conda_run_config.target = dsvm_compute\n", |
| 248 | + "# Set compute target to AmlCompute\n", |
| 249 | + "conda_run_config.target = compute_target\n", |
| 250 | + "conda_run_config.environment.docker.enabled = True\n", |
| 251 | + "conda_run_config.environment.docker.base_image = azureml.core.runconfig.DEFAULT_CPU_IMAGE\n", |
233 | 252 | "\n", |
234 | 253 | "cd = CondaDependencies.create(pip_packages=['azureml-sdk[automl]'], conda_packages=['numpy','py-xgboost<=0.80'])\n", |
235 | 254 | "conda_run_config.environment.python.conda_dependencies = cd" |
|
294 | 313 | "remote_run.clean_preprocessor_cache()" |
295 | 314 | ] |
296 | 315 | }, |
| 316 | + { |
| 317 | + "cell_type": "markdown", |
| 318 | + "metadata": {}, |
| 319 | + "source": [ |
| 320 | + "### Cancelling Runs\n", |
| 321 | + "You can cancel ongoing remote runs using the `cancel` and `cancel_iteration` functions." |
| 322 | + ] |
| 323 | + }, |
| 324 | + { |
| 325 | + "cell_type": "code", |
| 326 | + "execution_count": null, |
| 327 | + "metadata": {}, |
| 328 | + "outputs": [], |
| 329 | + "source": [ |
| 330 | + "# Cancel the ongoing experiment and stop scheduling new iterations.\n", |
| 331 | + "# remote_run.cancel()\n", |
| 332 | + "\n", |
| 333 | + "# Cancel iteration 1 and move onto iteration 2.\n", |
| 334 | + "# remote_run.cancel_iteration(1)" |
| 335 | + ] |
| 336 | + }, |
297 | 337 | { |
298 | 338 | "cell_type": "markdown", |
299 | 339 | "metadata": {}, |
|
0 commit comments