Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pip install -r requirements.txt
3. Build the project
```bash
# Manually download the model and run with local path
huggingface-cli download microsoft/BitNet-b1.58-2B-4T-gguf --local-dir models/BitNet-b1.58-2B-4T
hf download microsoft/BitNet-b1.58-2B-4T-gguf --local-dir models/BitNet-b1.58-2B-4T
python setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s

```
Expand Down Expand Up @@ -382,7 +382,7 @@ python utils/e2e_benchmark.py -m models/dummy-bitnet-125m.tl1.gguf -p 512 -n 128

```sh
# Prepare the .safetensors model file
huggingface-cli download microsoft/bitnet-b1.58-2B-4T-bf16 --local-dir ./models/bitnet-b1.58-2B-4T-bf16
hf download microsoft/bitnet-b1.58-2B-4T-bf16 --local-dir ./models/bitnet-b1.58-2B-4T-bf16

# Convert to gguf model
python ./utils/convert-helper-bitnet.py ./models/bitnet-b1.58-2B-4T-bf16
Expand Down
2 changes: 1 addition & 1 deletion gpu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ End-to-end inference:
```bash
# Download and convert the BitNet-b1.58-2B model
mkdir checkpoints
huggingface-cli download microsoft/bitnet-b1.58-2B-4T-bf16 --local-dir ./checkpoints/bitnet-b1.58-2B-4T-bf16
hf download microsoft/bitnet-b1.58-2B-4T-bf16 --local-dir ./checkpoints/bitnet-b1.58-2B-4T-bf16
python ./convert_safetensors.py --safetensors_file ./checkpoints/bitnet-b1.58-2B-4T-bf16/model.safetensors --output checkpoints/model_state.pt --model_name 2B
python ./convert_checkpoint.py --input ./checkpoints/model_state.pt
rm ./checkpoints/model_state.pt
Expand Down
2 changes: 1 addition & 1 deletion setup_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def prepare_model():
model_dir = os.path.join(model_dir, SUPPORTED_HF_MODELS[hf_url]["model_name"])
Path(model_dir).mkdir(parents=True, exist_ok=True)
logging.info(f"Downloading model {hf_url} from HuggingFace to {model_dir}...")
run_command(["huggingface-cli", "download", hf_url, "--local-dir", model_dir], log_step="download_model")
run_command(["hf", "download", hf_url, "--local-dir", model_dir], log_step="download_model")
elif not os.path.exists(model_dir):
logging.error(f"Model directory {model_dir} does not exist.")
sys.exit(1)
Expand Down
61 changes: 61 additions & 0 deletions tests/test_setup_env_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Regression test for issue #560.

`setup_env.py` must download models with the current Hugging Face CLI entry
point (`hf`). The legacy `huggingface-cli` command was removed from recent
`huggingface_hub` releases, so the documented `-hr/--hf-repo` download flow
fails with "command not found" when the script still shells out to it.
"""

import os
import sys
import types
import unittest
from pathlib import Path
from unittest import mock

REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if REPO_ROOT not in sys.path:
sys.path.insert(0, REPO_ROOT)

import setup_env # noqa: E402

DOWNLOAD_LOG_STEP = "download_model"
LEGACY_CLI = "huggingface-cli"
CURRENT_CLI = "hf"


class _StopAfterDownload(Exception):
"""Sentinel to halt prepare_model() right after the download command."""


class DownloadCommandTest(unittest.TestCase):
def test_download_uses_current_hf_cli(self):
captured = []

def fake_run_command(command, shell=False, log_step=None):
captured.append(command)
if log_step == DOWNLOAD_LOG_STEP:
raise _StopAfterDownload

hf_repo = next(iter(setup_env.SUPPORTED_HF_MODELS))
fake_args = types.SimpleNamespace(
hf_repo=hf_repo,
model_dir="models",
quant_type="i2_s",
quant_embd=False,
)

with mock.patch.object(setup_env, "run_command", fake_run_command), \
mock.patch.object(setup_env, "args", fake_args, create=True), \
mock.patch.object(Path, "mkdir", lambda *a, **k: None):
with self.assertRaises(_StopAfterDownload):
setup_env.prepare_model()

download_cmd = captured[-1]
self.assertEqual(download_cmd[0], CURRENT_CLI)
self.assertEqual(download_cmd[1], "download")
self.assertNotIn(LEGACY_CLI, download_cmd)


if __name__ == "__main__":
unittest.main()