|
169 | 169 | "if BUCKET_URI is None or BUCKET_URI.strip() == \"\" or BUCKET_URI == \"gs://\":\n", |
170 | 170 | " BUCKET_URI = f\"gs://{PROJECT_ID}-tmp-{now}-{str(uuid.uuid4())[:4]}\"\n", |
171 | 171 | " 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", |
173 | 173 | "else:\n", |
174 | 174 | " 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", |
176 | 176 | " bucket_region = shell_output[0].strip().lower()\n", |
177 | 177 | " if bucket_region != REGION:\n", |
178 | 178 | " raise ValueError(\n", |
|
197 | 197 | "\n", |
198 | 198 | "\n", |
199 | 199 | "# 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", |
201 | 201 | "\n", |
202 | 202 | "! gcloud config set project $PROJECT_ID\n", |
203 | 203 | "! gcloud projects add-iam-policy-binding --no-user-output-enabled {PROJECT_ID} --member=serviceAccount:{SERVICE_ACCOUNT} --role=\"roles/storage.admin\"\n", |
|
220 | 220 | " destination = os.path.join(CONFIG_DIR, filename)\n", |
221 | 221 | " print(\"Copy\", url, \"to\", destination)\n", |
222 | 222 | " ! wget \"$url\" -O \"$filename\"\n", |
223 | | - " ! gcloud storage cp \"$filename\" \"$destination\"\n", |
| 223 | + " ! gsutil cp \"$filename\" \"$destination\"\n", |
224 | 224 | "\n", |
225 | 225 | "\n", |
226 | 226 | "upload_config_to_gcs(\n", |
|
457 | 457 | " checkpoint_path = os.path.relpath(checkpoint_path, checkpoint_name)\n", |
458 | 458 | " break\n", |
459 | 459 | "\n", |
460 | | - " ! gcloud storage cp --recursive $checkpoint_name $CHECKPOINT_BUCKET/\n", |
| 460 | + " ! gsutil cp -r $checkpoint_name $CHECKPOINT_BUCKET/\n", |
461 | 461 | " checkpoint_uri = os.path.join(CHECKPOINT_BUCKET, checkpoint_name, checkpoint_path)\n", |
462 | 462 | " print(\"Checkpoint uploaded to\", checkpoint_uri)\n", |
463 | 463 | " return checkpoint_uri\n", |
|
588 | 588 | " current_trial_best_ckpt_evaluation_filepath = os.path.join(\n", |
589 | 589 | " current_trial_best_ckpt_dir, \"info.json\"\n", |
590 | 590 | " )\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", |
593 | 593 | " eval_metric_results = json.load(f)\n", |
594 | 594 | " current_performance = eval_metric_results[evaluation_metric]\n", |
595 | 595 | " if current_performance > best_performance:\n", |
|
696 | 696 | " serving_container_image_uri=PREDICTION_CONTAINER_URI,\n", |
697 | 697 | " serving_container_args=SERVING_CONTAINER_ARGS,\n", |
698 | 698 | " 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", |
700 | 702 | ")\n", |
701 | 703 | "\n", |
702 | 704 | "models[\"model_icn\"].wait()\n", |
|
724 | 726 | " accelerator_count=1,\n", |
725 | 727 | " min_replica_count=1,\n", |
726 | 728 | " 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", |
728 | 732 | ")\n", |
729 | 733 | "\n", |
730 | 734 | "endpoint_id = endpoints[\"endpoint_icn\"].name\n", |
|
772 | 776 | " \"\"\"\n", |
773 | 777 | " label_map_filename = os.path.basename(label_map_yaml_filepath)\n", |
774 | 778 | " 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", |
776 | 780 | " stderr=subprocess.STDOUT,\n", |
777 | 781 | " )\n", |
778 | 782 | " with open(label_map_filename, \"rb\") as input_file:\n", |
|
793 | 797 | " if new_width <= 0:\n", |
794 | 798 | " test_file = os.path.basename(test_filepath)\n", |
795 | 799 | " subprocess.check_output(\n", |
796 | | - " [\"gcloud\", \"storage\", \"cp\", test_filepath, test_file],\n", |
| 800 | + " [\"gsutil\", \"cp\", test_filepath, test_file], stderr=subprocess.STDOUT\n", |
797 | 801 | " stderr=subprocess.STDOUT,\n", |
798 | 802 | " )\n", |
799 | 803 | " with open(test_file, \"rb\") as input_file:\n", |
|
905 | 909 | "\n", |
906 | 910 | "delete_bucket = False # @param {type:\"boolean\"}\n", |
907 | 911 | "if delete_bucket:\n", |
908 | | - " ! gcloud storage rm --recursive $BUCKET_NAME" |
| 912 | + " ! gsutil -m rm -r $BUCKET_NAME" |
909 | 913 | ] |
910 | 914 | } |
911 | 915 | ], |
|
0 commit comments