Skip to content

Commit

Permalink
feat: add optional host argument for model download (#56)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
k99k5 and CodeWithKyrian authored Aug 14, 2024
1 parent f3865ee commit 49fbf23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ Arguments:
can use the shorthand `-q` instead of `--quantized`. Example: `--quantized=false`, `-q false`.
- `--model-filename=<filename>`: Specify the exact model filename to download (without the `.onnx` suffix. Eg. "
model" or "model_quantized".
- `--host=<remote_host>`: Choose a different model hub host. Instead of fetching models from the Hugging Face model
hub, you can use a different host. You can use a private model hub or mirror the original hub.
Eg. `--host=https://hf.co`

The `download` command will download the model weights and save them to the cache directory. The next time you use the
model, TransformersPHP will use the cached weights instead of downloading them again.
Expand Down
14 changes: 12 additions & 2 deletions src/Commands/DownloadModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ protected function configure(): void
'The filename of the exact model weights version to download.',
null
);

$this->addOption(
'host',
null,
InputOption::VALUE_OPTIONAL,
'The host to download the model from.',
null
);

}

Expand All @@ -71,9 +79,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$quantized = filter_var($input->getOption('quantized'), FILTER_VALIDATE_BOOLEAN);
$task = $input->getArgument('task');
$modelFilename = $input->getOption('model-filename');

$host = $input->getOption('host') ?? Transformers::$remoteHost;

Transformers::setup()
->setCacheDir($cacheDir)
->setRemoteHost(rtrim($host,'/'))
->apply();

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

0 comments on commit 49fbf23

Please sign in to comment.