Skip to content

Commit d988db8

Browse files
author
steinmetzc
committed
make fix-copies
1 parent 6eaf9d1 commit d988db8

5 files changed

Lines changed: 37 additions & 39 deletions

File tree

src/transformers/convert_slow_tokenizer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,8 +1563,6 @@ def bytes_to_unicode():
15631563
n += 1
15641564
cs = [chr(n) for n in cs]
15651565
return dict(zip(bs, cs))
1566-
1567-
15681566
class TikTokenConverter:
15691567
"""
15701568
A general tiktoken converter.
@@ -1584,7 +1582,7 @@ def __init__(
15841582
self.pattern = pattern
15851583
self.add_prefix_space = add_prefix_space
15861584
self.additional_special_tokens = (
1587-
additional_special_tokens.keys() if type(additional_special_tokens) is dict else additional_special_tokens
1585+
additional_special_tokens.keys() if isinstance(additional_special_tokens, dict) else additional_special_tokens
15881586
)
15891587

15901588
def extract_vocab_merges_from_model(self, tiktoken_url: str):

src/transformers/models/flaubert/modeling_flaubert.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ def forward(
363363
Returns:
364364
`torch.FloatTensor`: The end logits for SQuAD.
365365
"""
366-
assert start_states is not None or start_positions is not None, (
367-
"One of start_states, start_positions should be not None"
368-
)
366+
assert (
367+
start_states is not None or start_positions is not None
368+
), "One of start_states, start_positions should be not None"
369369
if start_positions is not None:
370370
slen, hsz = hidden_states.shape[-2:]
371371
start_positions = start_positions[:, None, None].expand(-1, -1, hsz) # shape (bsz, 1, hsz)
@@ -432,9 +432,9 @@ def forward(
432432
"""
433433
# No dependency on end_feature so that we can obtain one single `cls_logits` for each sample.
434434
hsz = hidden_states.shape[-1]
435-
assert start_states is not None or start_positions is not None, (
436-
"One of start_states, start_positions should be not None"
437-
)
435+
assert (
436+
start_states is not None or start_positions is not None
437+
), "One of start_states, start_positions should be not None"
438438
if start_positions is not None:
439439
start_positions = start_positions[:, None, None].expand(-1, -1, hsz) # shape (bsz, 1, hsz)
440440
start_states = hidden_states.gather(-2, start_positions).squeeze(-2) # shape (bsz, hsz)

src/transformers/models/led/modeling_led.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ def __init__(self, config, layer_id):
113113

114114
self.layer_id = layer_id
115115
attention_window = config.attention_window[self.layer_id]
116-
assert attention_window % 2 == 0, (
117-
f"`attention_window` for layer {self.layer_id} has to be an even value. Given {attention_window}"
118-
)
119-
assert attention_window > 0, (
120-
f"`attention_window` for layer {self.layer_id} has to be positive. Given {attention_window}"
121-
)
116+
assert (
117+
attention_window % 2 == 0
118+
), f"`attention_window` for layer {self.layer_id} has to be an even value. Given {attention_window}"
119+
assert (
120+
attention_window > 0
121+
), f"`attention_window` for layer {self.layer_id} has to be positive. Given {attention_window}"
122122

123123
self.one_sided_attn_window_size = attention_window // 2
124124

@@ -152,9 +152,9 @@ def forward(
152152
value_vectors = self.value(hidden_states)
153153

154154
seq_len, batch_size, embed_dim = hidden_states.size()
155-
assert embed_dim == self.embed_dim, (
156-
f"hidden_states should have embed_dim = {self.embed_dim}, but has {embed_dim}"
157-
)
155+
assert (
156+
embed_dim == self.embed_dim
157+
), f"hidden_states should have embed_dim = {self.embed_dim}, but has {embed_dim}"
158158

159159
# normalize query
160160
query_vectors /= math.sqrt(self.head_dim)
@@ -222,9 +222,9 @@ def forward(
222222
) # use fp32 for numerical stability
223223

224224
if layer_head_mask is not None:
225-
assert layer_head_mask.size() == (self.num_heads,), (
226-
f"Head mask for a single layer should be of size {(self.num_heads,)}, but is {layer_head_mask.size()}"
227-
)
225+
assert layer_head_mask.size() == (
226+
self.num_heads,
227+
), f"Head mask for a single layer should be of size {(self.num_heads,)}, but is {layer_head_mask.size()}"
228228
attn_probs = layer_head_mask.view(1, 1, -1, 1) * attn_probs
229229

230230
# softmax sometimes inserts NaN if all positions are masked, replace them with 0
@@ -416,9 +416,9 @@ def _sliding_chunks_query_key_matmul(self, query: torch.Tensor, key: torch.Tenso
416416
overlap of size window_overlap
417417
"""
418418
batch_size, seq_len, num_heads, head_dim = query.size()
419-
assert seq_len % (window_overlap * 2) == 0, (
420-
f"Sequence length should be multiple of {window_overlap * 2}. Given {seq_len}"
421-
)
419+
assert (
420+
seq_len % (window_overlap * 2) == 0
421+
), f"Sequence length should be multiple of {window_overlap * 2}. Given {seq_len}"
422422
assert query.size() == key.size()
423423

424424
chunks_count = torch.div(seq_len, window_overlap, rounding_mode="trunc") - 1
@@ -689,9 +689,9 @@ def _compute_global_attn_output_from_hidden(
689689

690690
# apply layer head masking
691691
if layer_head_mask is not None:
692-
assert layer_head_mask.size() == (self.num_heads,), (
693-
f"Head mask for a single layer should be of size {(self.num_heads,)}, but is {layer_head_mask.size()}"
694-
)
692+
assert layer_head_mask.size() == (
693+
self.num_heads,
694+
), f"Head mask for a single layer should be of size {(self.num_heads,)}, but is {layer_head_mask.size()}"
695695
global_attn_probs_float = layer_head_mask.view(1, -1, 1, 1) * global_attn_probs_float.view(
696696
batch_size, self.num_heads, max_num_global_attn_indices, seq_len
697697
)

src/transformers/models/led/modeling_tf_led.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ def __init__(self, config, layer_id, **kwargs):
182182
self.layer_id = layer_id
183183
attention_window = config.attention_window[self.layer_id]
184184

185-
assert attention_window % 2 == 0, (
186-
f"`attention_window` for layer {self.layer_id} has to be an even value. Given {attention_window}"
187-
)
188-
assert attention_window > 0, (
189-
f"`attention_window` for layer {self.layer_id} has to be positive. Given {attention_window}"
190-
)
185+
assert (
186+
attention_window % 2 == 0
187+
), f"`attention_window` for layer {self.layer_id} has to be an even value. Given {attention_window}"
188+
assert (
189+
attention_window > 0
190+
), f"`attention_window` for layer {self.layer_id} has to be positive. Given {attention_window}"
191191

192192
self.one_sided_attn_window_size = attention_window // 2
193193

src/transformers/models/xlnet/modeling_xlnet.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,9 @@ def forward(
605605
Returns:
606606
`torch.FloatTensor`: The end logits for SQuAD.
607607
"""
608-
assert start_states is not None or start_positions is not None, (
609-
"One of start_states, start_positions should be not None"
610-
)
608+
assert (
609+
start_states is not None or start_positions is not None
610+
), "One of start_states, start_positions should be not None"
611611
if start_positions is not None:
612612
slen, hsz = hidden_states.shape[-2:]
613613
start_positions = start_positions[:, None, None].expand(-1, -1, hsz) # shape (bsz, 1, hsz)
@@ -674,9 +674,9 @@ def forward(
674674
"""
675675
# No dependency on end_feature so that we can obtain one single `cls_logits` for each sample.
676676
hsz = hidden_states.shape[-1]
677-
assert start_states is not None or start_positions is not None, (
678-
"One of start_states, start_positions should be not None"
679-
)
677+
assert (
678+
start_states is not None or start_positions is not None
679+
), "One of start_states, start_positions should be not None"
680680
if start_positions is not None:
681681
start_positions = start_positions[:, None, None].expand(-1, -1, hsz) # shape (bsz, 1, hsz)
682682
start_states = hidden_states.gather(-2, start_positions).squeeze(-2) # shape (bsz, hsz)

0 commit comments

Comments
 (0)