Skip to content

Commit 9c5ff0d

Browse files
authored
[Cherry-pick] logger level (#7920)
Cherry-pick of #7903
1 parent 797efa6 commit 9c5ff0d

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

paddlenlp/peft/lora/lora_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def print_trainable_parameters(self) -> None:
489489
freeze_numel += np.prod(weight.shape)
490490
else:
491491
trainable_numel += np.prod(weight.shape)
492-
logger.info(
492+
logger.debug(
493493
f"Frozen parameters: {freeze_numel:.2e} || Trainable parameters:{trainable_numel:.2e} || Total parameters:{freeze_numel+trainable_numel:.2e}|| Trainable:{trainable_numel / (freeze_numel+trainable_numel):.2%}"
494494
)
495495

paddlenlp/peft/prefix/prefix_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def print_trainable_parameters(self) -> None:
282282
freeze_numel += np.prod(weight.shape)
283283
else:
284284
trainable_numel += np.prod(weight.shape)
285-
logger.info(
285+
logger.debug(
286286
f"Frozen parameters: {freeze_numel:.2e} || Trainable parameters:{trainable_numel:.2e} || Total parameters:{freeze_numel+trainable_numel:.2e}|| Trainable:{trainable_numel / (freeze_numel+trainable_numel):.2%}"
287287
)
288288

paddlenlp/trainer/integrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def on_train_begin(self, args, state, control, **kwargs):
9696

9797
if self.vdl_writer is not None:
9898
self.vdl_writer.add_text("args", args.to_json_string())
99-
if "model" in kwargs:
99+
if "model" in kwargs and logger.logger.level < 20:
100100
model = kwargs["model"]
101101
if isinstance(model, LoRAModel) or isinstance(model, PrefixModelForCausalLM):
102102
model = kwargs["model"].model

paddlenlp/trainer/trainer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ def train(
729729
# per_device_trainable_numel = sum(p.numel().item() for p in model.parameters() if not p.stop_gradient)
730730
# TODO: Temporary fix since Tensor.numel() not supported in distributed mode
731731
per_device_trainable_numel = sum(np.prod(p.shape) for p in model.parameters() if not p.stop_gradient)
732-
logger.info(f" Number of trainable parameters = {per_device_trainable_numel:,} (per device)")
732+
logger.debug(f" Number of trainable parameters = {per_device_trainable_numel:,} (per device)")
733733
if self.args.use_hybrid_parallel:
734734
# todo fix for pipeline_parallel_degree
735735
parts_num = max(self.args.tensor_parallel_degree, 1) * max(self.args.pipeline_parallel_degree, 1)
@@ -745,7 +745,7 @@ def train(
745745
trainable_numel = trainable_numel // self.args.sep_parallel_degree
746746
# the numel is roughly, because the tensor parallel still hold own bias or layer_norm weight without splited
747747
# so, the trainable numel is a little bigger than real.
748-
logger.info(f" Number of trainable parameters = {trainable_numel:,} (all devices, roughly)")
748+
logger.debug(f" Number of trainable parameters = {trainable_numel:,} (all devices, roughly)")
749749

750750
start_time = time.time()
751751
self._globalstep_last_start_time = time.time()
@@ -2392,7 +2392,7 @@ def log(self, logs: Dict[str, float], **kwargs) -> None:
23922392
kwargs.update(timer=self.timers, paddle_pipeline_timers=paddle_pipeline_timers)
23932393

23942394
if self.state.epoch is not None:
2395-
logs["epoch"] = round(self.state.epoch, 4)
2395+
logs["progress_or_epoch"] = round(self.state.epoch, 4)
23962396
output = {**logs, **{"step": self.state.global_step}}
23972397
self.state.log_history.append(output)
23982398
self.control = self.callback_handler.on_log(self.args, self.state, self.control, logs, **kwargs)
@@ -2953,23 +2953,23 @@ def print_config(self, args=None, key=""):
29532953
"""
29542954
print config values
29552955
"""
2956-
logger.info("=" * 60)
2956+
logger.debug("=" * 60)
29572957
if args is None:
29582958
args = self.args
29592959
key = "Training"
29602960
import paddlenlp
29612961

2962-
logger.info("{:^40}".format("{} Configuration Arguments".format(key)))
2963-
logger.info("{:30}: {}".format("paddle commit id", paddle.version.commit))
2964-
logger.info("{:30}: {}".format("paddlenlp commit id", paddlenlp.version.commit))
2962+
logger.debug("{:^40}".format("{} Configuration Arguments".format(key)))
2963+
logger.debug("{:30}: {}".format("paddle commit id", paddle.version.commit))
2964+
logger.debug("{:30}: {}".format("paddlenlp commit id", paddlenlp.version.commit))
29652965

29662966
for a in dir(args):
29672967
if a[:2] != "__": # don't print double underscore methods
29682968
v = getattr(args, a)
29692969
if not isinstance(v, types.MethodType):
2970-
logger.info("{:30}: {}".format(a, v))
2970+
logger.debug("{:30}: {}".format(a, v))
29712971

2972-
logger.info("")
2972+
logger.debug("")
29732973

29742974
def is_unified_checkpoint(self, resume_from_checkpoint, safe_serialization=True):
29752975
is_unified_checkpoint_type = False

paddlenlp/trainer/trainer_callback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def on_log(self, args, state, control, logs=None, **kwargs):
515515
logs_str = ", ".join(f"{k}: {v}" for k, v in logs.items())
516516
else:
517517
logs_str = str(logs)
518-
self.training_bar.write(logs_str)
518+
logger.info(logs_str)
519519

520520
def on_train_end(self, args, state, control, **kwargs):
521521
if state.is_local_process_zero:

paddlenlp/trainer/training_args.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,21 +1703,21 @@ def print_config(self, args=None, key=""):
17031703
"""
17041704
print all config values.
17051705
"""
1706-
logger.info("=" * 60)
1706+
logger.debug("=" * 60)
17071707
if args is None:
17081708
args = self
17091709
key = "Training"
17101710

17111711
import paddlenlp
17121712

1713-
logger.info("{:^40}".format("{} Configuration Arguments".format(key)))
1714-
logger.info("{:30}: {}".format("paddle commit id", paddle.version.commit))
1715-
logger.info("{:30}: {}".format("paddlenlp commit id", paddlenlp.version.commit))
1713+
logger.debug("{:^40}".format("{} Configuration Arguments".format(key)))
1714+
logger.debug("{:30}: {}".format("paddle commit id", paddle.version.commit))
1715+
logger.debug("{:30}: {}".format("paddlenlp commit id", paddlenlp.version.commit))
17161716

17171717
for a in dir(args):
17181718
if a[:2] != "__": # don't print double underscore methods
17191719
v = getattr(args, a)
17201720
if not isinstance(v, types.MethodType):
1721-
logger.info("{:30}: {}".format(a, v))
1721+
logger.debug("{:30}: {}".format(a, v))
17221722

1723-
logger.info("")
1723+
logger.debug("")

paddlenlp/transformers/model_utils.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,15 +1929,23 @@ def _find_mismatched_keys(
19291929
raise RuntimeError(f"Error(s) in loading state_dict for {model.__class__.__name__}:\n\t{error_msg}")
19301930

19311931
if len(unexpected_keys) > 0:
1932-
logger.warning(
1933-
f"Some weights of the model checkpoint at {pretrained_model_name_or_path} were not used when"
1934-
f" initializing {model.__class__.__name__}: {sorted(unexpected_keys)}\n- This IS expected if you are"
1935-
f" initializing {model.__class__.__name__} from the checkpoint of a model trained on another task or"
1936-
" with another architecture (e.g. initializing a BertForSequenceClassification model from a"
1937-
" BertForPreTraining model).\n- This IS NOT expected if you are initializing"
1938-
f" {model.__class__.__name__} from the checkpoint of a model that you expect to be exactly identical"
1939-
" (initializing a BertForSequenceClassification model from a BertForSequenceClassification model)."
1940-
)
1932+
if logger.logger.level < 20:
1933+
logger.warning(
1934+
f"Some weights of the model checkpoint at {pretrained_model_name_or_path} were not used when"
1935+
f" initializing {model.__class__.__name__}: {sorted(unexpected_keys)}\n- This IS expected if you are"
1936+
f" initializing {model.__class__.__name__} from the checkpoint of a model trained on another task or"
1937+
" with another architecture (e.g. initializing a BertForSequenceClassification model from a"
1938+
" BertForPreTraining model).\n- This IS NOT expected if you are initializing"
1939+
f" {model.__class__.__name__} from the checkpoint of a model that you expect to be exactly identical"
1940+
" (initializing a BertForSequenceClassification model from a BertForSequenceClassification model)."
1941+
)
1942+
else:
1943+
logger.warning(
1944+
f"Some weights of the model checkpoint at {pretrained_model_name_or_path} were not used when"
1945+
f" initializing the model, - This IS expected if you are"
1946+
f" initializing the model from a checkpoint of a model trained on another task or"
1947+
" with another architecture."
1948+
)
19411949
else:
19421950
logger.info(f"All model checkpoint weights were used when initializing {model.__class__.__name__}.\n")
19431951

0 commit comments

Comments
 (0)