AI & Agents

How-To: Pin Hugging Face Models to a Commit So a Hijacked Account Can’t Swap Your Weights

Leave a comment

After the Kokoro account takeover, I want my local AI experiments to load the exact weights I tested, not whatever “main” points to today. Here’s how to pin a model to a commit.

1. Find the commit you trust

pip install -U huggingface_hub
python3 -c "from huggingface_hub import HfApi; i=HfApi().model_info('ORG/MODEL'); print(i.sha, i.last_modified)"

2. Download that exact revision

hf download ORG/MODEL --revision <sha> --local-dir ./models/MODEL

In Python, pass revision="<sha>" to from_pretrained() or hf_hub_download(). A branch name like main can move, but a full commit hash can’t.

3. Stop silent re-downloads

export HF_HUB_OFFLINE=1

With that set, your scripts use only what’s already cached locally and won’t fetch new revisions behind your back.

4. Record what you run

sha256sum ./models/MODEL/*.safetensors > MODEL.sha256
sha256sum -c MODEL.sha256

When you’re ready to upgrade, read the commit history first, test in a VM, and only then bump the pin.

Isolate it: try new software in a disposable VM or on a spare machine first, with a snapshot you can roll back to. Don’t point it at a machine you care about.

God Bless, and May the Source Be with You!

References & Further Reading

Subscribe (RSS) Follow AI & Agents via RSS

Leave a note

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.