-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup_models.sh
More file actions
92 lines (74 loc) · 2.82 KB
/
Copy pathbackup_models.sh
File metadata and controls
92 lines (74 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# Check if the number of arguments is correct
if [ "$#" -ne 2 ]; then
echo "Usage: $0 run_time_hours sacred_run_number"
exit 1
fi
# Assign arguments to variables
run_time_hours="$1"
sacred_run_number="$2"
start_time=$(date +%s)
# Convert hours to seconds
run_time=$((run_time_hours * 3600))
# Print starting message
echo "Starting script with sacred_run_number $sacred_run_number. It will run for $run_time_hours hours."
# Function to clear cache, excluding ~/.cache/huggingface/metrics
clear_cache() {
cache_dir="$HOME/.cache"
# Check if the cache directory exists
if [ -d "$cache_dir" ]; then
# Remove all files and directories inside the cache directory except ~/.cache/huggingface/metrics
find "$cache_dir/huggingface" -mindepth 1 -maxdepth 1 -type d ! -name "metrics" -exec rm -rf {} \;
echo "Cache cleared except for ~/.cache/huggingface/metrics"
else
echo "Cache directory not found: $cache_dir"
fi
}
# Function to create directory if it doesn't exist
create_directory() {
directory="$1"
# Check if directory exists, if not create it
if [ ! -d "$directory" ]; then
mkdir -p "$directory"
echo "Created directory: $directory"
fi
}
# Function to copy checkpoints
copy_checkpoints() {
checkpoint_dir="data/generative_re_model_storage_azure/$sacred_run_number/checkpoints"
create_directory "$checkpoint_dir"
for checkpoint_dir_path in Generative-re-tests/results/checkpoint-*; do
if [ -d "$checkpoint_dir_path" ]; then
cp -r "$checkpoint_dir_path" "$checkpoint_dir"
echo "Copied: $checkpoint_dir_path to $checkpoint_dir"
fi
done
}
# Function to copy latest sacred run
copy_latest_sacred_run() {
latest_sacred_run=$(ls -td Generative-re-tests/sacred_runs/"$sacred_run_number"/*/ | head -n 1)
if [ -n "$latest_sacred_run" ]; then
cp -r "$latest_sacred_run" "data/generative_re_model_storage_azure/$sacred_run_number"
echo "Copied latest sacred run: $latest_sacred_run"
else
echo "No sacred run found for sacred_run_number: $sacred_run_number"
fi
}
# Main function
main() {
clear_cache
# Check if directory exists, if not create it
create_directory "data/generative_re_model_storage_azure/$sacred_run_number"
create_directory "data/generative_re_model_storage_azure/$sacred_run_number/checkpoints"
# Run loop for specified run_time
while [ $(($(date +%s) - start_time)) -lt "$run_time" ]; do
copy_checkpoints
sleep 300 # Sleep for 5 minutes (300 seconds)
done
copy_latest_sacred_run
end_time=$(date +%s)
elapsed_time=$((end_time - start_time))
echo "Script ran for $((elapsed_time / 3600)) hours, $(((elapsed_time / 60) % 60)) minutes, and $((elapsed_time % 60)) seconds."
}
# Execute main function
main