| #!/usr/bin/env bash |
|
|
| |
|
|
| |
| |
|
|
| |
| PV="pv -cpteab" |
|
|
| model_id="$1" |
| revision="$2" |
| shift 2 |
| repo_url=https://huggingface.co/"$model_id" |
| clonepath="$(basename "$repo_url")" |
| cachepath="${HOME}/.cache/huggingface/hub/models--${model_id//\//--}/blobs" |
| if ! [ -e ${HOME}/.cache/huggingface/token ] |
| then |
| huggingface-cli login || exit -1 |
| fi |
| HF_TOKEN="$(<${HOME}/.cache/huggingface/token)" |
| GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/"$model_id" "$clonepath" |
| mkdir -p "$cachepath" |
| cd "$clonepath" |
| GIT_LFS_SKIP_SMUDGE=1 git checkout "$revision" || exit -1 |
| filecount=$(ls *.safetensors | wc -l) |
| export repo_url revision cachepath HF_TOKEN PV |
| |
| parallel "$@" -i bash -c \ |
| 'file_url="$repo_url"/resolve/"$revision"/"{}";\ |
| export $(cat "{}" | tr \ =);\ |
| blobname=${oid##*:};\ |
| outfile="$cachepath"/"$blobname";\ |
| set pipefail;\ |
| if [ "$(($(stat -c %s "$outfile" 2>/dev/null)))" != "$(($size))" ]; then\ |
| curl --silent -L --header "Authorization: Bearer $HF_TOKEN" "$file_url" |\ |
| $PV -s "$size" -N "{}" > "$outfile" 2>/dev/tty || continue;\ |
| fi;\ |
| echo "$blobname" "$outfile"'\ |
| -- *.safetensors | |
| $PV -l -s "$filecount" -N "$clonepath" 2>/dev/tty | |
| sha256sum -c && echo SUCCESS || { echo ERROR try again; false; } |
|
|