

TITLE
Both `max_new_tokens` and `max_length` seem to have been set.

COMMENTS
4

REACTIONS
+1: 0
-1: 0
laugh: 0
hooray: 0
heart: 0
rocket: 0
eyes: 0

BODY
### System Info

- `transformers` version: 4.27.4
- Platform: Linux-5.15.0-69-generic-x86_64-with-glibc2.35
- Python version: 3.9.16
- Huggingface_hub version: 0.13.3
- PyTorch version (GPU?): 1.13.1+cu117 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: yes
- Using distributed or parallel set-up in script?: no

### Who can help?

@ArthurZucker
@younesbelkada

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

I'm trying to generate some text with `text-generation` pipeline.

```python
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, GenerationConfig

device = "cuda:0"
model_name = "facebook/opt-1.3b"

# tokenizer, model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    low_cpu_mem_usage=True,
    pad_token_id=tokenizer.eos_token_id
).to(device)

# pipeline
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device)

# generate text
text = "Hello "
result = pipe(
    text,
    generation_config=GenerationConfig(
        max_new_tokens=70,
        return_full_text=False,
        num_beams=1,
        do_sample=False
    )
)

# print result
print(result)
```

When I execute the code above, it shows error/warning messages like below.

```text
--- 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
Call stack:
  File "/python-path/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/python-path/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/python-path/python3.9/site-packages/ipykernel_launcher.py", line 17, in <module>
    app.launch_new_instance()
  File "/python-path/python3.9/site-packages/traitlets/config/application.py", line 1043, in launch_instance
    app.start()
  File "/python-pathpython3.9/site-packages/ipykernel/kernelapp.py", line 725, in start
    self.io_loop.start()
  File "/python-path/python3.9/site-packages/tornado/platform/asyncio.py", line 215, in start
    self.asyncio_loop.run_forever()
  File "/python-path/python3.9/asyncio/base_events.py", line 601, in run_forever
    self._run_once()
  File "/python-path/python3.9/asyncio/base_events.py", line 1905, in _run_once
    handle._run()
  File "/python-path/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/python-path/python3.9/site-packages/ipykernel/kernelbase.py", line 513, in dispatch_queue
    await self.process_one()
  File "/python-path/python3.9/site-packages/ipykernel/kernelbase.py", line 502, in process_one
    await dispatch(*args)
  File "/python-path/python3.9/site-packages/ipykernel/kernelbase.py", line 409, in dispatch_shell
    await result
  File "/python-path/python3.9/site-packages/ipykernel/kernelbase.py", line 729, in execute_request
    reply_content = await reply_content
  File "/python-path/python3.9/site-packages/ipykernel/ipkernel.py", line 422, in do_execute
    res = shell.run_cell(
  File "/python-path/python3.9/site-packages/ipykernel/zmqshell.py", line 540, in run_cell
    return super().run_cell(*args, **kwargs)
  File "/python-path/python3.9/site-packages/IPython/core/interactiveshell.py", line 3006, in run_cell
    result = self._run_cell(
  File "/python-path/python3.9/site-packages/IPython/core/interactiveshell.py", line 3061, in _run_cell
    result = runner(coro)
  File "/python-path/python3.9/site-packages/IPython/core/async_helpers.py", line 129, in _pseudo_sync_runner
    coro.send(None)
  File "/python-path/python3.9/site-packages/IPython/core/interactiveshell.py", line 3266, in run_cell_async
    has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
  File "/python-path/python3.9/site-packages/IPython/core/interactiveshell.py", line 3445, in run_ast_nodes
    if await self.run_code(code, result, async_=asy):
  File "/python-path/python3.9/site-packages/IPython/core/interactiveshell.py", line 3505, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "/tmp/ipykernel_872573/1980627959.py", line 19, in <module>
    result = pipe(
  File "/python-path/python3.9/site-packages/transformers/pipelines/text_generation.py", line 209, in __call__
    return super().__call__(text_inputs, **kwargs)
  File "/python-path/python3.9/site-packages/transformers/pipelines/base.py", line 1109, in __call__
    return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)
  File "/python-path/python3.9/site-packages/transformers/pipelines/base.py", line 1116, in run_single
    model_outputs = self.forward(model_inputs, **forward_params)
  File "/python-path/python3.9/site-packages/transformers/pipelines/base.py", line 1015, in forward
    model_outputs = self._forward(model_inputs, **forward_params)
  File "/python-path/python3.9/site-packages/transformers/pipelines/text_generation.py", line 251, in _forward
    generated_sequence = self.model.generate(input_ids=input_ids, attention_mask=attention_mask, **generate_kwargs)
  File "/python-path/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/python-path/python3.9/site-packages/transformers/generation/utils.py", line 1297, in generate
    logger.warn(
Message: 'Both `max_new_tokens` (=70) and `max_length`(=73) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)'
Arguments: (<class 'UserWarning'>,)
```

### Expected behavior

1. It seems like that `transformers` gives a warning message when both `max_new_tokens` and `max_length` are set. But `max_length` is not set by me, but the downloaded pretrained model(`facebook/opt-1.3b`). So far as I know, almost all generative models set `max_length`, so this warning message is always shown up when the user set `max_new_tokens`, regardless of whether the user actually set `max_length` as well or not. However, to avoid unnecessary warning messages, I think **the warning message should be shown up only when the user *explicitly* set both `max_new_tokens` and `max_length`**

    - Even `max_length` value on the warning message is wrong, because `generation_config.max_length` is overwrited with `generation_config.max_new_tokens + input_ids_seq_length` if `max_new_tokens` has been set.

2. `logging` module throws an error, because `UserWarning` is passed as a parameter to `logger.warn()` method.
    ```python
    logger.warn(
        f"Both `max_new_tokens` (={generation_config.max_new_tokens}) and `max_length`(="
        f"{generation_config.max_length}) seem to have been set. `max_new_tokens` will take precedence. "
        "Please refer to the documentation for more information. "
        "(https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)",
        UserWarning,
    )
    ```

    - It seems like `transformers` use `warnings.warn()`, `logger.warn()`, and `logger.warning()`. I think **it should be consolidated to use one method consistently for better coherence.**