diff --git a/README.md b/README.md index 952ba3efb..10e150069 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 diff --git a/gpu/README.md b/gpu/README.md index da4b25925..3498e9c25 100755 --- a/gpu/README.md +++ b/gpu/README.md @@ -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 diff --git a/setup_env.py b/setup_env.py index 12622d201..f67f3189f 100644 --- a/setup_env.py +++ b/setup_env.py @@ -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) diff --git a/tests/test_setup_env_download.py b/tests/test_setup_env_download.py new file mode 100644 index 000000000..09cd66a85 --- /dev/null +++ b/tests/test_setup_env_download.py @@ -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()