Skip to content

Commit 88258ed

Browse files
cyyeverAhnJoonSung
authored andcommitted
Fix unnecessary single-item container checks (huggingface#41279)
Signed-off-by: Yuanyuan Chen <[email protected]>
1 parent 651afde commit 88258ed

File tree

45 files changed

+79
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+79
-84
lines changed

examples/legacy/pytorch-lightning/run_ner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ def prepare_data(self):
7272
self.labels,
7373
args.max_seq_length,
7474
self.tokenizer,
75-
cls_token_at_end=bool(self.config.model_type in ["xlnet"]),
75+
cls_token_at_end=bool(self.config.model_type == "xlnet"),
7676
cls_token=self.tokenizer.cls_token,
77-
cls_token_segment_id=2 if self.config.model_type in ["xlnet"] else 0,
77+
cls_token_segment_id=2 if self.config.model_type == "xlnet" else 0,
7878
sep_token=self.tokenizer.sep_token,
7979
sep_token_extra=False,
80-
pad_on_left=bool(self.config.model_type in ["xlnet"]),
80+
pad_on_left=bool(self.config.model_type == "xlnet"),
8181
pad_token=self.tokenizer.pad_token_id,
8282
pad_token_segment_id=self.tokenizer.pad_token_type_id,
8383
pad_token_label_id=self.pad_token_label_id,

examples/legacy/token-classification/utils_ner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ def __init__(
246246
labels,
247247
max_seq_length,
248248
tokenizer,
249-
cls_token_at_end=bool(model_type in ["xlnet"]),
249+
cls_token_at_end=bool(model_type == "xlnet"),
250250
# xlnet has a cls token at the end
251251
cls_token=tokenizer.cls_token,
252-
cls_token_segment_id=2 if model_type in ["xlnet"] else 0,
252+
cls_token_segment_id=2 if model_type == "xlnet" else 0,
253253
sep_token=tokenizer.sep_token,
254254
sep_token_extra=False,
255255
# roberta uses an extra separator b/w pairs of sentences, cf. github.com/pytorch/fairseq/commit/1684e166e3da03f5b600dbb7855cb98ddfcd0805

src/transformers/audio_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def window_function(
587587
window = np.hamming(length)
588588
elif name in ["hann", "hann_window"]:
589589
window = np.hanning(length)
590-
elif name in ["povey"]:
590+
elif name == "povey":
591591
window = np.power(np.hanning(length), 0.85)
592592
else:
593593
raise ValueError(f"Unknown window function '{name}'")

src/transformers/generation/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ def _prepare_decoder_input_ids_for_generation(
883883
self.config.model_type == "vision-encoder-decoder" and "donut" in self.config.encoder.model_type.lower()
884884
):
885885
pass
886-
elif self.config.model_type in ["whisper"]:
886+
elif self.config.model_type == "whisper":
887887
pass
888888
# user input but doesn't start with decoder_start_token_id -> prepend decoder_start_token_id (and adjust
889889
# decoder_attention_mask if provided)

src/transformers/integrations/ggml.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,11 @@ def _gguf_parse_value(_value, data_type):
329329
_value = int(_value[0])
330330
elif data_type in [6, 12]:
331331
_value = float(_value[0])
332-
elif data_type in [7]:
332+
elif data_type == 7:
333333
_value = bool(_value[0])
334-
elif data_type in [8]:
334+
elif data_type == 8:
335335
_value = array("B", list(_value)).tobytes().decode()
336-
elif data_type in [9]:
336+
elif data_type == 9:
337337
_value = _gguf_parse_value(_value, array_data_type)
338338
return _value
339339

src/transformers/modeling_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4001,7 +4001,7 @@ def save_pretrained(
40014001
if _is_dtensor_available and isinstance(state_dict[tensor], DTensor):
40024002
full_tensor = state_dict[tensor].full_tensor()
40034003
# to get the correctly ordered tensor we need to repack if packed
4004-
if _get_parameter_tp_plan(tensor, self._tp_plan) in ("local_packed_rowwise",):
4004+
if _get_parameter_tp_plan(tensor, self._tp_plan) == "local_packed_rowwise":
40054005
full_tensor = repack_weights(full_tensor, -1, self._tp_size, 2)
40064006
shard[tensor] = full_tensor.contiguous() # only do contiguous after it's permuted correctly
40074007
else:

src/transformers/models/altclip/configuration_altclip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def __init__(
303303

304304
# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
305305
for key, value in _text_config_dict.items():
306-
if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
306+
if key in text_config and value != text_config[key] and key != "transformers_version":
307307
# If specified in `text_config_dict`
308308
if key in text_config_dict:
309309
message = (
@@ -335,7 +335,7 @@ def __init__(
335335

336336
# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
337337
for key, value in _vision_config_dict.items():
338-
if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
338+
if key in vision_config and value != vision_config[key] and key != "transformers_version":
339339
# If specified in `vision_config_dict`
340340
if key in vision_config_dict:
341341
message = (

src/transformers/models/chinese_clip/configuration_chinese_clip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def __init__(
306306

307307
# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
308308
for key, value in _text_config_dict.items():
309-
if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
309+
if key in text_config and value != text_config[key] and key != "transformers_version":
310310
# If specified in `text_config_dict`
311311
if key in text_config_dict:
312312
message = (
@@ -338,7 +338,7 @@ def __init__(
338338

339339
# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
340340
for key, value in _vision_config_dict.items():
341-
if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
341+
if key in vision_config and value != vision_config[key] and key != "transformers_version":
342342
# If specified in `vision_config_dict`
343343
if key in vision_config_dict:
344344
message = (

src/transformers/models/clip/configuration_clip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def __init__(
295295

296296
# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
297297
for key, value in _text_config_dict.items():
298-
if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
298+
if key in text_config and value != text_config[key] and key != "transformers_version":
299299
# If specified in `text_config_dict`
300300
if key in text_config_dict:
301301
message = (
@@ -327,7 +327,7 @@ def __init__(
327327

328328
# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
329329
for key, value in _vision_config_dict.items():
330-
if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
330+
if key in vision_config and value != vision_config[key] and key != "transformers_version":
331331
# If specified in `vision_config_dict`
332332
if key in vision_config_dict:
333333
message = (

src/transformers/models/clipseg/configuration_clipseg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def __init__(
307307

308308
# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
309309
for key, value in _text_config_dict.items():
310-
if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
310+
if key in text_config and value != text_config[key] and key != "transformers_version":
311311
# If specified in `text_config_dict`
312312
if key in text_config_dict:
313313
message = (
@@ -339,7 +339,7 @@ def __init__(
339339

340340
# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
341341
for key, value in _vision_config_dict.items():
342-
if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
342+
if key in vision_config and value != vision_config[key] and key != "transformers_version":
343343
# If specified in `vision_config_dict`
344344
if key in vision_config_dict:
345345
message = (

0 commit comments

Comments
 (0)