Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions official/legacy/bert/bert_cloud_tpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ gcloud config set project ${PROJECT_ID}
```
4. Create a Cloud Storage bucket using the following command:
```
gsutil mb -p ${PROJECT_ID} -c standard -l europe-west4 -b on gs://your-bucket-name
gcloud storage buckets create --project=${PROJECT_ID} --default-storage-class=standard --location=europe-west4 --uniform-bucket-level-access gs://your-bucket-name
```
This Cloud Storage bucket stores the data you use to train your model and the training results.
5. Launch a Compute Engine VM and Cloud TPU using the ctpu up command.
Expand Down Expand Up @@ -100,7 +100,7 @@ $ ctpu status --zone=your-zone
```
4. Run gsutil as shown, replacing your-bucket with the name of the Cloud Storage bucket you created for this tutorial:
```
$ gsutil rm -r gs://your-bucket
$ gcloud storage rm --recursive gs://your-bucket
```


Expand Down
4 changes: 2 additions & 2 deletions official/legacy/xlnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export SPIECE_DIR=~/cased_spiece/
export SPIECE_MODEL=${SPIECE_DIR}/cased_spiece.model
export DATASETS_DIR=gs://some_bucket/datasets
mkdir -p ${SPIECE_DIR}
gsutil cp gs://cloud-tpu-checkpoints/xlnet/cased_spiece.model ${SPIECE_DIR}
gcloud storage cp gs://cloud-tpu-checkpoints/xlnet/cased_spiece.model ${SPIECE_DIR}
```


Expand Down Expand Up @@ -134,7 +134,7 @@ Then to process the dataset into TFRecords, run the following commands:
```shell
python3 preprocess_squad_data.py --spiece_model_file=${SPIECE_MODEL} --train_file=${SQUAD_DIR}/train-v2.0.json --predict_file=${SQUAD_DIR}/dev-v2.0.json --output_dir=${DATASETS_DIR}/squad --uncased=False --max_seq_length=512 --num_proc=1 --proc_id=0

gsutil cp ${SQUAD_DIR}/dev-v2.0.json ${DATASETS_DIR}/squad
gcloud storage cp ${SQUAD_DIR}/dev-v2.0.json ${DATASETS_DIR}/squad
```

## Fine-tuning with XLNet
Expand Down
2 changes: 1 addition & 1 deletion official/projects/longformer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pytorch longformer tokenized data to tf_records.
Option 1. Use our saved checkpoint of `allenai/longformer-base-4096` stored in cloud storage

```bash
gsutil cp -r gs://model-garden-ucsd-zihan/longformer-4096 .
gcloud storage cp --recursive gs://model-garden-ucsd-zihan/longformer-4096 .
```
Option 2. Create it directly

Expand Down
2 changes: 1 addition & 1 deletion official/projects/qat/nlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ training, using mobilebert as an exmaple:
```shell

# First, Download the pre-trained floating point model as QAT needs to finetune it.
gsutil cp gs://tf_model_garden/nlp/qat/mobilebert/mobilebert_fp32_ckpt.tar.gz /tmp/qat/
gcloud storage cp gs://tf_model_garden/nlp/qat/mobilebert/mobilebert_fp32_ckpt.tar.gz /tmp/qat/

