Allow trust_remote_code in example scripts (#25248)
* pytorch examples * pytorch mim no trainer * cookiecutter * flax examples * missed line in pytorch run_glue * tensorflow examples * tensorflow run_clip * tensorflow run_mlm * tensorflow run_ner * tensorflow run_clm * pytorch example from_configs * pytorch no trainer examples * Revert "tensorflow run_clip" This reverts commit 261f86ac1f1c9e05dd3fd0291e1a1f8e573781d5. * fix: duplicated argument
This commit is contained in:
@@ -95,6 +95,16 @@ class ModelArguments:
|
||||
"help": "The `use_auth_token` argument is deprecated and will be removed in v4.34. Please use `token`."
|
||||
},
|
||||
)
|
||||
trust_remote_code: bool = field(
|
||||
default=False,
|
||||
metadata={
|
||||
"help": (
|
||||
"Whether or not to allow for custom models defined on the Hub in their own modeling files. This option"
|
||||
"should only be set to `True` for repositories you trust and in which you have read the code, as it will"
|
||||
"execute code present on the Hub on your local machine."
|
||||
)
|
||||
},
|
||||
)
|
||||
ignore_mismatched_sizes: bool = field(
|
||||
default=False,
|
||||
metadata={"help": "Will enable to load a pretrained model whose head dimensions are different."},
|
||||
@@ -362,6 +372,7 @@ def main():
|
||||
cache_dir=model_args.cache_dir,
|
||||
revision=model_args.model_revision,
|
||||
token=model_args.token,
|
||||
trust_remote_code=model_args.trust_remote_code,
|
||||
)
|
||||
|
||||
tokenizer_name_or_path = model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path
|
||||
@@ -372,6 +383,7 @@ def main():
|
||||
use_fast=True,
|
||||
revision=model_args.model_revision,
|
||||
token=model_args.token,
|
||||
trust_remote_code=model_args.trust_remote_code,
|
||||
add_prefix_space=True,
|
||||
)
|
||||
else:
|
||||
@@ -381,6 +393,7 @@ def main():
|
||||
use_fast=True,
|
||||
revision=model_args.model_revision,
|
||||
token=model_args.token,
|
||||
trust_remote_code=model_args.trust_remote_code,
|
||||
)
|
||||
|
||||
model = AutoModelForTokenClassification.from_pretrained(
|
||||
@@ -390,6 +403,7 @@ def main():
|
||||
cache_dir=model_args.cache_dir,
|
||||
revision=model_args.model_revision,
|
||||
token=model_args.token,
|
||||
trust_remote_code=model_args.trust_remote_code,
|
||||
ignore_mismatched_sizes=model_args.ignore_mismatched_sizes,
|
||||
)
|
||||
|
||||
|
||||
@@ -210,6 +210,16 @@ def parse_args():
|
||||
"--hub_model_id", type=str, help="The name of the repository to keep in sync with the local `output_dir`."
|
||||
)
|
||||
parser.add_argument("--hub_token", type=str, help="The token to use to push to the Model Hub.")
|
||||
parser.add_argument(
|
||||
"--trust_remote_code",
|
||||
type=bool,
|
||||
default=False,
|
||||
help=(
|
||||
"Whether or not to allow for custom models defined on the Hub in their own modeling files. This option"
|
||||
"should only be set to `True` for repositories you trust and in which you have read the code, as it will"
|
||||
"execute code present on the Hub on your local machine."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--checkpointing_steps",
|
||||
type=str,
|
||||
@@ -388,9 +398,13 @@ def main():
|
||||
# In distributed training, the .from_pretrained methods guarantee that only one local process can concurrently
|
||||
# download model & vocab.
|
||||
if args.config_name:
|
||||
config = AutoConfig.from_pretrained(args.config_name, num_labels=num_labels)
|
||||
config = AutoConfig.from_pretrained(
|
||||
args.config_name, num_labels=num_labels, trust_remote_code=args.trust_remote_code
|
||||
)
|
||||
elif args.model_name_or_path:
|
||||
config = AutoConfig.from_pretrained(args.model_name_or_path, num_labels=num_labels)
|
||||
config = AutoConfig.from_pretrained(
|
||||
args.model_name_or_path, num_labels=num_labels, trust_remote_code=args.trust_remote_code
|
||||
)
|
||||
else:
|
||||
config = CONFIG_MAPPING[args.model_type]()
|
||||
logger.warning("You are instantiating a new config instance from scratch.")
|
||||
@@ -403,9 +417,13 @@ def main():
|
||||
)
|
||||
|
||||
if config.model_type in {"bloom", "gpt2", "roberta"}:
|
||||
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name_or_path, use_fast=True, add_prefix_space=True)
|
||||
tokenizer = AutoTokenizer.from_pretrained(
|
||||
tokenizer_name_or_path, use_fast=True, add_prefix_space=True, trust_remote_code=args.trust_remote_code
|
||||
)
|
||||
else:
|
||||
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name_or_path, use_fast=True)
|
||||
tokenizer = AutoTokenizer.from_pretrained(
|
||||
tokenizer_name_or_path, use_fast=True, trust_remote_code=args.trust_remote_code
|
||||
)
|
||||
|
||||
if args.model_name_or_path:
|
||||
model = AutoModelForTokenClassification.from_pretrained(
|
||||
@@ -413,10 +431,11 @@ def main():
|
||||
from_tf=bool(".ckpt" in args.model_name_or_path),
|
||||
config=config,
|
||||
ignore_mismatched_sizes=args.ignore_mismatched_sizes,
|
||||
trust_remote_code=args.trust_remote_code,
|
||||
)
|
||||
else:
|
||||
logger.info("Training new model from scratch")
|
||||
model = AutoModelForTokenClassification.from_config(config)
|
||||
model = AutoModelForTokenClassification.from_config(config, trust_remote_code=args.trust_remote_code)
|
||||
|
||||
# We resize the embeddings only when necessary to avoid index errors. If you are creating a model from scratch
|
||||
# on a small vocab and want a smaller embedding size, remove this test.
|
||||
|
||||
Reference in New Issue
Block a user