Skip to content
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
4 changes: 2 additions & 2 deletions benchmark_v2/framework/benchmark_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def save_results(self, model_name: str, results: dict, timestamp: str = "", summ
os.makedirs(model_dir, exist_ok=True)

# Create filename with timestamp
timestamp = timestamp if timestamp else datetime.now().strftime("%Y%m%d_%H%M%S")
timestamp = timestamp or datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{model_name}_benchmark_{timestamp}.json"
filepath = os.path.join(model_dir, filename)

Expand Down Expand Up @@ -471,7 +471,7 @@ def push_results_to_hub(self, dataset_id: str, results: dict[Any, Any], timestam
f.write("\n".join(json_lines))

# NOTE: we expect the repository to already exist
timestamp = timestamp if timestamp else datetime.now().strftime("%Y%m%d_%H%M%S")
timestamp = timestamp or datetime.now().strftime("%Y%m%d_%H%M%S")
file_name = file_name + "/" + f"benchmark_run_{timestamp}.jsonl"
api.upload_file(
path_or_fileobj=jsonl_path,
Expand Down
6 changes: 2 additions & 4 deletions examples/modular-transformers/modeling_new_task_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,8 @@ def create_causal_mask_mapping(
# from `forward` call. If users run a `forward` call, we have no option to infer `is_first_iteration` because users may be
# running generation with custom loop. Thus we need to infer it in a `non-perfect` way
# NOTE: Determining prefill in that case requires checking data values, which is not compile-compatible.
is_first_iteration = (
is_first_iteration
if is_first_iteration
else (past_key_values is None or not past_key_values.is_initialized or pixel_values is not None)
is_first_iteration = is_first_iteration or (
past_key_values is None or not past_key_values.is_initialized or pixel_values is not None
)

if is_first_iteration or not kwargs.get("use_cache", True):
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/image-pretraining/run_mae.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __post_init__(self):
data_files["train"] = self.train_dir
if self.validation_dir is not None:
data_files["val"] = self.validation_dir
self.data_files = data_files if data_files else None
self.data_files = data_files or None


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/image-pretraining/run_mim.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __post_init__(self):
data_files["train"] = self.train_dir
if self.validation_dir is not None:
data_files["val"] = self.validation_dir
self.data_files = data_files if data_files else None
self.data_files = data_files or None


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/image-pretraining/run_mim_no_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def parse_args():
data_files["train"] = args.train_dir
if args.validation_dir is not None:
data_files["val"] = args.validation_dir
args.data_files = data_files if data_files else None
args.data_files = data_files or None

if args.push_to_hub:
assert args.output_dir is not None, "Need an `output_dir` to create a repo when `--push_to_hub` is passed."
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/multiple-choice/run_swag.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ def main():
# The .from_pretrained methods guarantee that only one local process can concurrently
# download model & vocab.
config = AutoConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
model_args.config_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
token=model_args.token,
trust_remote_code=model_args.trust_remote_code,
)
tokenizer = AutoTokenizer.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
model_args.tokenizer_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
use_fast=model_args.use_fast_tokenizer,
revision=model_args.model_revision,
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/question-answering/run_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,14 @@ def main():
# The .from_pretrained methods guarantee that only one local process can concurrently
# download model & vocab.
config = AutoConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
model_args.config_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
token=model_args.token,
trust_remote_code=model_args.trust_remote_code,
)
tokenizer = AutoTokenizer.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
model_args.tokenizer_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
use_fast=True,
revision=model_args.model_revision,
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/question-answering/run_qa_beam_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ def main():
# The .from_pretrained methods guarantee that only one local process can concurrently
# download model & vocab.
config = XLNetConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
model_args.config_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
token=model_args.token,
)
tokenizer = XLNetTokenizerFast.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
model_args.tokenizer_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
token=model_args.token,
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/question-answering/run_seq2seq_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,14 @@ def main():
# The .from_pretrained methods guarantee that only one local process can concurrently
# download model & vocab.
config = AutoConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
model_args.config_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
token=model_args.token,
trust_remote_code=model_args.trust_remote_code,
)
tokenizer = AutoTokenizer.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
model_args.tokenizer_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
use_fast=model_args.use_fast_tokenizer,
revision=model_args.model_revision,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def main():
# Distributed training:
# The .from_pretrained methods guarantee that only one local process can concurrently
config = AutoConfig.from_pretrained(
(model_args.config_name if model_args.config_name else model_args.model_name_or_path),
(model_args.config_name or model_args.model_name_or_path),
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
token=model_args.token,
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/summarization/run_summarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,14 @@ def main():
# The .from_pretrained methods guarantee that only one local process can concurrently
# download model & vocab.
config = AutoConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
model_args.config_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
token=model_args.token,
trust_remote_code=model_args.trust_remote_code,
)
tokenizer = AutoTokenizer.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
model_args.tokenizer_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
use_fast=model_args.use_fast_tokenizer,
revision=model_args.model_revision,
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/text-classification/run_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def main():
# In distributed training, the .from_pretrained methods guarantee that only one local process can concurrently
# download model & vocab.
config = AutoConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
model_args.config_name or model_args.model_name_or_path,
num_labels=num_labels,
finetuning_task="text-classification",
cache_dir=model_args.cache_dir,
Expand All @@ -491,7 +491,7 @@ def main():
logger.info("setting problem type to single label classification")

tokenizer = AutoTokenizer.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
model_args.tokenizer_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
use_fast=model_args.use_fast_tokenizer,
revision=model_args.model_revision,
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/text-classification/run_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def main():
# In distributed training, the .from_pretrained methods guarantee that only one local process can concurrently
# download model & vocab.
config = AutoConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
model_args.config_name or model_args.model_name_or_path,
num_labels=num_labels,
finetuning_task=data_args.task_name,
cache_dir=model_args.cache_dir,
Expand All @@ -370,7 +370,7 @@ def main():
trust_remote_code=model_args.trust_remote_code,
)
tokenizer = AutoTokenizer.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
model_args.tokenizer_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
use_fast=model_args.use_fast_tokenizer,
revision=model_args.model_revision,
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/text-classification/run_xnli.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def main():
# In distributed training, the .from_pretrained methods guarantee that only one local process can concurrently
# download model & vocab.
config = AutoConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
model_args.config_name or model_args.model_name_or_path,
num_labels=num_labels,
id2label={str(i): label for i, label in enumerate(label_list)},
label2id={label: i for i, label in enumerate(label_list)},
Expand All @@ -285,7 +285,7 @@ def main():
trust_remote_code=model_args.trust_remote_code,
)
tokenizer = AutoTokenizer.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
model_args.tokenizer_name or model_args.model_name_or_path,
do_lower_case=model_args.do_lower_case,
cache_dir=model_args.cache_dir,
use_fast=model_args.use_fast_tokenizer,
Expand Down
8 changes: 4 additions & 4 deletions examples/pytorch/text-generation/run_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ def prepare_xlm_input(args, model, tokenizer, prompt_text):


