fix warning function call creating logger error (max_length and max_new_tokens)
Author: QuentinAmbard
Pull request: yes

# What does this PR do?

PR #21347 introduced a bug in the warning we display, calling the wrong warn function.

There is a bug open about this error: #22636 

it's either 
`warnings.warn("msg", UserWarning,)`
or 
`logger.warning("msg")`
In this case we have
`logger.warn` which is deprecated, and `logger.warn("msg", category)` doesn't exist and throws an error:

```
--- Logging error ---
Traceback (most recent call last):
  File "/python-path/python3.9/logging/__init__.py", line 1083, in emit
    msg = self.format(record)
  File "/python-path/python3.9/logging/__init__.py", line 927, in format
    return fmt.format(record)
  File "/python-path/python3.9/logging/__init__.py", line 663, in format
    record.message = record.getMessage()
  File "/python-path/python3.9/logging/__init__.py", line 367, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
```


Fixes # (issue)

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

@gante  ?


Comments:
_The documentation is not available anymore as the PR was closed or merged._

@QuentinAmbard @gante , could you please tell how to fix this bug? I still see "logging error message".

You need to wait for the next release I guess, or apply the fix directly?

> You need to wait for the next release I guess, or apply the fix directly?

Yep, or you can [install from source](https://huggingface.co/docs/transformers/installation#install-from-source) 

@QuentinAmbard okay, thanks for quicky response. I will better remove the logging from source code.

@amyeroberts how to install from source, if new fix isn't merged with main branch? 

@IamExperimenting The fix is merged into the main branch. Installing from source means installing the version of the library currently on main. The instructions were in the link I shared above: https://huggingface.co/docs/transformers/installation#install-from-source

@amyeroberts thanks for the information, I installed from source but its throwing error
```
from transformers import pipeline
```

error: 
```
RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
cannot import name `PartialState` from `accelerate`
```

You need to upgrade your `accelerate` library: `pip install --upgrade accelerate`.

@amyeroberts @sgugger it worked after upgrading. However, it removed only `logging error` not the `warning message`.