# Extract the checkpoint.
tar -xvzf /tmp/qat/mobilebert_fp32_ckpt.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion official/projects/qat/vision/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ using object detection as an example:
```shell

# First download the pre-trained floating point model as QAT needs to finetune it.
gsutil cp gs://tf_model_garden/vision/qat/mobilenetv2_ssd_coco/mobilenetv2_ssd_i256_ckpt.tar.gz /tmp/qat/
gcloud storage cp gs://tf_model_garden/vision/qat/mobilenetv2_ssd_coco/mobilenetv2_ssd_i256_ckpt.tar.gz /tmp/qat/

# Extract the checkpoint.
tar -xvzf /tmp/qat/mobilenetv2_ssd_i256_ckpt.tar.gz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def upload_image_results_to_storage_bucket(
try:
commands = [
f"rm -r {os.path.basename(input_directory)}",
f"gsutil -m cp -r {prediction_folder} {output_directory}",
f"gcloud storage cp --recursive {prediction_folder} {output_directory}",
f"rm -r {prediction_folder}",
]
subprocess.run(" && ".join(commands), shell=True, check=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_upload_image_results_to_storage_bucket_success(self):

self.mock_subprocess_run.assert_called_once()
args, _ = self.mock_subprocess_run.call_args
self.assertIn(f"gsutil -m cp -r {pred_dir} {output_dir}", args[0])
self.assertIn(f"gcloud storage cp --recursive {pred_dir} {output_dir}", args[0])

def test_upload_image_results_to_storage_bucket_failure(self):
input_dir = "/tmp/input"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def copy(path: str) -> None:
Args:
path: path of the video in GCS bucket.
"""
gsutil_command = f"gsutil cp -r {path} ."
gsutil_command = f"gcloud storage cp --recursive {path} ."
subprocess.run(gsutil_command, shell=True, check=True)


def move(file_path: str, destination_bucket_path: str) -> None:
"""Moves a video file or directory of image files.

This function uses the 'gsutil' command-line utility to move a file or
This function uses the 'gcloud' command-line utility to move a file or
directory to a GCS bucket. If the given file path is a directory, it moves
all contents recursively. The function executes the appropriate 'gsutil'
command based on whether the provided file path is a file or a directory.
Expand All @@ -48,9 +48,10 @@ def move(file_path: str, destination_bucket_path: str) -> None:
will be moved to. This path should be in the format
'gs://bucket-name/path/to/destination'.
"""
destination_bucket_path = destination_bucket_path.rstrip('/') + '/'
if os.path.isdir(file_path):
gsutil_command = f"gsutil -m mv -r {file_path} {destination_bucket_path}"
gsutil_command = f"gcloud storage mv {file_path} {destination_bucket_path}"
else:
gsutil_command = f"gsutil mv {file_path} {destination_bucket_path}"
gsutil_command = f"gcloud storage mv {file_path} {destination_bucket_path}"

subprocess.run(gsutil_command, shell=True, check=True)
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ images to the source GCS bucket created by the script. The script output will
provide the name of the bucket.

```bash
gsutil cp your-local-image.jpg gs://<source-bucket-name>/
gcloud storage cp your-local-image.jpg gs://<source-bucket-name>/
```
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ cd milk_pouch_project
# NOTE: Adjust the grep pattern if other image types are expected.
echo "=== DEBUGGING START ==="
echo "DEBUG: gcs_path variable is: '${gcs_path}'"
echo "DEBUG: Running 'gsutil ls \"${gcs_path}\"' to check accessibility:"
gsutil ls "${gcs_path}" || echo "❌ gsutil ls failed"
echo "DEBUG: Running 'gsutil ls -r \"${gcs_path}\" | head -n 10' to check content:"
gsutil ls -r "${gcs_path}" | head -n 10 || echo "❌ gsutil recursive ls failed"
echo "DEBUG: Running 'gcloud storage ls \"${gcs_path}\"' to check accessibility:"
gcloud storage ls "${gcs_path}" || echo "❌ gcloud storage ls failed"
echo "DEBUG: Running 'gcloud storage ls --recursive \"${gcs_path}\" | head -n 10' to check content:"
gcloud storage ls --recursive "${gcs_path}" | head -n 10 || echo "❌ gsutil recursive ls failed"
echo "=== DEBUGGING END ==="

echo "🖨️ Listing image files from GCS bucket: $gcs_path"
mapfile -t all_gcs_files < <(gsutil ls -r "${gcs_path}" | grep -iE '\.(png|jpg|jpeg)$' | grep -v "/predictions/" | grep -v "/processed/")
mapfile -t all_gcs_files < <(gcloud storage ls --recursive "${gcs_path}" | grep -iE '\.(png|jpg|jpeg)$' | grep -v "/predictions/" | grep -v "/processed/")
num_files=${#all_gcs_files[@]}

if (( num_files == 0 )); then
Expand Down Expand Up @@ -77,7 +77,7 @@ for (( i=0; i<num_files; i+=batch_size )); do

# Copy current batch files from GCS
echo "🖨️ Copying $num_in_batch files from GCS to input_images/..."
gsutil -m cp "${current_batch[@]}" input_images/
gcloud storage cp "${current_batch[@]}" input_images/

# Extract objects
echo "🔎 Extracting objects from images..."
Expand All @@ -96,7 +96,7 @@ for (( i=0; i<num_files; i+=batch_size )); do
# Move predictions back to GCS
if [ -d "predictions" ] && [ -n "$(find predictions -type f -print -quit)" ]; then
echo "🖨️ Moving predictions for this batch back to GCS bucket: $gcs_path"
gsutil -m cp -r predictions/ "$gcs_path"
gcloud storage cp --recursive predictions/ "$gcs_path"
else
echo "⚠️ No predictions generated for this batch."
fi
Expand Down Expand Up @@ -128,7 +128,7 @@ for (( i=0; i<num_files; i+=batch_size )); do
# If the destination directory changes, flush the current batch
if [[ "$dest_dir" != "$current_move_dir" ]]; then
if (( ${#current_move_batch[@]} > 0 )); then
gsutil -m mv "${current_move_batch[@]}" "$current_move_dir"
gcloud storage mv "${current_move_batch[@]}" "$current_move_dir"
current_move_batch=()
fi
current_move_dir="$dest_dir"
Expand All @@ -138,7 +138,7 @@ for (( i=0; i<num_files; i+=batch_size )); do

# Flush any remaining files
if (( ${#current_move_batch[@]} > 0 )); then
gsutil -m mv "${current_move_batch[@]}" "$current_move_dir"
gcloud storage mv "${current_move_batch[@]}" "$current_move_dir"
fi

unset current_move_batch
Expand Down