`do_sample` does not work in Qwen3 Model‘s `generate` method
Author: Hermit-w
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.56.1
- Platform: Linux-4.18.0-193.28.1.el8_2.x86_64-x86_64-with-glibc2.28
- Python version: 3.12.11
- Huggingface_hub version: 0.34.4
- Safetensors version: 0.5.3
- Accelerate version: 1.10.1
- Accelerate config:    not found
- DeepSpeed version: 0.17.5
- PyTorch version (accelerator?): 2.8.0+cu128 (CUDA)
- 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?: no
- Using GPU in script?: yes
- GPU type: NVIDIA H800

### Who can help?

_No response_

### 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

Simply run the scripts as follows:
```python
import os

import torch
import transformers

if __name__ == "__main__":
    model_name = "Qwen/Qwen3-0.6B"
    model_path = model_name
    
    temperature: float = 1e-5
    device = torch.device(f"cuda")
    model = transformers.AutoModelForCausalLM.from_pretrained(model_path).to(device).eval()
    tokenizer = transformers.AutoTokenizer.from_pretrained(model_path)

    prompt = "Hello, please introduce yourself.\n"

    inputs = tokenizer(prompt, return_tensors="pt").to(device)
 
    with torch.inference_mode():
        generate_config = transformers.GenerationConfig(
            num_beams=1,
            do_sample=False,# this doesn't work
            max_new_tokens=200,
            # top_k=1 # this works well
            )
        outputs = model.generate(inputs['input_ids'], attention_mask = inputs['attention_mask'], generation_config=generate_config)
        print("".join(tokenizer.batch_decode(outputs)))
```
The document indicates that with `num_beams=1` and `do_sample=False`, it will behaviour like *greedy decoding*, which is expected to get same response with same prompt. But when I run the scripts twice the responses are different and it says the `do_sample=False` are modified to `do_sample=True`.

![Image](https://github.com/user-attachments/assets/344af711-2737-489a-9f84-dca9338f3320)

The result is shown in the following fig.

![Image](https://github.com/user-attachments/assets/2ec99005-f9d3-4df9-bd34-2dd99567c37e)

### Expected behavior

As shown in the output tips in the figure, I am expecting by setting `do_sample=False` in the `generate_config` explicitly, the value should not be modifed by model-specific defaults as other values.
![Image](https://github.com/user-attachments/assets/4c7fe43b-dea9-49ab-b572-4ea863c386de)

However, when I try to set `top_k=1`, it works well to get same response even if it says the value may be ignored.

![Image](https://github.com/user-attachments/assets/bf15c28e-c57a-4a95-b6cb-8d4a26949f57)

Comments:
cc @gante (see also the PR at #41075)

@Hermit-w Thank you for opening this issue 🤗 

I'm aware of it 😭 It's due to a backwards compatibility piece of logic + generation default flags. Solving it correctly is tricky and will break backwards compatibility in some cases, but I will work on in for the v5 release.

Meanwhile, to ignore model-specific default flags, please call `generate` with `use_model_defaults=False`, i.e.

```py
generation_outputs = model.generate(**model_inputs, ..., use_model_defaults=False)
```

Thanks for your answer and the alternative solutions.
It seems to be a complex problem. I will close this issue and by the way,  using `top_k=1` is also a temporary solution that works well.