forked from inference-labs-inc/omron-subnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_model_files.sh
executable file
·36 lines (32 loc) · 1.39 KB
/
sync_model_files.sh
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
#!/bin/bash
# Search for models in the deployment layer
MODEL_DIR="neurons/deployment_layer"
for MODEL_FOLDER in $(find "$MODEL_DIR" -maxdepth 1 -type d -name 'model_*'); do
# See if the model has metadata attached
METADATA_FILE="${MODEL_FOLDER}/metadata.json"
if [ ! -f "$METADATA_FILE" ]; then
echo "Error: Metadata file not found at $METADATA_FILE"
continue
fi
# If the model has a metadata file, check external_files to determine which files are needed
external_files=$(jq -r '.external_files | to_entries[] | "\(.key) \(.value)"' "$METADATA_FILE")
if [ $? -ne 0 ]; then
echo "Error: Failed to parse JSON from $METADATA_FILE"
continue
fi
while IFS=' ' read -r key url; do
# If the external file already exists then do nothing
if [ -f "${MODEL_FOLDER}/${key}" ]; then
echo "File ${key} already downloaded at ${MODEL_FOLDER}/${key}, skipping..."
continue
fi
# If the file doesn't exist we'll pull from the URL specified
echo "Downloading ${url} to ${MODEL_FOLDER}/${key}..."
curl -o "${MODEL_FOLDER}/${key}" "${url}"
# If the file doesn't download then we'll skip this file and echo the error
if [ $? -ne 0 ]; then
echo "Error: Failed to download ${url} to ${MODEL_FOLDER}/${key}"
continue
fi
done <<< "$external_files"
done