Skip to content

Commit 49fbf23

Browse files
feat: add optional host argument for model download (#56)
* feat(download-model): add optional host argument for model download * feat: update optional host argument documentation for model download --------- Co-authored-by: Kyrian Obikwelu <[email protected]>
1 parent f3865ee commit 49fbf23

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

docs/getting-started.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Arguments:
7373
can use the shorthand `-q` instead of `--quantized`. Example: `--quantized=false`, `-q false`.
7474
- `--model-filename=<filename>`: Specify the exact model filename to download (without the `.onnx` suffix. Eg. "
7575
model" or "model_quantized".
76+
- `--host=<remote_host>`: Choose a different model hub host. Instead of fetching models from the Hugging Face model
77+
hub, you can use a different host. You can use a private model hub or mirror the original hub.
78+
Eg. `--host=https://hf.co`
7679

7780
The `download` command will download the model weights and save them to the cache directory. The next time you use the
7881
model, TransformersPHP will use the cached weights instead of downloading them again.

src/Commands/DownloadModelCommand.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ protected function configure(): void
5959
'The filename of the exact model weights version to download.',
6060
null
6161
);
62+
63+
$this->addOption(
64+
'host',
65+
null,
66+
InputOption::VALUE_OPTIONAL,
67+
'The host to download the model from.',
68+
null
69+
);
6270

6371
}
6472

@@ -71,9 +79,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7179
$quantized = filter_var($input->getOption('quantized'), FILTER_VALIDATE_BOOLEAN);
7280
$task = $input->getArgument('task');
7381
$modelFilename = $input->getOption('model-filename');
74-
82+
$host = $input->getOption('host') ?? Transformers::$remoteHost;
83+
7584
Transformers::setup()
7685
->setCacheDir($cacheDir)
86+
->setRemoteHost(rtrim($host,'/'))
7787
->apply();
7888

7989
try {
@@ -152,4 +162,4 @@ protected function askToStar(InputInterface $input, OutputInterface $output): vo
152162
$output->writeln('✔ That\'s okay. You can always star the repo later.');
153163
}
154164
}
155-
}
165+
}

0 commit comments

Comments
 (0)