def prepare_xlnet_input(args, _, tokenizer, prompt_text):
prefix = args.prefix if args.prefix else args.padding_text if args.padding_text else PREFIX
prefix = args.prefix or (args.padding_text or PREFIX)
prompt_text = prefix + prompt_text
return prompt_text


def prepare_transfoxl_input(args, _, tokenizer, prompt_text):
prefix = args.prefix if args.prefix else args.padding_text if args.padding_text else PREFIX
prefix = args.prefix or (args.padding_text or PREFIX)
prompt_text = prefix + prompt_text
return prompt_text

Expand Down Expand Up @@ -366,7 +366,7 @@ def main():
args.length = adjust_length_to_model(args.length, max_sequence_length=max_seq_length)
logger.info(args)

prompt_text = args.prompt if args.prompt else input("Model prompt >>> ")
prompt_text = args.prompt or input("Model prompt >>> ")

# Different models need different input formatting and/or extra arguments
requires_preprocessing = args.model_type in PREPROCESSING_FUNCTIONS
Expand All @@ -380,7 +380,7 @@ def main():
preprocessed_prompt_text, add_special_tokens=False, return_tensors="pt", **tokenizer_kwargs
)
else:
prefix = args.prefix if args.prefix else args.padding_text
prefix = args.prefix or args.padding_text
encoded_prompt = tokenizer.encode(prefix + prompt_text, add_special_tokens=False, return_tensors="pt")
encoded_prompt = encoded_prompt.to(distributed_state.device)

Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/token-classification/run_ner.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def get_label_list(labels):
# The .from_pretrained methods guarantee that only one local process can concurrently
# download model & vocab.
config = AutoConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
model_args.config_name or model_args.model_name_or_path,
num_labels=num_labels,
finetuning_task=data_args.task_name,
cache_dir=model_args.cache_dir,
Expand All @@ -354,7 +354,7 @@ def get_label_list(labels):
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
tokenizer_name_or_path = model_args.tokenizer_name or model_args.model_name_or_path
if config.model_type in {"bloom", "gpt2", "roberta", "deberta"}:
tokenizer = AutoTokenizer.from_pretrained(
tokenizer_name_or_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def get_label_list(labels):
config = CONFIG_MAPPING[args.model_type]()
logger.warning("You are instantiating a new config instance from scratch.")

tokenizer_name_or_path = args.tokenizer_name if args.tokenizer_name else args.model_name_or_path
tokenizer_name_or_path = args.tokenizer_name or args.model_name_or_path
if not tokenizer_name_or_path:
raise ValueError(
"You are instantiating a new tokenizer from scratch. This is not supported by this script. "
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/translation/run_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@ def main():
# The .from_pretrained methods guarantee that only one local process can concurrently
# download model & vocab.
config = AutoConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
model_args.config_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
token=model_args.token,
trust_remote_code=model_args.trust_remote_code,
)
tokenizer = AutoTokenizer.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
model_args.tokenizer_name or model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
use_fast=model_args.use_fast_tokenizer,
revision=model_args.model_revision,
Expand Down
6 changes: 2 additions & 4 deletions src/transformers/data/metrics/squad_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def compute_predictions_logits(
end_logit=null_end_logit,
)
)
prelim_predictions = sorted(prelim_predictions, key=lambda x: (x.start_logit + x.end_logit), reverse=True)
prelim_predictions = sorted(prelim_predictions, key=lambda x: x.start_logit + x.end_logit, reverse=True)

