3v324v23 commited on
Commit
5c18fd7
·
1 Parent(s): e7df8ec

weight downloading script

Browse files
Files changed (1) hide show
  1. download_weights.bash +40 -0
download_weights.bash ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ # fills huggingfaces cache by downloading safetensors files in parallel
4
+ # usage: $ bash download_weights.bash SOME/MODEL_ID COMMIT_HASH -j4
5
+
6
+ #PV="pv -cpteabm $((60*60*24))"
7
+ PV="pv -cpteab"
8
+
9
+ model_id="$1"
10
+ revision="$2"
11
+ shift 2
12
+ repo_url=https://huggingface.co/"$model_id"
13
+ clonepath="$(basename "$repo_url")"
14
+ cachepath="${HOME}/.cache/huggingface/hub/models--${model_id//\//--}/blobs"
15
+ if ! [ -e ${HOME}/.cache/huggingface/token ]
16
+ then
17
+ huggingface-cli login || exit -1
18
+ fi
19
+ HF_TOKEN="$(<${HOME}/.cache/huggingface/token)"
20
+ GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/"$model_id" "$clonepath"
21
+ mkdir -p "$cachepath"
22
+ cd "$clonepath"
23
+ GIT_LFS_SKIP_SMUDGE=1 git checkout "$revision" || exit -1
24
+ filecount=$(ls *.safetensors | wc -l)
25
+ export repo_url revision cachepath HF_TOKEN PV
26
+ # troubleshot by adding -vx before -c in the bash command
27
+ parallel "$@" -i bash -c \
28
+ 'file_url="$repo_url"/resolve/"$revision"/"{}";\
29
+ export $(cat "{}" | tr \ =);\
30
+ blobname=${oid##*:};\
31
+ outfile="$cachepath"/"$blobname";\
32
+ set pipefail;\
33
+ if [ "$(($(stat -c %s "$outfile" 2>/dev/null)))" != "$(($size))" ]; then\
34
+ curl --silent -L --header "Authorization: Bearer $HF_TOKEN" "$file_url" |\
35
+ $PV -s "$size" -N "{}" > "$outfile" 2>/dev/tty || continue;\
36
+ fi;\
37
+ echo "$blobname" "$outfile"'\
38
+ -- *.safetensors |
39
+ $PV -l -s "$filecount" -N "$clonepath" 2>/dev/tty |
40
+ sha256sum -c && echo SUCCESS || { echo ERROR try again; false; }