Skip to content

Commit f1cd4bf

Browse files
committed
fix(docker): patch PIGuard export script to trust remote HF modeling code
The guard repo's export_onnx.py does not pass trust_remote_code=True, which causes the non-interactive container to hang on the HuggingFace prompt. We now patch the script after cloning and set HF_TRUST_REMOTE_CODE=1. HF_TOKEN is passed through if set on the host.
1 parent 880d989 commit f1cd4bf

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

docker/piguard/download-model.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ echo "Output directory: ${MODEL_DIR}"
2525
#
2626
# DEBIAN_FRONTEND=noninteractive keeps apt-get quiet on headless hosts.
2727
# GIT_CONFIG_GLOBAL turns off the detached-HEAD advice and clone progress spam.
28+
# HF_TRUST_REMOTE_CODE=1 allows the PIGuard model's custom modeling code to run
29+
# without an interactive prompt. Pass through HF_TOKEN if set on the host.
30+
DOCKER_ENVS=(
31+
-e HF_HOME=/tmp
32+
-e DEBIAN_FRONTEND=noninteractive
33+
-e GIT_CONFIG_GLOBAL=/tmp/.gitconfig
34+
-e HF_TRUST_REMOTE_CODE=1
35+
)
36+
if [ -n "${HF_TOKEN:-}" ]; then
37+
DOCKER_ENVS+=(-e "HF_TOKEN=${HF_TOKEN}")
38+
fi
39+
2840
docker run --rm \
2941
-v "${MODEL_DIR}:/out" \
30-
-e HF_HOME=/tmp \
31-
-e DEBIAN_FRONTEND=noninteractive \
32-
-e GIT_CONFIG_GLOBAL=/tmp/.gitconfig \
42+
"${DOCKER_ENVS[@]}" \
3343
python:3.12-slim bash -c "
3444
set -euo pipefail
3545
@@ -46,6 +56,13 @@ docker run --rm \
4656
4757
cd /src
4858
59+
# The PIGuard model uses custom HF modeling code. The upstream export script
60+
# does not pass trust_remote_code=True, so we patch it to avoid the interactive
61+
# y/N prompt that would hang in a non-TTY container.
62+
echo '==> Patching export script to allow custom HF modeling code...'
63+
sed -i 's/AutoTokenizer.from_pretrained(MODEL_ID, revision=MODEL_REVISION)/AutoTokenizer.from_pretrained(MODEL_ID, revision=MODEL_REVISION, trust_remote_code=True)/' scripts/export_onnx.py
64+
sed -i 's/AutoModelForSequenceClassification.from_pretrained(/AutoModelForSequenceClassification.from_pretrained(trust_remote_code=True, /' scripts/export_onnx.py
65+
4966
echo '==> Installing Python export requirements (this may take a minute)...'
5067
pip install --no-cache-dir --quiet -r scripts/requirements.txt
5168

0 commit comments

Comments
 (0)