Is there any way to use the some logging basicConfig across the Trainer object?

I’m currently using logging and the Trainer as follows:

from accelerate.logging import get_logger
from transformers import Trainer


logger = get_logger()

def main():
    logging.basicConfig()
    # Some code.
    trainer = Trainer()
    trainer.train()

What I’m noticing is that the logging formats are different for my main script and from within the Trainer. I’m assuming that this is because the Trainer module has its own logger initialized from Python’s logging module at the very top, and therefore my main script’s configurations aren’t transferring over.

Is there a way that I can make sure the logging is consistent?

2 Likes

Same issues with wav2vec finetuning. Practically a zoo of message types.

(1) normal log

2025-07-09 12:13:33,550 [DEBUG] _api.acquire Lock 125134761104336 acquired on

(2) printing a json object

{'eval_loss': 1011.0382690429688, 'eval_cer': 1.0, 'eval_runtime': 476.243, ... }

(3) banner

***** Running Evaluation *****                                                                                                                                                                                                                                                  
  Num examples = 10042                                                                                                                                                                                                                                                          
  Batch size = 12 

(4) printf instead of a log msg

Model weights saved in....
The following columns in the Evaluation set don't have a corresponding argument in 

( +1 ) repeating the same warning in each and every evaluation phase - a dozen of times …

UserWarning: `as_target_processor` is deprecated

(+2) In many cases I have no idea what HF/transformers is doing. GPU is at 0% util., CPU is almost dead except for 1 core. It would be nice to show what is happening. Especially if this “what” takes up 20% of the training time.

When/If you decide to change the code, assume that some of the users would programmatically parse the logs. So, there is no need for visually fancy banners.

1 Like