Untitled

Anonymous
Plain Text
10/09/2025 1:37 PM
1.9 KB
28
Indexable
Never
#!/bin/bash

# ===== CONFIGURATION - MODIFY THESE =====
HF_DATASET="finetrainers/OpenVid-60k-split"
LOCAL_DIR="/tmp/openvid_download"
REMOTE_USER="your_username"
REMOTE_HOST="your_server.com"
REMOTE_DIR="/path/to/remote/dataset"
SSH_KEY_PATH="~/.ssh/id_rsa"   # Use "" for default key

# RANGE TO DOWNLOAD (inclusive)
START_IDX=10
END_IDX=31
BATCH_SIZE=3
# =======================================

mkdir -p "$LOCAL_DIR"

handle_error() {
    echo "ERROR: $1" >&2
    exit 1
}

process_batch() {
    local files=("$@")
    local batch_desc="files [${files[0]} to ${files[-1]}]"
    echo "=== Processing batch: $batch_desc ==="

    # Build --include args
    declare -a includes
    for f in "${files[@]}"; do
        includes+=("--include" "dataset_$(printf "%04d" $f).tar")
    done

    # Download
    echo "Downloading ${#files[@]} files..."
    huggingface-cli download "$HF_DATASET" \
        --repo-type dataset \
        --local-dir "$LOCAL_DIR" \
        --local-dir-use-symlinks False \
        "${includes[@]}" || handle_error "Download failed for batch $batch_desc"

    # Verify
    for f in "${files[@]}"; do
        local fname="dataset_$(printf "%04d" $f).tar"
        [[ -f "$LOCAL_DIR/$fname" ]] || handle_error "Missing $fname"
    done

    # Transfer
    echo "Transferring batch to remote server..."
    scp -i "$SSH_KEY_PATH" "$LOCAL_DIR"/*.tar "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/" \
        || handle_error "SCP failed for batch $batch_desc"

    # Cleanup
    rm -f "$LOCAL_DIR"/*.tar
    echo "Batch $batch_desc completed."
    echo
}

# Generate file indices
declare -a indices
for ((i=START_IDX; i<=END_IDX; i++)); do
    indices+=($i)
done

# Process in batches
total=${#indices[@]}
for ((i=0; i<total; i+=BATCH_SIZE)); do
    batch=("${indices[@]:i:BATCH_SIZE}")
    process_batch "${batch[@]}"
done

echo "✅ All batches from $START_IDX to $END_IDX processed!"
Editor is loading...
Leave a Comment