_NbestPrediction = collections.namedtuple( # pylint: disable=invalid-name
"NbestPrediction", ["text", "start_logit", "end_logit"]
Expand Down Expand Up @@ -681,9 +681,7 @@ def compute_predictions_log_probs(
)
)

prelim_predictions = sorted(
prelim_predictions, key=lambda x: (x.start_log_prob + x.end_log_prob), reverse=True
)
prelim_predictions = sorted(prelim_predictions, key=lambda x: x.start_log_prob + x.end_log_prob, reverse=True)

seen_predictions = {}
nbest = []
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/integrations/integration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def run_hp_search_wandb(trainer, n_trials: int, direction: str, **kwargs) -> Bes
sweep_config["name"] = name

def _objective():
run = wandb.run if wandb.run else wandb.init()
run = wandb.run or wandb.init()
trainer.state.trial_name = run.name
run.config.update({"assignments": {}, "metric": metric})
config = wandb.config
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/modelcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def extract_hyperparameters_from_trainer(trainer):

if trainer.args.optim:
optimizer_name = trainer.args.optim
optimizer_args = trainer.args.optim_args if trainer.args.optim_args else "No additional optimizer arguments"
optimizer_args = trainer.args.optim_args or "No additional optimizer arguments"

if "adam" in optimizer_name.lower():
hyperparameters["optimizer"] = (
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/clap/feature_extraction_clap.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def __call__(
pipeline.
"""
truncation = truncation if truncation is not None else self.truncation
padding = padding if padding else self.padding
padding = padding or self.padding

if sampling_rate is not None:
if sampling_rate != self.sampling_rate:
Expand Down Expand Up @@ -331,7 +331,7 @@ def __call__(

# convert to mel spectrogram, truncate and pad if needed.
padded_inputs = [
self._get_input_mel(waveform, max_length if max_length else self.nb_max_samples, truncation, padding)
self._get_input_mel(waveform, max_length or self.nb_max_samples, truncation, padding)
for waveform in raw_speech
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@
r"depth_head\.scratch\.output_conv(\d+)(?:\.(\d+))?\.(weight|bias)": lambda m: (
f"head.conv{int(m[1]) + (int(m[2]) // 2 if m[2] else 0)}.{m[3]}" if m[1] == "2" else f"head.conv{m[1]}.{m[3]}"
),
r"depth_head\.scratch\.refinenet(\d+)\.out_conv\.(weight|bias)": lambda m: f"neck.fusion_stage.layers.{3 - (int(m[1]) - 1)}.projection.{m[2]}",
r"depth_head\.scratch\.refinenet(\d+)\.resConfUnit(\d+)\.conv(\d+)\.(weight|bias)": lambda m: f"neck.fusion_stage.layers.{3 - (int(m[1]) - 1)}.residual_layer{m[2]}.convolution{m[3]}.{m[4]}",
r"depth_head\.scratch\.refinenet(\d+)\.out_conv\.(weight|bias)": lambda m: (
f"neck.fusion_stage.layers.{3 - (int(m[1]) - 1)}.projection.{m[2]}"
),
r"depth_head\.scratch\.refinenet(\d+)\.resConfUnit(\d+)\.conv(\d+)\.(weight|bias)": lambda m: (
f"neck.fusion_stage.layers.{3 - (int(m[1]) - 1)}.residual_layer{m[2]}.convolution{m[3]}.{m[4]}"
),
}


Expand Down
Loading
Loading