torch._dynamo.exc.Unsupported: call_method UserDefinedObjectVariable(Logger)
Author: ghost
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.43.0
- Platform: Linux-5.15.0-118-generic-x86_64-with-glibc2.35
- Python version: 3.10.14
- Huggingface_hub version: 0.23.3
- Safetensors version: 0.4.3
- Accelerate version: 0.24.1
- Accelerate config:    not found
- PyTorch version (GPU?): 2.1.1+cu121 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: Tesla V100S-PCIE-32GB

### Who can help?

_No response_

### Information

- [X] The official example scripts
- [ ] 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

from datasets import load_dataset
from transformers import WhisperProcessor, WhisperForConditionalGeneration
import torch

ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
audio_sample = ds[0]["audio"]

processor = WhisperProcessor.from_pretrained("openai/whisper-tiny")
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny")
model = model.to('cuda')

model.generation_config.cache_implementation = "static"
model.forward = torch.compile(model.forward, mode="reduce-overhead", fullgraph=True)

input_features = processor(
    audio_sample["array"], sampling_rate=audio_sample["sampling_rate"], return_tensors="pt"
).input_features

input_features = input_features.to("cuda")
_ = model.generate(input_features)

### Expected behavior

it does not raise an error
as of now it raises
  File "/home/jsoto/.pyenv/versions/3.10.14/envs/triton-server/lib/python3.10/site-packages/torch/_dynamo/exc.py", line 172, in unimplemented
    raise Unsupported(msg)
torch._dynamo.exc.Unsupported: call_method UserDefinedObjectVariable(Logger) warning_once [ConstantVariable(str)] {}

Comments:
related to https://github.com/huggingface/transformers/issues/31987

if I put fullgraph=False, it works fine

the same problem arises with torch 2.2.1

the same problem arises with torch 2.3.1

a similar problem arises with torch 2.4.0
  File "/home/jsoto/.pyenv/versions/3.10.14/envs/triton-server/lib/python3.10/site-packages/torch/_dynamo/exc.py", line 221, in unimplemented
    raise Unsupported(msg)
torch._dynamo.exc.Unsupported: Logger not supported for non-export cases

it seems the problem is related to multilingual model...
If I use tiny, it gives the error above
I I use tiny.en, everything works fine


@sanchit-gandhi 

when putting a mulitlingual model I get the following error
  File "/home/jsoto/.pyenv/versions/3.10.14/envs/triton-server/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 464, in inner
    raise exc.UserError(
torch._dynamo.exc.UserError: Dynamic control flow is not supported at the moment. Please use functorch.experimental.control_flow.cond to explicitly capture the control flow. For more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#cond-operands

I found the problem. It lies in the fact that if you do not specify the language
torch compile will try to run detect language (that contains an if condition [here](https://github.com/huggingface/transformers/blob/3bb7b05229466ce820f76dadb250a848e7eb22e7/src/transformers/models/whisper/modeling_whisper.py#L688)) and thus fails
the solution is to provide the language

for the record the versions are:
torch==2.3.0
torchaudio==2.3.0
transformers==4.44.1

Well, we can keep this open as language detection would be nice to have in compile as well no?