Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HF token in CLI for private and gated repos #1984

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 7 additions & 0 deletions optimum/commands/export/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ def parse_args_onnx(parser):
action="store_true",
help="Allows to use custom code for the modeling hosted in the model repository. This option should only be set for repositories you trust and in which you have read the code, as it will execute on your local machine arbitrary code present in the model repository.",
)
optional_group.add_argument(
"--token",
type=str,
default=None,
help="Hugging Face API token to use for authentication.",
)
optional_group.add_argument(
"--pad_token_id",
type=int,
Expand Down Expand Up @@ -277,6 +283,7 @@ def run(self):
atol=self.args.atol,
cache_dir=self.args.cache_dir,
trust_remote_code=self.args.trust_remote_code,
token=self.args.token,
pad_token_id=self.args.pad_token_id,
for_ort=self.args.for_ort,
use_subprocess=True,
Expand Down
18 changes: 17 additions & 1 deletion tests/exporters/onnx/test_exporters_onnx_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@
ONNX_DECODER_WITH_PAST_NAME,
ONNX_ENCODER_NAME,
)
from optimum.utils.testing_utils import grid_parameters, require_diffusers, require_sentence_transformers, require_timm
from optimum.utils.testing_utils import (
grid_parameters,
require_diffusers,
require_hf_token,
require_sentence_transformers,
require_timm,
)


if is_torch_available():
Expand Down Expand Up @@ -730,3 +736,13 @@ def test_complex_synonyms(self):
model.save_pretrained(tmpdir_in)

main_export(model_name_or_path=tmpdir_in, output=tmpdir_out, task="text-classification")

@require_hf_token
def test_hf_token(self):
with TemporaryDirectory() as tmpdirname:
token = os.environ.get("HF_AUTH_TOKEN")
subprocess.run(
f"python3 -m optimum.exporters.onnx --model optimum-internal-testing/tiny-random-phi-private {tmpdirname} --token {token}",
shell=True,
check=True,
)
Loading