Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
crazygao committed May 9, 2024
1 parent ae99b74 commit 9305234
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions examples/tutorials/run-flow-with-pipeline/pipeline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" credential = DefaultAzureCredential()\n",
" # Check if given credential can get token successfully.\n",
" credential.get_token(\"https://management.azure.com/.default\")\n",
"except Exception as ex:\n",
" # Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work\n",
" credential = InteractiveBrowserCredential()"
"def ensure_credential():\n",
" try:\n",
" credential = DefaultAzureCredential()\n",
" # Check if given credential can get token successfully.\n",
" credential.get_token(\"https://management.azure.com/.default\")\n",
" except Exception as ex:\n",
" # Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work\n",
" credential = InteractiveBrowserCredential()\n",
" return credential\n",
"\n",
"credential = ensure_credential()"
]
},
{
Expand Down Expand Up @@ -297,7 +301,8 @@
"outputs": [],
"source": [
"# Ensure the credential is still valid, refresh the token if needed\n",
"credential.get_token(\"https://management.azure.com/.default\")\n",
"credential = ensure_credential()\n",
"ml_client = MLClient.from_config(credential=credential)\n",
"# Submit the pipeline job to your workspace\n",
"pipeline_job_run = ml_client.jobs.create_or_update(\n",
" pipeline_job_def, experiment_name=\"Single_flow_component_pipeline_job\"\n",
Expand Down Expand Up @@ -417,7 +422,8 @@
"outputs": [],
"source": [
"# Ensure the credential is still valid, refresh the token if needed\n",
"credential.get_token(\"https://management.azure.com/.default\")\n",
"credential = ensure_credential()\n",
"ml_client = MLClient.from_config(credential=credential)\n",
"# submit job to workspace\n",
"pipeline_job_run = ml_client.jobs.create_or_update(\n",
" pipeline_job_def, experiment_name=\"Complex_flow_component_pipeline_job\"\n",
Expand Down Expand Up @@ -482,7 +488,8 @@
"outputs": [],
"source": [
"# Ensure the credential is still valid, refresh the token if needed\n",
"credential.get_token(\"https://management.azure.com/.default\")\n",
"credential = ensure_credential()\n",
"ml_client = MLClient.from_config(credential=credential)\n",
"\n",
"job_schedule = ml_client.schedules.begin_create_or_update(\n",
" schedule=job_schedule\n",
Expand All @@ -506,7 +513,8 @@
"outputs": [],
"source": [
"# Ensure the credential is still valid, refresh the token if needed\n",
"credential.get_token(\"https://management.azure.com/.default\")\n",
"credential = ensure_credential()\n",
"ml_client = MLClient.from_config(credential=credential)\n",
"\n",
"job_schedule = ml_client.schedules.begin_disable(name=schedule_name).result()\n",
"job_schedule.is_enabled"
Expand Down Expand Up @@ -548,7 +556,8 @@
")\n",
"\n",
"# Ensure the credential is still valid, refresh the token if needed\n",
"credential.get_token(\"https://management.azure.com/.default\")\n",
"credential = ensure_credential()\n",
"ml_client = MLClient.from_config(credential=credential)\n",
"\n",
"ml_client.batch_endpoints.begin_create_or_update(endpoint).result()"
]
Expand Down Expand Up @@ -576,12 +585,14 @@
")\n",
"\n",
"# Ensure the credential is still valid, refresh the token if needed\n",
"credential.get_token(\"https://management.azure.com/.default\")\n",
"credential = ensure_credential()\n",
"ml_client = MLClient.from_config(credential=credential)\n",
"\n",
"ml_client.batch_deployments.begin_create_or_update(deployment).result()\n",
"\n",
"# Ensure the credential is still valid, refresh the token if needed\n",
"credential.get_token(\"https://management.azure.com/.default\")\n",
"credential = ensure_credential()\n",
"ml_client = MLClient.from_config(credential=credential)\n",
"\n",
"# Refresh the default deployment to the latest one at our endpoint.\n",
"endpoint = ml_client.batch_endpoints.get(endpoint.name)\n",
Expand All @@ -603,7 +614,8 @@
"outputs": [],
"source": [
"# Ensure the credential is still valid, refresh the token if needed\n",
"credential.get_token(\"https://management.azure.com/.default\")\n",
"credential = ensure_credential()\n",
"ml_client = MLClient.from_config(credential=credential)\n",
"\n",
"batch_endpoint_job = ml_client.batch_endpoints.invoke(\n",
" endpoint_name=endpoint.name,\n",
Expand All @@ -625,7 +637,8 @@
"outputs": [],
"source": [
"# Ensure the credential is still valid, refresh the token if needed\n",
"credential.get_token(\"https://management.azure.com/.default\")\n",
"credential = ensure_credential()\n",
"ml_client = MLClient.from_config(credential=credential)\n",
"\n",
"ml_client.jobs.get(batch_endpoint_job.name)"
]
Expand Down

0 comments on commit 9305234

Please sign in to comment.