Skip to content

Commit 5f3152b

Browse files
Merge pull request #102 from bhandarivijay-png/ai-gsutil-migration-ae277dae317e4c0f8a6aa44815ef7ded
removed changes for model garden PR 4316
2 parents e7404ae + 9ee3716 commit 5f3152b

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

notebooks/community/model_garden/model_garden_tfvision_image_classification.ipynb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@
169169
"if BUCKET_URI is None or BUCKET_URI.strip() == \"\" or BUCKET_URI == \"gs://\":\n",
170170
" BUCKET_URI = f\"gs://{PROJECT_ID}-tmp-{now}-{str(uuid.uuid4())[:4]}\"\n",
171171
" BUCKET_NAME = \"/\".join(BUCKET_URI.split(\"/\")[:3])\n",
172-
" ! gcloud storage buckets create --location={REGION} {BUCKET_URI}\n",
172+
" ! gsutil mb -l {REGION} {BUCKET_URI}\n",
173173
"else:\n",
174174
" assert BUCKET_URI.startswith(\"gs://\"), \"BUCKET_URI must start with `gs://`.\"\n",
175-
" shell_output = ! gcloud storage ls --full --buckets {BUCKET_NAME} | grep \"Location Constraint:\" | sed \"s/Location Constraint://\"\n",
175+
" shell_output = ! gsutil ls -Lb {BUCKET_NAME} | grep \"Location constraint:\" | sed \"s/Location constraint://\"\n",
176176
" bucket_region = shell_output[0].strip().lower()\n",
177177
" if bucket_region != REGION:\n",
178178
" raise ValueError(\n",
@@ -197,7 +197,7 @@
197197
"\n",
198198
"\n",
199199
"# Provision permissions to the SERVICE_ACCOUNT with the GCS bucket\n",
200-
"! gcloud storage buckets add-iam-policy-binding $BUCKET_NAME --member=serviceAccount:{SERVICE_ACCOUNT} --role=roles/storage.admin\n",
200+
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.admin $BUCKET_NAME\n",
201201
"\n",
202202
"! gcloud config set project $PROJECT_ID\n",
203203
"! gcloud projects add-iam-policy-binding --no-user-output-enabled {PROJECT_ID} --member=serviceAccount:{SERVICE_ACCOUNT} --role=\"roles/storage.admin\"\n",
@@ -220,7 +220,7 @@
220220
" destination = os.path.join(CONFIG_DIR, filename)\n",
221221
" print(\"Copy\", url, \"to\", destination)\n",
222222
" ! wget \"$url\" -O \"$filename\"\n",
223-
" ! gcloud storage cp \"$filename\" \"$destination\"\n",
223+
" ! gsutil cp \"$filename\" \"$destination\"\n",
224224
"\n",
225225
"\n",
226226
"upload_config_to_gcs(\n",
@@ -457,7 +457,7 @@
457457
" checkpoint_path = os.path.relpath(checkpoint_path, checkpoint_name)\n",
458458
" break\n",
459459
"\n",
460-
" ! gcloud storage cp --recursive $checkpoint_name $CHECKPOINT_BUCKET/\n",
460+
" ! gsutil cp -r $checkpoint_name $CHECKPOINT_BUCKET/\n",
461461
" checkpoint_uri = os.path.join(CHECKPOINT_BUCKET, checkpoint_name, checkpoint_path)\n",
462462
" print(\"Checkpoint uploaded to\", checkpoint_uri)\n",
463463
" return checkpoint_uri\n",
@@ -588,8 +588,8 @@
588588
" current_trial_best_ckpt_evaluation_filepath = os.path.join(\n",
589589
" current_trial_best_ckpt_dir, \"info.json\"\n",
590590
" )\n",
591-
" ! gcloud storage cp $current_trial_best_ckpt_evaluation_filepath .\n",
592-
" with open(\"info.json\") as f:\n",
591+
" ! gsutil cp $current_trial_best_ckpt_evaluation_filepath .\n",
592+
" with open(\"info.json\", \"r\") as f:\n",
593593
" eval_metric_results = json.load(f)\n",
594594
" current_performance = eval_metric_results[evaluation_metric]\n",
595595
" if current_performance > best_performance:\n",
@@ -696,7 +696,9 @@
696696
" serving_container_image_uri=PREDICTION_CONTAINER_URI,\n",
697697
" serving_container_args=SERVING_CONTAINER_ARGS,\n",
698698
" serving_container_environment_variables=serving_env,\n",
699-
" model_garden_source_model_name=(f\"publishers/google/models/{publisher_model_id}\"),\n",
699+
" model_garden_source_model_name=(\n",
700+
" f\"publishers/google/models/{publisher_model_id}\"\n",
701+
" ),\n",
700702
")\n",
701703
"\n",
702704
"models[\"model_icn\"].wait()\n",
@@ -724,7 +726,9 @@
724726
" accelerator_count=1,\n",
725727
" min_replica_count=1,\n",
726728
" max_replica_count=1,\n",
727-
" system_labels={\"NOTEBOOK_NAME\": \"model_garden_tfvision_image_classification.ipynb\"},\n",
729+
" system_labels={\n",
730+
" \"NOTEBOOK_NAME\": \"model_garden_tfvision_image_classification.ipynb\"\n",
731+
" },\n",
728732
")\n",
729733
"\n",
730734
"endpoint_id = endpoints[\"endpoint_icn\"].name\n",
@@ -772,7 +776,7 @@
772776
" \"\"\"\n",
773777
" label_map_filename = os.path.basename(label_map_yaml_filepath)\n",
774778
" subprocess.check_output(\n",
775-
" [\"gcloud\", \"storage\", \"cp\", label_map_yaml_filepath, label_map_filename],\n",
779+
" [\"gsutil\", \"cp\", label_map_yaml_filepath, label_map_filename],\n",
776780
" stderr=subprocess.STDOUT,\n",
777781
" )\n",
778782
" with open(label_map_filename, \"rb\") as input_file:\n",
@@ -793,7 +797,7 @@
793797
" if new_width <= 0:\n",
794798
" test_file = os.path.basename(test_filepath)\n",
795799
" subprocess.check_output(\n",
796-
" [\"gcloud\", \"storage\", \"cp\", test_filepath, test_file],\n",
800+
" [\"gsutil\", \"cp\", test_filepath, test_file], stderr=subprocess.STDOUT\n",
797801
" stderr=subprocess.STDOUT,\n",
798802
" )\n",
799803
" with open(test_file, \"rb\") as input_file:\n",
@@ -905,7 +909,7 @@
905909
"\n",
906910
"delete_bucket = False # @param {type:\"boolean\"}\n",
907911
"if delete_bucket:\n",
908-
" ! gcloud storage rm --recursive $BUCKET_NAME"
912+
" ! gsutil -m rm -r $BUCKET_NAME"
909913
]
910914
}
911915
],

