[logging] Turn off loss logging, while keeping progress bar and logging to third-party application
Author: antonioloison
Pull request: no

### Feature request

I would like to add a training argument to the `TrainingArguments` class to turn off the loss logging to stdout while keeping the progress bar and logging to a third-party application like Weights and Biases.

### Motivation

I am working on a project that trains a model with the Trainer class. I need to log the losses at every epoch to Weights and Biases. Here is my code:
```
training_arguments = TrainingArguments(
    output_dir="./logging_dir",
    num_train_epochs=epochs,
    per_device_train_batch_size=batch_size,
    per_device_eval_batch_size=batch_size,
    report_to="wandb",
    logging_strategy="epoch",
)

trainer = Trainer(
    model=model,
    args=training_arguments,
    tokenizer=tokenizer,
    train_dataset=train_dataset,
    eval_dataset=eval_dataset,
)
```
This code is contained in a python file `train.py` and is launched in the terminal via the command `python train.py`.
However, I don’t want to have the loss printed because it breaks my progress bar as you can see in the image below and I need the progress bar to give some feedback on the training time.

<img width="1155" alt="cut_progress_bar" src="https://user-images.githubusercontent.com/48316195/178239258-ad61d97f-d851-4c31-a4da-c653aa17db3b.png">



### Your contribution

I think that I could add a `disable_on_log` argument to `TrainingArguments`. Then in the `on_log` of the `ProgressCallback`, a condition should be added like this:

```
def on_log(self, args, state, control, logs=None, **kwargs):
    if state.is_local_process_zero and self.training_bar is not None and args.disable_on_log:
         _ = logs.pop("total_flos", None)
         self.training_bar.write(str(logs))
```

Comments:
You should be able to disable logging while keeping progress bars active. Have you tried setting the log level manually?

```python
from transformers.utils.logging import set_verbosity_error

set_verbosity_error()
```

Yes, I've tried that, but this makes my progress bar disappear and keeps the loss logging. I want to do the opposite, keep my progress bar and remove the loss logging.

Ah, understood. Then in that case providing the training argument `logging_strategy` should do what you want: `logging_strategy="no"` will not output these logs. Did that solve your problem?


Thank you for your answer @LysandreJik. I also tried that, but I want to keep the logs in my third-party application (Weights and Biases here). If I use `logging_strategy="no"`, no more logs are reported to Weights and Biases.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

Not sure if it ever solved in the recent releases but for people who stuck in the older versions. As it is [this](https://github.com/huggingface/transformers/blob/v4.32.1/src/transformers/trainer_callback.py#L516) line that prints the dict log. While progress bar is handled somewhere else. This is an ugly way to stop `ProgressCallback` from printing the dict without modifying the source (at least in older version).

```
from transformers.trainer_callback import ProgressCallback
def on_log(self, args, state, control, logs=None, **kwargs):
    if state.is_local_process_zero and self.training_bar is not None:
        _ = logs.pop("total_flos", None)
ProgressCallback.on_log = on_log
```

I know this issue is old, but as far as I know, there's no way to achieve what OP intends unless he uses the solution posted above by @DableUTeeF (worked for me!). If there is, I didn't find it in the documentation.

This is very important for people that have their own logging solution. It would be cool if there were a clean way to keep logging the loss every `logging_steps`, since this should still work if the user has Neptune/wandb, but disable printing to the terminal.

I have the exact same problem, and would highly rate such feature, it is super annoying to have my screen spammed with all the logs given that i have all the info report to wandb... Nevertheless, kudos to @DableUTeeF for the hacky solution ,that works!

This removes the print outs of dictionaries. 
```
from transformers import Trainer, PrinterCallback
trainer = Trainer(...
trainer.remove_callback(PrinterCallback)
```


Despite calling `grpo_trainer.remove_callback(PrinterCallback)` it's printing this massive completions table and the dict at every step.
How do I make the trainer shut up? I want neither of those while still logging to wandb.
Any help, please?

<img width="742" height="309" alt="Image" src="https://github.com/user-attachments/assets/56fd1d88-89bb-47d3-bf59-efd1dd9dbffd" />

Time has passed, but for people coming here:

This is from `Trainer.__init__()`:
```python
self.add_callback(PrinterCallback if self.args.disable_tqdm else DEFAULT_PROGRESS_CALLBACK)
```

so in the last case you might need to remove `ProgressCallback` or better just remove both:
```python
        # Remove default Trainer callbacks that produce unwanted output
        from transformers import PrinterCallback, ProgressCallback
        trainer.remove_callback(PrinterCallback)
        trainer.remove_callback(ProgressCallback)
        print("Removed default Trainer callbacks (PrinterCallback, ProgressCallback)")
 ```