Skip to content

Commit cc92f28

Browse files
authored
[CodeStyle] Format trainer code style. (#4057)
1 parent 0da3f93 commit cc92f28

File tree

7 files changed

+12
-27
lines changed

7 files changed

+12
-27
lines changed

paddlenlp/trainer/compression_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from dataclasses import dataclass, field
1817
import types
18+
from dataclasses import dataclass, field
1919
from typing import List, Optional
2020

2121
import paddle

paddlenlp/trainer/integrations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import importlib
2020
import json
2121

22-
from .trainer_callback import TrainerCallback
23-
from ..utils.log import logger
2422
from ..transformers import PretrainedModel
23+
from ..utils.log import logger
24+
from .trainer_callback import TrainerCallback
2525

2626

2727
def is_visualdl_available():

paddlenlp/trainer/trainer_callback.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
import numpy as np
2727
from tqdm.auto import tqdm
2828

29+
from paddlenlp.utils.log import logger
30+
2931
from .trainer_utils import IntervalStrategy, has_length
3032
from .training_args import TrainingArguments
31-
from paddlenlp.utils.log import logger
3233

3334
__all__ = [
3435
"TrainerState",

paddlenlp/trainer/trainer_seq2seq.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
from .trainer import Trainer
2222
from .trainer_utils import PredictionOutput
23-
from ..utils.log import logger
2423

2524
__all__ = [
2625
"Seq2SeqTrainer",

paddlenlp/trainer/trainer_utils.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@
1616
# This file is modified from
1717
# https://github.com/huggingface/transformers/blob/main/src/transformers/trainer_utils.py
1818
"""
19-
Utilities for the Trainer class.
19+
Utilities for the Trainer class.
2020
"""
2121
import datetime
2222
import json
23+
import math
2324
import os
2425
import random
2526
import re
2627
import time
27-
import math
2828
from enum import Enum
29-
from typing import Dict, NamedTuple, Optional, Tuple, Union, List
29+
from typing import Dict, List, NamedTuple, Optional, Tuple, Union
3030

3131
import numpy as np
3232
import paddle
3333
from paddle.io import IterableDataset
3434
from paddle.optimizer.lr import LambdaDecay
3535

36-
from ..utils.log import logger
3736
from ..transformers.tokenizer_utils_base import BatchEncoding
37+
from ..utils.log import logger
3838

3939
__all__ = [
4040
"TrainOutput",
@@ -459,18 +459,6 @@ def has_length(dataset):
459459
return False
460460

461461

462-
def get_last_checkpoint(folder):
463-
content = os.listdir(folder)
464-
checkpoints = [
465-
path
466-
for path in content
467-
if _re_checkpoint.search(path) is not None and os.path.isdir(os.path.join(folder, path))
468-
]
469-
if len(checkpoints) == 0:
470-
return
471-
return os.path.join(folder, max(checkpoints, key=lambda x: int(_re_checkpoint.search(x).groups()[0])))
472-
473-
474462
class IterableDatasetShard(IterableDataset):
475463
"""
476464
Wraps a Paddle `IterableDataset` to generate samples for one of the processes only. Instances of this class will

paddlenlp/trainer/training_args.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@
2020
import json
2121
import math
2222
import os
23-
from dataclasses import asdict, dataclass, field
23+
import types
2424
import warnings
25+
from dataclasses import asdict, dataclass, field
2526
from enum import Enum
26-
import types
2727
from typing import Any, Dict, List, Optional
2828

2929
import paddle
3030
from paddle.distributed import fleet
3131

3232
from ..utils.log import logger
3333
from .trainer_utils import (
34-
SchedulerType,
3534
IntervalStrategy,
3635
OptimizerNames,
36+
SchedulerType,
3737
ShardingOption,
3838
)
3939

paddlenlp/trainer/training_args_seq2seq.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import logging
1615
from dataclasses import dataclass, field
1716
from typing import Optional
1817

1918
from .training_args import TrainingArguments
2019
from .utils import add_start_docstrings
2120

22-
from ..utils.log import logger
23-
2421
__all__ = [
2522
"Seq2SeqTrainingArguments",
2623
]

0 commit comments

Comments
 (0)