Skip to main content

Download a HuggingFace model and convert it to GGUF for Ollama.

Project description

hf2ollama

CI PyPI Downloads License Python

English | 中文 | हिन्दी | Español | Français | العربية | বাংলা | Русский | Português | اردو

Run any HuggingFace text model inside Ollama with one command.

Point hf2ollama at a HuggingFace repo — it fetches the model, converts it to the GGUF format Ollama needs, and prints the two ollama commands you run to register and chat with it. No manual convert_hf_to_gguf.py, no hand-written Modelfile.

Requires Python 3.11+ and a working Ollama install.


Install

pip install hf2ollama

Usage

Put your HuggingFace token in a .env next to where you'll run the command, then point the tool at a repo:

echo "HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxx" > .env
hf2ollama SicariusSicariiStuff/Assistant_Pepe_70B

When it finishes, the tool prints two commands. Run them and you're chatting:

ollama create assistant-pepe-70b -f <path>/Modelfile
ollama run assistant-pepe-70b

(Get a HuggingFace token at https://huggingface.co/settings/tokens with Read scope. It's needed only for private and gated models, but having one set never hurts.)

Optional flags

# See which GGUF quants are inside a *-GGUF repo (no download):
hf2ollama some-user/some-model-GGUF --list

# Download a single quant — other .gguf files are skipped:
hf2ollama some-user/some-model-GGUF --quant Q5_K_M

# Custom Ollama model name:
hf2ollama some-user/some-model --ollama-name my-model

Install from git

For the latest unreleased changes:

pip install git+https://github.com/wachawo/hf2ollama.git
# or, over SSH:
pip install git+ssh://git@github.com/wachawo/hf2ollama.git

Install from source

For local development:

git clone git@github.com:wachawo/hf2ollama.git
cd hf2ollama
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
cp .env.example .env   # then put your HF_TOKEN into .env
hf2ollama --help

Configuration

.env in the directory you run hf2ollama from:

HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Optional. f16 (default) | f32 | bf16 | q8_0 | auto
OUTTYPE=f16

Path overrides

Everything is written under the current working directory. Override with env vars if you want to share things between workspaces:

Variable Default Purpose
HF2OLLAMA_WORKSPACE $PWD Base directory for everything below.
HF2OLLAMA_HF_DIR <workspace>/hf Where HF snapshots and GGUFs go.
HF2OLLAMA_CACHE_DIR <workspace>/.hf_cache huggingface_hub cache.
HF2OLLAMA_LLAMA_CPP_DIR <workspace>/llama.cpp Where to clone llama.cpp.

What ends up on disk

<workspace>/
├── .env                # HF_TOKEN, OUTTYPE
├── hf/                 # HF snapshots land here
│   └── <org>/<name>/   # source files + resulting GGUF + Modelfile, all in one folder
│       ├── config.json
│       ├── model.safetensors
│       ├── ...
│       ├── <name>.f16.gguf
│       └── Modelfile
└── .hf_cache/          # local huggingface_hub cache

<workspace>/llama.cpp/   # cloned on first conversion run

The first run that needs conversion also clones llama.cpp into your workspace so the next run is fast. Only repos that ship prebuilt GGUF files skip this step. To share one clone across several workspaces, set HF2OLLAMA_LLAMA_CPP_DIR (e.g. HF2OLLAMA_LLAMA_CPP_DIR=../llama.cpp).

Example output

======================================================================
GGUF:      <workspace>/hf/SicariusSicariiStuff/Assistant_Pepe_70B/Assistant_Pepe_70B.f16.gguf
Modelfile: <workspace>/hf/SicariusSicariiStuff/Assistant_Pepe_70B/Modelfile

Done. To import the model into Ollama, run these 2 commands:
  ollama create assistant-pepe-70b -f <workspace>/hf/SicariusSicariiStuff/Assistant_Pepe_70B/Modelfile
  ollama run assistant-pepe-70b
======================================================================

ollama create copies the layers into ~/.ollama/models/blobs/ and creates a manifest itself. Do not manually copy files into ~/.ollama/models/ — Ollama stores blobs by sha256, and a manual copy will break its index.


Troubleshooting

RepositoryNotFoundError

The repo does not exist on HuggingFace. Some models are published elsewhere — e.g. xai/grok-* lives behind the xAI API rather than HF, and this pipeline cannot fetch it.

GatedRepoError

The model requires accepting a license. Open the model page on HF, click "Agree and access", and make sure the token in .env has access to that repo.

No .safetensors files found

The repo only ships weights in the legacy pytorch_model.bin format. By default .bin is excluded to avoid duplicating safetensors. Remove *.bin and *.pth from IGNORE_PATTERNS in hf2ollama.py and rerun.

Out of disk or VRAM

f16 for a 70B model is roughly 140 GB on disk and the same in VRAM when loading. Two ways out:

  • Convert to f16 first, then quantize to Q4_K_M (see below) — Q4_K_M shrinks the file ~4× with minimal quality loss.
  • Look for a community-built GGUF of the same model (<org>/<name>-GGUF) — then --list will show available quants, and --quant Q4_K_M downloads just the one you want.

Manual quantization (optional)

If you've converted to f16 and want a smaller Q4_K_M:

cd llama.cpp   # or wherever HF2OLLAMA_LLAMA_CPP_DIR points
cmake -B build && cmake --build build --target llama-quantize -j
./build/bin/llama-quantize \
    <workspace>/hf/<org>/<name>/<name>.f16.gguf \
    <workspace>/hf/<org>/<name>/<name>.Q4_K_M.gguf \
    Q4_K_M

Then create a new Modelfile pointing at the Q4_K_M.gguf and run ollama create with a new name.

Project details


Download files

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

Source Distribution

hf2ollama-0.0.3.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

hf2ollama-0.0.3-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file hf2ollama-0.0.3.tar.gz.

File metadata

  • Download URL: hf2ollama-0.0.3.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hf2ollama-0.0.3.tar.gz
Algorithm Hash digest
SHA256 cf2b2d084699ad4032decc79662f417c54cb741ae0ccd35aee0dc1b5ef360fda
MD5 80f174f6eb7cd0db1bb6dbbeac35dd72
BLAKE2b-256 e4a7f87e68004cda1c028383c2c51715b99e68b5892576138308752e60193ed0

See more details on using hashes here.

Provenance

The following attestation bundles were made for hf2ollama-0.0.3.tar.gz:

Publisher: publish.yml on wachawo/hf2ollama

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hf2ollama-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: hf2ollama-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hf2ollama-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a9bfac6853eef55af2a7af99e1048a1a19aa3233ca1c8b6ca8038419e59d217c
MD5 e98e04987efe9e36bc34b829653d8743
BLAKE2b-256 1f7ff999d314cc2d89d3fa79d9247c0fcb5212b5fab689119768d374ab019bd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for hf2ollama-0.0.3-py3-none-any.whl:

Publisher: publish.yml on wachawo/hf2ollama

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page