Skip to main content

hf-preflight

Check a Hugging Face model before you download it.

$ hf-preflight org/some-model
RISKY
  org/some-model

    gated: no
    licence: apache-2.0
    size on disk: 13.2 GB across 14 file(s)
  ! remote code: YES — config.json sets auto_map, so loading this model executes
    modeling_custom.py, configuration_custom.py from the repo on your machine
    (requires trust_remote_code=True)
  ! weights: pickle only (pytorch_model.bin) — no safetensors; unpickling
    executes whatever the file says to

No dependencies. Python 3.9+. Does not require huggingface_hub.

Why

Four things about a model are worth knowing before the download starts, and all four are currently learned the hard way:

  • Is it gated? You find out when the download fails — sometimes after tens of gigabytes have already moved.
  • What licence? llama3.1 and other are not apache-2.0. Worth knowing before the model is embedded in something you ship.
  • How big is it really? The model card rarely says. The file list does.
  • Does loading it execute someone else's code on your machine? Two ways it can, both routinely accepted without a thought.

That last one is the reason this exists.

The two code-execution paths

trust_remote_code. When a model's config.json carries auto_map, transformers imports and runs .py files from the model repository on your machine. The flag that permits this is passed constantly, usually because a tutorial said to. hf-preflight names the exact files that would run.

Pickle weights. .bin, .pt, .pth and .ckpt are pickles, and unpickling executes whatever the pickle instructs. .safetensors was created precisely so this is not true. A repository that ships only pickles is doing something worth noticing.

Neither is presented as an accusation — plenty of legitimate models use both. They are reported so the choice to accept them is a choice.

Install

pip install hf-preflight
# or, without installing:
uvx hf-preflight org/model

Use

hf-preflight org/model
hf-preflight https://huggingface.co/org/model     # a pasted URL works
hf-preflight org/model --revision refs/pr/3
hf-preflight org/model --json

Exit codes: 0 clean, 1 risky, 2 blocked, 3 error.

For CI, name the gates you actually care about — this exits non-zero only for those, so an unrelated risky finding does not fail your pipeline:

hf-preflight "$MODEL" --fail-on remote-code,pickle || {
  echo "refusing to pull a model that executes code on load"; exit 1
}

Available gates: gated, license, remote-code, pickle.

Authentication

Optional. Without a token a gated repository is indistinguishable from one that does not exist, so hf-preflight would report "not found" for a model that merely needs approval.

A token is read from HF_TOKEN, HUGGING_FACE_HUB_TOKEN, HUGGINGFACEHUB_API_TOKEN, or ~/.cache/huggingface/token — so if you have run huggingface-cli login there is nothing to do.

Note that reading a gated repo's metadata does not prove you may download its weights, and the output says so rather than implying access is confirmed.

What it does not do

  • It does not read the remote .py files or judge what they contain. It tells you they will run. Reviewing them is your call.
  • It does not scan weights for malicious payloads. It tells you the format permits them.
  • A clean verdict means nothing checked here was alarming — not that the model is safe.

Licence

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hf_preflight-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hf_preflight-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file hf_preflight-0.1.0.tar.gz.

File metadata

  • Download URL: hf_preflight-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for hf_preflight-0.1.0.tar.gz
Algorithm Hash digest
SHA256 04a8eb2c4fbaafe01daade8139e247a736c5235462a1c6a9b97cca5a1c2b2b46
MD5 b739461ef4e9e2d5478f35936e1b3234
BLAKE2b-256 17f31d2acbb1432bd5cfd1080e7a4b02d16657253dbaac8957e814a9c78ca5b0

See more details on using hashes here.

File details

Details for the file hf_preflight-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hf_preflight-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for hf_preflight-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5cc0453c1f1e34c79cb956d11718a60a36f2fdc1dcb51aabb41110753149936
MD5 7be9c16b1162aa8a051024f86d1b07ba
BLAKE2b-256 35717ec383fead9af0fd3e43735dfaafd491e2e85bb3feb67858cb3cbc5cd81e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page