notebooks/community/model_garden/model_garden_timesfm_2_0_deployment_on_vertex.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@
162162
"if BUCKET_URI is None or BUCKET_URI.strip() == \"\" or BUCKET_URI == \"gs://\":\n",
163163
" BUCKET_URI = f\"gs://{PROJECT_ID}-tmp-{now}-{str(uuid.uuid4())[:4]}\"\n",
164164
" BUCKET_NAME = \"/\".join(BUCKET_URI.split(\"/\")[:3])\n",
165-
" ! gcloud storage buckets create --location {REGION} {BUCKET_URI}\n",
165+
" ! gsutil mb -l {REGION} {BUCKET_URI}\n",
166166
"else:\n",
167167
" assert BUCKET_URI.startswith(\"gs://\"), \"BUCKET_URI must start with `gs://`.\"\n",
168-
" shell_output = ! gcloud storage ls --full --buckets {BUCKET_NAME} | grep \"Location Constraint:\" | sed \"s/Location Constraint://\"\n",
168+
" shell_output = ! gsutil ls -Lb {BUCKET_NAME} | grep \"Location constraint:\" | sed \"s/Location constraint://\"\n",
169169
" bucket_region = shell_output[0].strip().lower()\n",
170170
" if bucket_region != REGION:\n",
171171
" raise ValueError(\n",
@@ -190,7 +190,7 @@
190190
"\n",
191191
"\n",
192192
"# Provision permissions to the SERVICE_ACCOUNT with the GCS bucket\n",
193-
"! gcloud storage buckets add-iam-policy-binding $BUCKET_NAME --member=serviceAccount:{SERVICE_ACCOUNT} --role=roles/storage.admin\n",
193+
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.admin $BUCKET_NAME\n",
194194
"\n",
195195
"! gcloud config set project $PROJECT_ID\n",
196196
"! gcloud projects add-iam-policy-binding --no-user-output-enabled {PROJECT_ID} --member=serviceAccount:{SERVICE_ACCOUNT} --role=\"roles/storage.admin\"\n",
@@ -911,7 +911,7 @@
911911
"\n",
912912
"delete_bucket = False # @param {type:\"boolean\"}\n",
913913
"if delete_bucket:\n",
914-
" ! gcloud storage rm --recursive $BUCKET_NAME"
914+
" ! gsutil -m rm -r $BUCKET_NAME"
915915
]
916916
}
917917
],

0 commit comments

Comments
 (0)