Black preview (#17217)
* Black preview * Fixup too! * Fix check copies * Use the same version as the CI * Bump black
This commit is contained in:
@@ -101,15 +101,19 @@ class ModelArguments:
|
||||
use_auth_token: bool = field(
|
||||
default=False,
|
||||
metadata={
|
||||
"help": "Will use the token generated when running `transformers-cli login` (necessary to use this script "
|
||||
"with private models)."
|
||||
"help": (
|
||||
"Will use the token generated when running `transformers-cli login` (necessary to use this script "
|
||||
"with private models)."
|
||||
)
|
||||
},
|
||||
)
|
||||
resize_position_embeddings: Optional[bool] = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": "Whether to automatically resize the position embeddings if `max_source_length` exceeds "
|
||||
"the model's position embeddings."
|
||||
"help": (
|
||||
"Whether to automatically resize the position embeddings if `max_source_length` exceeds "
|
||||
"the model's position embeddings."
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -142,14 +146,15 @@ class DataTrainingArguments:
|
||||
validation_file: Optional[str] = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": "An optional input evaluation data file to evaluate the metrics (rouge) on "
|
||||
"(a jsonlines or csv file)."
|
||||
"help": (
|
||||
"An optional input evaluation data file to evaluate the metrics (rouge) on (a jsonlines or csv file)."
|
||||
)
|
||||
},
|
||||
)
|
||||
test_file: Optional[str] = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": "An optional input test data file to evaluate the metrics (rouge) on " "(a jsonlines or csv file)."
|
||||
"help": "An optional input test data file to evaluate the metrics (rouge) on (a jsonlines or csv file)."
|
||||
},
|
||||
)
|
||||
overwrite_cache: bool = field(
|
||||
@@ -162,60 +167,76 @@ class DataTrainingArguments:
|
||||
max_source_length: Optional[int] = field(
|
||||
default=1024,
|
||||
metadata={
|
||||
"help": "The maximum total input sequence length after tokenization. Sequences longer "
|
||||
"than this will be truncated, sequences shorter will be padded."
|
||||
"help": (
|
||||
"The maximum total input sequence length after tokenization. Sequences longer "
|
||||
"than this will be truncated, sequences shorter will be padded."
|
||||
)
|
||||
},
|
||||
)
|
||||
max_target_length: Optional[int] = field(
|
||||
default=128,
|
||||
metadata={
|
||||
"help": "The maximum total sequence length for target text after tokenization. Sequences longer "
|
||||
"than this will be truncated, sequences shorter will be padded."
|
||||
"help": (
|
||||
"The maximum total sequence length for target text after tokenization. Sequences longer "
|
||||
"than this will be truncated, sequences shorter will be padded."
|
||||
)
|
||||
},
|
||||
)
|
||||
val_max_target_length: Optional[int] = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": "The maximum total sequence length for validation target text after tokenization. Sequences longer "
|
||||
"than this will be truncated, sequences shorter will be padded. Will default to `max_target_length`."
|
||||
"This argument is also used to override the ``max_length`` param of ``model.generate``, which is used "
|
||||
"during ``evaluate`` and ``predict``."
|
||||
"help": (
|
||||
"The maximum total sequence length for validation target text after tokenization. Sequences longer "
|
||||
"than this will be truncated, sequences shorter will be padded. Will default to `max_target_length`."
|
||||
"This argument is also used to override the ``max_length`` param of ``model.generate``, which is used "
|
||||
"during ``evaluate`` and ``predict``."
|
||||
)
|
||||
},
|
||||
)
|
||||
pad_to_max_length: bool = field(
|
||||
default=False,
|
||||
metadata={
|
||||
"help": "Whether to pad all samples to model maximum sentence length. "
|
||||
"If False, will pad the samples dynamically when batching to the maximum length in the batch. More "
|
||||
"efficient on GPU but very bad for TPU."
|
||||
"help": (
|
||||
"Whether to pad all samples to model maximum sentence length. "
|
||||
"If False, will pad the samples dynamically when batching to the maximum length in the batch. More "
|
||||
"efficient on GPU but very bad for TPU."
|
||||
)
|
||||
},
|
||||
)
|
||||
max_train_samples: Optional[int] = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": "For debugging purposes or quicker training, truncate the number of training examples to this "
|
||||
"value if set."
|
||||
"help": (
|
||||
"For debugging purposes or quicker training, truncate the number of training examples to this "
|
||||
"value if set."
|
||||
)
|
||||
},
|
||||
)
|
||||
max_eval_samples: Optional[int] = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": "For debugging purposes or quicker training, truncate the number of evaluation examples to this "
|
||||
"value if set."
|
||||
"help": (
|
||||
"For debugging purposes or quicker training, truncate the number of evaluation examples to this "
|
||||
"value if set."
|
||||
)
|
||||
},
|
||||
)
|
||||
max_predict_samples: Optional[int] = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": "For debugging purposes or quicker training, truncate the number of prediction examples to this "
|
||||
"value if set."
|
||||
"help": (
|
||||
"For debugging purposes or quicker training, truncate the number of prediction examples to this "
|
||||
"value if set."
|
||||
)
|
||||
},
|
||||
)
|
||||
num_beams: Optional[int] = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": "Number of beams to use for evaluation. This argument will be passed to ``model.generate``, "
|
||||
"which is used during ``evaluate`` and ``predict``."
|
||||
"help": (
|
||||
"Number of beams to use for evaluation. This argument will be passed to ``model.generate``, "
|
||||
"which is used during ``evaluate`` and ``predict``."
|
||||
)
|
||||
},
|
||||
)
|
||||
ignore_pad_token_for_loss: bool = field(
|
||||
@@ -231,9 +252,11 @@ class DataTrainingArguments:
|
||||
forced_bos_token: Optional[str] = field(
|
||||
default=None,
|
||||
metadata={
|
||||
"help": "The token to force as the first generated token after the decoder_start_token_id."
|
||||
"Useful for multilingual models like mBART where the first generated token"
|
||||
"needs to be the target language token (Usually it is the target language token)"
|
||||
"help": (
|
||||
"The token to force as the first generated token after the decoder_start_token_id."
|
||||
"Useful for multilingual models like mBART where the first generated token"
|
||||
"needs to be the target language token (Usually it is the target language token)"
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -410,17 +433,18 @@ def main():
|
||||
):
|
||||
if model_args.resize_position_embeddings is None:
|
||||
logger.warning(
|
||||
f"Increasing the model's number of position embedding vectors from {model.config.max_position_embeddings} "
|
||||
f"to {data_args.max_source_length}."
|
||||
"Increasing the model's number of position embedding vectors from"
|
||||
f" {model.config.max_position_embeddings} to {data_args.max_source_length}."
|
||||
)
|
||||
model.resize_position_embeddings(data_args.max_source_length)
|
||||
elif model_args.resize_position_embeddings:
|
||||
model.resize_position_embeddings(data_args.max_source_length)
|
||||
else:
|
||||
raise ValueError(
|
||||
f"`--max_source_length` is set to {data_args.max_source_length}, but the model only has {model.config.max_position_embeddings}"
|
||||
f" position encodings. Consider either reducing `--max_source_length` to {model.config.max_position_embeddings} or to automatically "
|
||||
"resize the model's position encodings by passing `--resize_position_embeddings`."
|
||||
f"`--max_source_length` is set to {data_args.max_source_length}, but the model only has"
|
||||
f" {model.config.max_position_embeddings} position encodings. Consider either reducing"
|
||||
f" `--max_source_length` to {model.config.max_position_embeddings} or to automatically resize the"
|
||||
" model's position encodings by passing `--resize_position_embeddings`."
|
||||
)
|
||||
|
||||
prefix = data_args.source_prefix if data_args.source_prefix is not None else ""
|
||||
|
||||
@@ -111,20 +111,22 @@ def parse_args():
|
||||
"--ignore_pad_token_for_loss",
|
||||
type=bool,
|
||||
default=True,
|
||||
help="Whether to ignore the tokens corresponding to " "padded labels in the loss computation or not.",
|
||||
help="Whether to ignore the tokens corresponding to padded labels in the loss computation or not.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--max_source_length",
|
||||
type=int,
|
||||
default=1024,
|
||||
help="The maximum total input sequence length after "
|
||||
"tokenization.Sequences longer than this will be truncated, sequences shorter will be padded.",
|
||||
help=(
|
||||
"The maximum total input sequence length after "
|
||||
"tokenization.Sequences longer than this will be truncated, sequences shorter will be padded."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--source_prefix",
|
||||
type=str,
|
||||
default=None,
|
||||
help="A prefix to add before every source text " "(useful for T5 models).",
|
||||
help="A prefix to add before every source text (useful for T5 models).",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--preprocessing_num_workers",
|
||||
@@ -139,18 +141,22 @@ def parse_args():
|
||||
"--max_target_length",
|
||||
type=int,
|
||||
default=128,
|
||||
help="The maximum total sequence length for target text after "
|
||||
"tokenization. Sequences longer than this will be truncated, sequences shorter will be padded."
|
||||
"during ``evaluate`` and ``predict``.",
|
||||
help=(
|
||||
"The maximum total sequence length for target text after "
|
||||
"tokenization. Sequences longer than this will be truncated, sequences shorter will be padded."
|
||||
"during ``evaluate`` and ``predict``."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--val_max_target_length",
|
||||
type=int,
|
||||
default=None,
|
||||
help="The maximum total sequence length for validation "
|
||||
"target text after tokenization.Sequences longer than this will be truncated, sequences shorter will be "
|
||||
"padded. Will default to `max_target_length`.This argument is also used to override the ``max_length`` "
|
||||
"param of ``model.generate``, which is used during ``evaluate`` and ``predict``.",
|
||||
help=(
|
||||
"The maximum total sequence length for validation "
|
||||
"target text after tokenization.Sequences longer than this will be truncated, sequences shorter will be "
|
||||
"padded. Will default to `max_target_length`.This argument is also used to override the ``max_length`` "
|
||||
"param of ``model.generate``, which is used during ``evaluate`` and ``predict``."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--max_length",
|
||||
@@ -165,8 +171,10 @@ def parse_args():
|
||||
"--num_beams",
|
||||
type=int,
|
||||
default=None,
|
||||
help="Number of beams to use for evaluation. This argument will be "
|
||||
"passed to ``model.generate``, which is used during ``evaluate`` and ``predict``.",
|
||||
help=(
|
||||
"Number of beams to use for evaluation. This argument will be "
|
||||
"passed to ``model.generate``, which is used during ``evaluate`` and ``predict``."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--pad_to_max_length",
|
||||
|
||||
Reference in New Issue
Block a user