Skip to content

Commit 08ecbbe

Browse files
committed
convert: add --remote option
1 parent 7f61d0b commit 08ecbbe

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

convert_hf_to_gguf.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5470,6 +5470,10 @@ def parse_args() -> argparse.Namespace:
54705470
"--print-supported-models", action="store_true",
54715471
help="Print the supported models"
54725472
)
5473+
parser.add_argument(
5474+
"--remote", action="store_true",
5475+
help="(Experimental) Read safetensors file remotely without downloading to disk. Config and tokenizer files will still be downloaded. To use this feature, you need to specify Hugging Face model repo name instead of a local directory. For example: 'HuggingFaceTB/SmolLM2-1.7B'",
5476+
)
54735477

54745478
args = parser.parse_args()
54755479
if not args.print_supported_models and args.model is None:
@@ -5510,6 +5514,14 @@ def main() -> None:
55105514

55115515
dir_model = args.model
55125516

5517+
if args.remote:
5518+
from huggingface_hub import snapshot_download
5519+
local_dir = snapshot_download(
5520+
repo_id=str(dir_model),
5521+
allow_patterns=["LICENSE", "*.json", "*.md", "*.txt", "tokenizer.model"])
5522+
dir_model = Path(local_dir)
5523+
logger.info(f"Downloaded config and tokenizer to {local_dir}")
5524+
55135525
if not dir_model.is_dir():
55145526
logger.error(f'Error: {args.model} is not a directory')
55155527
sys.exit(1)
@@ -5531,6 +5543,9 @@ def main() -> None:
55315543

55325544
if args.outfile is not None:
55335545
fname_out = args.outfile
5546+
elif args.remote:
5547+
# if remote, use the model ID as the output file name
5548+
fname_out = Path("./" + str(args.model).replace("/", "-") + "-{ftype}.gguf")
55345549
else:
55355550
fname_out = dir_model
55365551

0 commit comments

Comments
 (0)