benzlxs commited on
Commit
eb2cff2
·
verified ·
1 Parent(s): 3e05348

Upload hf_upload_173.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. hf_upload_173.sh +149 -0
hf_upload_173.sh ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Configuration
4
+ REPO_ID="benzlxs/objaverse_rendering_set"
5
+ REPO_TYPE="dataset"
6
+ LOCAL_DIR="zip_folder"
7
+ STABILITY_CHECK_INTERVAL=150 # Seconds between size checks
8
+ STABILITY_THRESHOLD=2 # Number of consecutive checks with same size before considering stable
9
+ LOG_FILE="upload_log_173.txt"
10
+
11
+ # Enable hf_transfer for faster uploads
12
+ export HF_HUB_ENABLE_HF_TRANSFER=1
13
+
14
+ # Colors for output
15
+ GREEN='\033[0;32m'
16
+ YELLOW='\033[1;33m'
17
+ RED='\033[0;31m'
18
+ NC='\033[0m' # No Color
19
+
20
+ # Function to log messages
21
+ log_message() {
22
+ echo -e "$1"
23
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
24
+ }
25
+
26
+ # Function to check if file size is stable
27
+ is_file_stable() {
28
+ local file=$1
29
+ local prev_size=0
30
+ local stable_count=0
31
+
32
+ log_message "${YELLOW}Monitoring $file for stability...${NC}"
33
+
34
+ while [ $stable_count -lt $STABILITY_THRESHOLD ]; do
35
+ if [ ! -f "$file" ]; then
36
+ log_message "${YELLOW}File $file not found yet, waiting...${NC}"
37
+ sleep $STABILITY_CHECK_INTERVAL
38
+ continue
39
+ fi
40
+
41
+ current_size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null)
42
+
43
+ if [ "$current_size" -eq "$prev_size" ] && [ "$current_size" -gt 0 ]; then
44
+ stable_count=$((stable_count + 1))
45
+ log_message "Size unchanged: $current_size bytes (check $stable_count/$STABILITY_THRESHOLD)"
46
+ else
47
+ stable_count=0
48
+ prev_size=$current_size
49
+ log_message "Size changed to: $current_size bytes, resetting counter"
50
+ fi
51
+
52
+ if [ $stable_count -lt $STABILITY_THRESHOLD ]; then
53
+ sleep $STABILITY_CHECK_INTERVAL
54
+ fi
55
+ done
56
+
57
+ log_message "${GREEN}File $file is stable at $current_size bytes${NC}"
58
+ return 0
59
+ }
60
+
61
+ # Function to wait for file to exist
62
+ wait_for_file() {
63
+ local file=$1
64
+ local max_wait=3600 # Maximum wait time in seconds (1 hour)
65
+ local waited=0
66
+
67
+ while [ ! -f "$file" ] && [ $waited -lt $max_wait ]; do
68
+ log_message "${YELLOW}Waiting for $file to be created...${NC}"
69
+ sleep 10
70
+ waited=$((waited + 10))
71
+ done
72
+
73
+ if [ ! -f "$file" ]; then
74
+ log_message "${RED}Timeout waiting for $file${NC}"
75
+ return 1
76
+ fi
77
+
78
+ return 0
79
+ }
80
+
81
+ # Main upload loop
82
+ log_message "${GREEN}=== Starting Hugging Face Upload Script ===${NC}"
83
+ log_message "Repository: $REPO_ID"
84
+ log_message "Local directory: $LOCAL_DIR"
85
+
86
+
87
+ # for i in 000-068 000-078 000-088 000-100 000-112 000-122 000-132 000-142 000-152 000-009 000-019 000-029 000-039 000-049 000-059 000-069 000-079 000-089 000-102 000-113 000-123 000-133 000-143 000-153
88
+ # for i in 000-068 000-078 000-088 000-100 000-112 000-122 000-132 000-142 000-152 000-009 000-019 000-029 000-039 000-059 000-069 000-079 000-089 000-102 000-113 000-123 000-133 000-143 000-153
89
+ # for i in 000-085 000-096 000-108 000-119 000-129 000-139 000-149 000-159 000-006 000-016 000-026 000-036 000-046 000-056 000-066 000-076 000-086 000-097 000-109 000-120 000-130 000-140 000-150 000-007 000-017 000-027 000-037 000-047 000-057 000-067 000-077 000-087 000-098 000-110 000-121 000-131 000-141 000-151 000-008 000-018 000-028 000-038 000-048 000-058
90
+ # for i in 000-010 000-020 000-030 000-040 000-050 000-060 000-070 000-080 000-090 000-103 000-114 000-124 000-134 000-144 000-154 000-001 000-011 000-021 000-031 000-041 000-051 000-061 000-071
91
+ for i in 000-126 000-136 000-146 000-156 000-003 000-013 000-023 000-033 000-043 000-053 000-063 000-073 000-083 000-094 000-106 000-117 000-127 000-137 000-147 000-157 000-004 000-014 000-024 000-034
92
+ do
93
+ tar_file="${LOCAL_DIR}/${i}.tar"
94
+ log_message "\n${GREEN}========================================${NC}"
95
+ log_message "${GREEN}Processing: ${i}.tar${NC}"
96
+ log_message "${GREEN}========================================${NC}"
97
+
98
+ # Wait for the tar file to appear (if it doesn't exist yet)
99
+ if [ ! -f "$tar_file" ]; then
100
+ log_message "${YELLOW}File ${i}.tar doesn't exist yet, waiting for creation...${NC}"
101
+ if ! wait_for_file "$tar_file"; then
102
+ log_message "${RED}Skipping ${i}.tar - file was not created within timeout${NC}"
103
+ continue
104
+ fi
105
+ fi
106
+
107
+ # Wait for file to be stable (packing complete)
108
+ if is_file_stable "$tar_file"; then
109
+ # Get final file size for logging
110
+ file_size=$(stat -f%z "$tar_file" 2>/dev/null || stat -c%s "$tar_file" 2>/dev/null)
111
+ file_size_mb=$((file_size / 1048576))
112
+
113
+ log_message "${GREEN}Uploading ${i}.tar (${file_size_mb} MB) to Hugging Face...${NC}"
114
+
115
+ # Upload with retry logic
116
+ max_retries=3
117
+ retry_count=0
118
+ upload_success=false
119
+
120
+ while [ $retry_count -lt $max_retries ] && [ "$upload_success" = false ]; do
121
+ if huggingface-cli upload "$REPO_ID" "$tar_file" "${i}.tar" --repo-type="$REPO_TYPE"; then
122
+ log_message "${GREEN}✓ Successfully uploaded ${i}.tar${NC}"
123
+ upload_success=true
124
+
125
+ # Optional: Delete local file after successful upload to save space
126
+ # rm "$tar_file"
127
+ # log_message "${YELLOW}Deleted local file ${i}.tar${NC}"
128
+ else
129
+ retry_count=$((retry_count + 1))
130
+ log_message "${RED}Upload failed for ${i}.tar (attempt $retry_count/$max_retries)${NC}"
131
+ if [ $retry_count -lt $max_retries ]; then
132
+ log_message "Retrying in 30 seconds..."
133
+ sleep 30
134
+ fi
135
+ fi
136
+ done
137
+
138
+ if [ "$upload_success" = false ]; then
139
+ log_message "${RED}✗ Failed to upload ${i}.tar after $max_retries attempts${NC}"
140
+ fi
141
+ else
142
+ log_message "${RED}File stability check failed for ${i}.tar${NC}"
143
+ fi
144
+
145
+ log_message "${GREEN}Completed processing ${i}.tar${NC}"
146
+ done
147
+
148
+ log_message "\n${GREEN}=== All files processed ===${NC}"
149
+ log_message "Check $LOG_FILE for detailed logs"