Add token arugment in example scripts (#25172)
* fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
@@ -26,6 +26,7 @@ Text models: BERT, ROBERTa (https://huggingface.co/models?filter=fill-mask)
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional
|
||||
|
||||
@@ -92,15 +93,21 @@ class ModelArguments:
|
||||
default=True,
|
||||
metadata={"help": "Whether to use one of the fast tokenizer (backed by the tokenizers library) or not."},
|
||||
)
|
||||
use_auth_token: bool = field(
|
||||
default=False,
|
||||
token: str = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": (
|
||||
"Will use the token generated when running `huggingface-cli login` (necessary to use this script "
|
||||
"with private models)."
|
||||
"The token to use as HTTP bearer authorization for remote files. If not specified, will use the token "
|
||||
"generated when running `huggingface-cli login` (stored in `~/.huggingface`)."
|
||||
)
|
||||
},
|
||||
)
|
||||
use_auth_token: bool = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": "The `use_auth_token` argument is deprecated and will be removed in v4.34. Please use `token`."
|
||||
},
|
||||
)
|
||||
freeze_vision_model: bool = field(
|
||||
default=False, metadata={"help": "Whether to freeze the vision model parameters or not."}
|
||||
)
|
||||
@@ -245,6 +252,12 @@ def main():
|
||||
else:
|
||||
model_args, data_args, training_args = parser.parse_args_into_dataclasses()
|
||||
|
||||
if model_args.use_auth_token is not None:
|
||||
warnings.warn("The `use_auth_token` argument is deprecated and will be removed in v4.34.", FutureWarning)
|
||||
if model_args.token is not None:
|
||||
raise ValueError("`token` and `use_auth_token` are both specified. Please set only the argument `token`.")
|
||||
model_args.token = model_args.use_auth_token
|
||||
|
||||
if model_args.model_name_or_path is not None:
|
||||
if model_args.vision_model_name_or_path is not None or model_args.text_model_name_or_path is not None:
|
||||
raise ValueError(
|
||||
@@ -315,7 +328,7 @@ def main():
|
||||
cache_dir=model_args.cache_dir,
|
||||
keep_in_memory=False,
|
||||
data_dir=data_args.data_dir,
|
||||
use_auth_token=True if model_args.use_auth_token else None,
|
||||
token=model_args.token,
|
||||
)
|
||||
else:
|
||||
data_files = {}
|
||||
@@ -332,7 +345,7 @@ def main():
|
||||
extension,
|
||||
data_files=data_files,
|
||||
cache_dir=model_args.cache_dir,
|
||||
use_auth_token=True if model_args.use_auth_token else None,
|
||||
token=model_args.token,
|
||||
)
|
||||
# See more about loading any type of standard or custom dataset (from files, python dict, pandas DataFrame, etc) at
|
||||
# https://huggingface.co/docs/datasets/loading_datasets.html.
|
||||
@@ -362,14 +375,14 @@ def main():
|
||||
model_args.image_processor_name or model_args.model_name_or_path,
|
||||
cache_dir=model_args.cache_dir,
|
||||
revision=model_args.model_revision,
|
||||
token=True if model_args.use_auth_token else None,
|
||||
token=model_args.token,
|
||||
)
|
||||
with training_args.strategy.scope():
|
||||
model = TFAutoModel.from_pretrained(
|
||||
model_args.model_name_or_path,
|
||||
cache_dir=model_args.cache_dir,
|
||||
revision=model_args.model_revision,
|
||||
token=True if model_args.use_auth_token else None,
|
||||
token=model_args.token,
|
||||
)
|
||||
else:
|
||||
# Load image_processor, in this script we only use this to get the mean and std for normalization.
|
||||
@@ -377,14 +390,14 @@ def main():
|
||||
model_args.image_processor_name or model_args.vision_model_name_or_path,
|
||||
cache_dir=model_args.cache_dir,
|
||||
revision=model_args.model_revision,
|
||||
token=True if model_args.use_auth_token else None,
|
||||
token=model_args.token,
|
||||
)
|
||||
with training_args.strategy.scope():
|
||||
model = TFVisionTextDualEncoderModel.from_vision_text_pretrained(
|
||||
vision_model_name_or_path=model_args.vision_model_name_or_path,
|
||||
text_model_name_or_path=model_args.text_model_name_or_path,
|
||||
cache_dir=model_args.cache_dir,
|
||||
token=True if model_args.use_auth_token else None,
|
||||
token=model_args.token,
|
||||
)
|
||||
config = model.config
|
||||
|
||||
|
||||
Reference in New Issue
Block a user