Skip to content

Commit c4d3a2f

Browse files
authored
Revert "[Tokenier] Enable padding_side as call time kwargs (#9161)" (#9192)
This reverts commit c5e6db5.
1 parent c5e6db5 commit c4d3a2f

File tree

15 files changed

+57
-186
lines changed

15 files changed

+57
-186
lines changed

paddlenlp/transformers/artist/tokenizer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ def __call__(
225225
return_offsets_mapping=False,
226226
add_special_tokens=True,
227227
pad_to_multiple_of=None,
228-
padding_side=None,
229228
return_tensors=None,
230229
verbose: bool = True,
231230
**kwargs
@@ -248,7 +247,6 @@ def __call__(
248247
return_offsets_mapping,
249248
add_special_tokens,
250249
pad_to_multiple_of,
251-
padding_side,
252250
return_tensors,
253251
verbose,
254252
**kwargs,

paddlenlp/transformers/bloom/tokenizer.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import os
1919
import shutil
2020
from functools import lru_cache
21-
from typing import Dict, Literal, Optional, Union
21+
from typing import Dict, Optional, Union
2222

2323
import numpy as np
2424
from paddle.utils import try_import
@@ -360,7 +360,6 @@ def _pad(
360360
max_length: Optional[int] = None,
361361
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
362362
pad_to_multiple_of: Optional[int] = None,
363-
padding_side: Optional[Literal["right", "left"]] = None,
364363
return_attention_mask: Optional[bool] = None,
365364
) -> dict:
366365
"""
@@ -376,16 +375,13 @@ def _pad(
376375
- PaddingStrategy.LONGEST Pad to the longest sequence in the batch
377376
- PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
378377
- PaddingStrategy.DO_NOT_PAD: Do not pad
379-
The tokenizer padding sides are defined in `padding_side` argument:
378+
The tokenizer padding sides are defined in self.padding_side:
380379
381380
- 'left': pads on the left of the sequences
382381
- 'right': pads on the right of the sequences
383382
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
384383
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
385384
>= 7.5 (Volta).
386-
padding_side: (optional) The side on which the model should have padding applied.
387-
Should be selected between ['right', 'left'].
388-
Default value is picked from the class attribute of the same name.
389385
return_attention_mask:
390386
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
391387
"""
@@ -398,7 +394,7 @@ def _pad(
398394

399395
required_input = encoded_inputs[self.model_input_names[0]]
400396
encoded_inputs = super()._pad(
401-
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, padding_side, return_attention_mask
397+
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, return_attention_mask
402398
)
403399
if attention_mask is not None and len(np.shape(attention_mask)) > 2:
404400
encoded_inputs["attention_mask"] = attention_mask

paddlenlp/transformers/chatglm/tokenizer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""Tokenization classes for ChatGLM."""
1616
import os
17-
from typing import Dict, List, Literal, Optional, Union
17+
from typing import Dict, List, Optional, Union
1818

1919
import numpy as np
2020
import sentencepiece as spm
@@ -218,15 +218,13 @@ def _pad(
218218
max_length: Optional[int] = None,
219219
padding_strategy=PaddingStrategy.DO_NOT_PAD,
220220
pad_to_multiple_of: Optional[int] = None,
221-
padding_side: Optional[Literal["right", "left"]] = None,
222221
return_attention_mask: Optional[bool] = None,
223222
) -> dict:
224223
# Load from model defaults
225224
if return_attention_mask is None:
226225
return_attention_mask = "attention_mask" in self.model_input_names or "attention_mask" in encoded_inputs
227226

228-
padding_side = padding_side if padding_side is not None else self.padding_side
229-
assert padding_side == "left"
227+
assert self.padding_side == "left"
230228
required_input = encoded_inputs[self.model_input_names[0]]
231229
seq_length = len(required_input)
232230

paddlenlp/transformers/chatglm_v2/tokenizer.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import os
1717
import re
18-
from typing import Any, Dict, List, Literal, Optional, Union
18+
from typing import Any, Dict, List, Optional, Union
1919

2020
import numpy as np
2121
from sentencepiece import SentencePieceProcessor
@@ -244,7 +244,6 @@ def _pad(
244244
max_length: Optional[int] = None,
245245
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
246246
pad_to_multiple_of: Optional[int] = None,
247-
padding_side: Optional[Literal["right", "left"]] = None,
248247
return_attention_mask: Optional[bool] = None,
249248
) -> dict:
250249
"""
@@ -260,22 +259,18 @@ def _pad(
260259
- PaddingStrategy.LONGEST Pad to the longest sequence in the batch
261260
- PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
262261
- PaddingStrategy.DO_NOT_PAD: Do not pad
263-
The tokenizer padding sides are defined in `padding_side` argument:
262+
The tokenizer padding sides are defined in self.padding_side:
264263
265264
- 'left': pads on the left of the sequences
266265
- 'right': pads on the right of the sequences
267266
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
268267
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
269-
>= 7.5 (Volta).
270-
padding_side: (optional) The side on which the model should have padding applied.
271-
Should be selected between ['right', 'left'].
272-
Default value is picked from the class attribute of the same name.
268+
`>= 7.5` (Volta).
273269
return_attention_mask:
274270
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
275271
"""
276272
# Load from model defaults
277-
padding_side = padding_side if padding_side is not None else self.padding_side
278-
assert padding_side == "left"
273+
assert self.padding_side == "left"
279274

280275
required_input = encoded_inputs[self.model_input_names[0]]
281276
seq_length = len(required_input)

paddlenlp/transformers/dallebart/tokenizer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ def __call__(
464464
return_offsets_mapping=False,
465465
add_special_tokens=True,
466466
pad_to_multiple_of=None,
467-
padding_side=None,
468467
return_tensors=None,
469468
verbose: bool = True,
470469
**kwargs
@@ -498,7 +497,6 @@ def __call__(
498497
return_offsets_mapping,
499498
add_special_tokens,
500499
pad_to_multiple_of,
501-
padding_side,
502500
return_tensors,
503501
verbose,
504502
**kwargs,

paddlenlp/transformers/gemma/tokenizer.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import os
1717
from shutil import copyfile
18-
from typing import Any, Dict, List, Literal, Optional, Tuple, Union
18+
from typing import Any, Dict, List, Optional, Tuple, Union
1919

2020
import numpy as np
2121
import sentencepiece as spm
@@ -323,7 +323,6 @@ def _pad(
323323
max_length: Optional[int] = None,
324324
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
325325
pad_to_multiple_of: Optional[int] = None,
326-
padding_side: Optional[Literal["right", "left"]] = None,
327326
return_attention_mask: Optional[bool] = None,
328327
) -> dict:
329328
"""
@@ -346,9 +345,6 @@ def _pad(
346345
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
347346
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
348347
>= 7.5 (Volta).
349-
padding_side: (optional) The side on which the model should have padding applied.
350-
Should be selected between ['right', 'left'].
351-
Default value is picked from the class attribute of the same name.
352348
return_attention_mask:
353349
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
354350
"""
@@ -363,7 +359,7 @@ def _pad(
363359

364360
required_input = encoded_inputs[self.model_input_names[0]]
365361
encoded_inputs = super()._pad(
366-
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, padding_side, return_attention_mask
362+
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, return_attention_mask
367363
)
368364
if attention_mask is not None and len(np.shape(attention_mask)) > 2:
369365
encoded_inputs["attention_mask"] = attention_mask

paddlenlp/transformers/gpt/tokenizer.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import os
1818
import shutil
1919
from functools import lru_cache
20-
from typing import Dict, Literal, Optional, Union
20+
from typing import Dict, Optional, Union
2121

2222
import jieba
2323
import numpy as np
@@ -584,7 +584,6 @@ def _pad(
584584
max_length: Optional[int] = None,
585585
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
586586
pad_to_multiple_of: Optional[int] = None,
587-
padding_side: Optional[Literal["right", "left"]] = None,
588587
return_attention_mask: Optional[bool] = None,
589588
) -> dict:
590589
"""
@@ -600,16 +599,13 @@ def _pad(
600599
- PaddingStrategy.LONGEST Pad to the longest sequence in the batch
601600
- PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
602601
- PaddingStrategy.DO_NOT_PAD: Do not pad
603-
The tokenizer padding sides are defined in `padding_side` argument:
602+
The tokenizer padding sides are defined in self.padding_side:
604603
605604
- 'left': pads on the left of the sequences
606605
- 'right': pads on the right of the sequences
607606
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
608607
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
609608
>= 7.5 (Volta).
610-
padding_side: (optional) The side on which the model should have padding applied.
611-
Should be selected between ['right', 'left'].
612-
Default value is picked from the class attribute of the same name.
613609
return_attention_mask:
614610
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
615611
"""
@@ -624,7 +620,7 @@ def _pad(
624620

625621
required_input = encoded_inputs[self.model_input_names[0]]
626622
encoded_inputs = super()._pad(
627-
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, padding_side, return_attention_mask
623+
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, return_attention_mask
628624
)
629625
if attention_mask is not None and len(np.shape(attention_mask)) > 2:
630626
encoded_inputs["attention_mask"] = attention_mask

paddlenlp/transformers/llama/tokenizer.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import os
1717
from shutil import copyfile
18-
from typing import Dict, List, Literal, Optional, Tuple, Union
18+
from typing import Dict, List, Optional, Tuple, Union
1919

2020
import numpy as np
2121
import sentencepiece as spm
@@ -232,7 +232,6 @@ def _pad(
232232
max_length: Optional[int] = None,
233233
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
234234
pad_to_multiple_of: Optional[int] = None,
235-
padding_side: Optional[Literal["right", "left"]] = None,
236235
return_attention_mask: Optional[bool] = None,
237236
) -> dict:
238237
"""
@@ -248,16 +247,13 @@ def _pad(
248247
- PaddingStrategy.LONGEST Pad to the longest sequence in the batch
249248
- PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
250249
- PaddingStrategy.DO_NOT_PAD: Do not pad
251-
The tokenizer padding sides are defined in `padding_side` argument:
250+
The tokenizer padding sides are defined in self.padding_side:
252251
253252
- 'left': pads on the left of the sequences
254253
- 'right': pads on the right of the sequences
255254
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
256255
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
257256
>= 7.5 (Volta).
258-
padding_side: (optional) The side on which the model should have padding applied.
259-
Should be selected between ['right', 'left'].
260-
Default value is picked from the class attribute of the same name.
261257
return_attention_mask:
262258
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
263259
"""
@@ -272,7 +268,7 @@ def _pad(
272268

273269
required_input = encoded_inputs[self.model_input_names[0]]
274270
encoded_inputs = super()._pad(
275-
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, padding_side, return_attention_mask
271+
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, return_attention_mask
276272
)
277273
if attention_mask is not None and len(np.shape(attention_mask)) > 2:
278274
encoded_inputs["attention_mask"] = attention_mask
@@ -525,7 +521,6 @@ def _pad(
525521
max_length: Optional[int] = None,
526522
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
527523
pad_to_multiple_of: Optional[int] = None,
528-
padding_side: Optional[Literal["right", "left"]] = None,
529524
return_attention_mask: Optional[bool] = None,
530525
) -> dict:
531526
"""
@@ -541,16 +536,13 @@ def _pad(
541536
- PaddingStrategy.LONGEST Pad to the longest sequence in the batch
542537
- PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
543538
- PaddingStrategy.DO_NOT_PAD: Do not pad
544-
The tokenizer padding sides are defined in `padding_side` argument:
539+
The tokenizer padding sides are defined in self.padding_side:
545540
546541
- 'left': pads on the left of the sequences
547542
- 'right': pads on the right of the sequences
548543
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
549544
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
550545
>= 7.5 (Volta).
551-
padding_side: (optional) The side on which the model should have padding applied.
552-
Should be selected between ['right', 'left'].
553-
Default value is picked from the class attribute of the same name.
554546
return_attention_mask:
555547
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
556548
"""
@@ -565,7 +557,7 @@ def _pad(
565557

566558
required_input = encoded_inputs[self.model_input_names[0]]
567559
encoded_inputs = super()._pad(
568-
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, padding_side, return_attention_mask
560+
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, return_attention_mask
569561
)
570562
if attention_mask is not None and len(np.shape(attention_mask)) > 2:
571563
encoded_inputs["attention_mask"] = attention_mask

paddlenlp/transformers/mamba/tokenizer.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import os
1919
import shutil
2020
from functools import lru_cache
21-
from typing import Dict, Literal, Optional, Union
21+
from typing import Dict, Optional, Union
2222

2323
import numpy as np
2424
from paddle.utils import try_import
@@ -302,7 +302,6 @@ def _pad(
302302
max_length: Optional[int] = None,
303303
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
304304
pad_to_multiple_of: Optional[int] = None,
305-
padding_side: Optional[Literal["right", "left"]] = None,
306305
return_attention_mask: Optional[bool] = None,
307306
) -> dict:
308307
"""
@@ -318,16 +317,13 @@ def _pad(
318317
- PaddingStrategy.LONGEST Pad to the longest sequence in the batch
319318
- PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
320319
- PaddingStrategy.DO_NOT_PAD: Do not pad
321-
The tokenizer padding sides are defined in `padding_side` argument:
320+
The tokenizer padding sides are defined in self.padding_side:
322321
323322
- 'left': pads on the left of the sequences
324323
- 'right': pads on the right of the sequences
325324
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
326325
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
327326
>= 7.5 (Volta).
328-
padding_side: (optional) The side on which the model should have padding applied.
329-
Should be selected between ['right', 'left'].
330-
Default value is picked from the class attribute of the same name.
331327
return_attention_mask:
332328
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
333329
"""
@@ -342,7 +338,7 @@ def _pad(
342338

343339
required_input = encoded_inputs[self.model_input_names[0]]
344340
encoded_inputs = super()._pad(
345-
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, padding_side, return_attention_mask
341+
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, return_attention_mask
346342
)
347343
if attention_mask is not None and len(np.shape(attention_mask)) > 2:
348344
encoded_inputs["attention_mask"] = attention_mask

paddlenlp/transformers/qwen/tokenizer.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import base64
1818
import os
1919
import unicodedata
20-
from typing import Collection, Dict, List, Literal, Optional, Set, Tuple, Union
20+
from typing import Collection, Dict, List, Optional, Set, Tuple, Union
2121

2222
import numpy as np
2323

@@ -255,7 +255,6 @@ def _pad(
255255
max_length: Optional[int] = None,
256256
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
257257
pad_to_multiple_of: Optional[int] = None,
258-
padding_side: Optional[Literal["right", "left"]] = None,
259258
return_attention_mask: Optional[bool] = None,
260259
) -> dict:
261260
"""
@@ -271,16 +270,13 @@ def _pad(
271270
- PaddingStrategy.LONGEST Pad to the longest sequence in the batch
272271
- PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
273272
- PaddingStrategy.DO_NOT_PAD: Do not pad
274-
The tokenizer padding sides are defined in `padding_side` argument:
273+
The tokenizer padding sides are defined in self.padding_side:
275274
276275
- 'left': pads on the left of the sequences
277276
- 'right': pads on the right of the sequences
278277
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
279278
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
280279
>= 7.5 (Volta).
281-
padding_side: (optional) The side on which the model should have padding applied.
282-
Should be selected between ['right', 'left'].
283-
Default value is picked from the class attribute of the same name.
284280
return_attention_mask:
285281
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
286282
"""
@@ -295,7 +291,7 @@ def _pad(
295291

296292
required_input = encoded_inputs[self.model_input_names[0]]
297293
encoded_inputs = super()._pad(
298-
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, padding_side, return_attention_mask
294+
encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, return_attention_mask
299295
)
300296
if attention_mask is not None and len(np.shape(attention_mask)) > 2:
301297
encoded_inputs["attention_mask"] = attention_mask

0 commit comments

Comments
 (0)