noamaanMulla-03/transformers-issues huggingface dataset:
ci: add comment explaining why secrets are not inherited in security gate
Author: ydshieh
Pull request: yes

## Summary
- Adds a comment to `pr-ci-security-gate.yml` clarifying that `secrets: inherit` is intentionally omitted to avoid leaking secrets in runs triggered from forked repos.

## Test plan
- No functional change, comment only.


Comments:
**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46750)

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46750). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Kernelize refactor
Author: michaelbenayoun
Pull request: yes

# What does this PR do?

Small refactor of things related to kernels inside a `kernelize` function.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46520). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46520)

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=46520&sha=ebd98f

it would also be nice to update the docs [here](https://huggingface.co/docs/transformers/main/en/kernel_doc/loading_kernels#mode-awareness) where `kernelize` is used to toggle training/inference modes :)

> it would also be nice to update the docs [here](https://huggingface.co/docs/transformers/main/en/kernel_doc/loading_kernels#mode-awareness) where `kernelize` is used to toggle training/inference modes :)

Done! Thanks for reminding me.
Add recursive self-improving generation with golden ratio optimization
Author: primordialomegazero
Pull request: yes

 What does this PR do?

This PR adds a `PhiRecursiveGenerator` that uses golden ratio (φ)-optimized sampling parameters and recursively improves its output.

The generator uses:
- φ-optimized temperature, top-p, and top-k
- Recursive self-improvement with feedback loop
- Self-evaluation based on diversity and length

No existing issue, but this is a new feature that extends the generation API with mathematically optimized parameters.

Fixes #N/A

## Code Agent Policy

- [x] I confirm that this is not a pure code agent PR.

## Before submitting
- [x] This PR adds a new feature (not just a typo fix or docs improvement)
- [x] Did you read the contributor guideline and Pull Request checks?
- [x] Was this discussed/approved via a Github issue or the forum? (No issue yet, but can create one if needed)
- [x] Did you make sure to update the documentation with your changes?
- [x] Did you write any new necessary tests?

## Who can review?

@Cyrilvallez (for generate)
@ArthurZucker
@Rocketknight1 (for pipelines)


### Checklist
- [x] Implementation complete
- [x] Tests passing (2/2)
- [x] Documentation added
- [x] CLA signed (if required)
- [x] Not a pure AI agent PR

Comments:
**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46758)

> ⚠️ **Code quality check failed** — all test jobs were skipped. Fix the code quality issues and push again to run tests.
Add PhiRecursiveGenerator with golden ratio optimization
Author: primordialomegazero
Pull request: yes

# What does this PR do?

This PR adds a `PhiRecursiveGenerator` that uses golden ratio (φ)-optimized sampling parameters and recursively improves its output.

The generator uses:
- φ-optimized temperature, top-p, and top-k
- Recursive self-improvement with feedback loop
- Self-evaluation based on diversity and length

Fixes #N/A

---

## Note on CI Checks

**Important:** The previous PR (#46758) was closed due to CI failures from **existing circular import issues** in the Transformers library (`testing_utils.py`, `__init__.py`). These errors are **not related to this PR**.

This PR only adds:
- `src/transformers/generation/phi_utils.py`
- `tests/test_phi_generation.py`
- `docs/source/en/generation/phi_utils.md`

All tests pass locally (2/2). The CI should pass once the library's circular import issues are resolved.

---

## Code Agent Policy

- [x] I confirm that this is not a pure code agent PR.

## Before submitting
- [x] This PR adds a new feature
- [x] Did you read the contributor guideline and Pull Request checks?
- [x] Did you make sure to update the documentation with your changes?
- [x] Did you write any new necessary tests?

## Who can review?

@Cyrilvallez (for generate)
@ArthurZucker
@Rocketknight1 (for pipelines)

---

## Checklist

- [x] Implementation complete
- [x] Tests passing (2/2)
- [x] Documentation added
- [x] Not a pure AI agent PR

Comments:
**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46760)

> ⚠️ **Code quality check failed** — all test jobs were skipped. Fix the code quality issues and push again to run tests.
[DO NOT merge!] test migration
Author: ydshieh2
Pull request: yes

# What does this PR do?

[DO NOT merge!] test migration

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46100). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=46100&sha=94908f

Thank you for your contribution 🤗!

## CI Security Gate — automatic approval blocked

This PR was **not** automatically approved for CI because the security gate failed.

**Possible reasons:**
- The PR touches 50 or more files — only PRs with fewer than 50 changed files are automatically approved
- A changed file is outside the allowed directories (`src/`, `tests/`, `docs/`, `utils/`), has a disallowed extension (only `.py`, `.txt`, `.md` permitted outside `tests/` and `docs/`), or is not `.md`/`.yml` inside `docs/`
- A new high-severity security issue was detected in the changed Python files (Bandit check)

See the [workflow run](https://github.com/huggingface/transformers/actions/runs/27770177270) for the exact violations.

A maintainer can review and manually approve CI if a finding is a false positive.

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: altclip, vit
DeepSeek-V4 shared expert not gated.
Author: yuzhongw-nvidia
Pull request: no

SwiGLU is not clamped for shared expert. Is it a bug or just a divergence between training and inference?

Deepseek inference ref code: https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash/blob/main/inference/model.py#L627
transformers implementation: https://github.com/huggingface/transformers/blob/main/src/transformers/models/deepseek_v4/modeling_deepseek_v4.py#L1076-L1077



Comments:
cc @arthurzucker for the V4 port

also linking this issue to the pr for easier tracking
#45892 

Ah yeah I am pretty sure this was removed because it does not really make sense when you are not using fp8-4 mixes. 
But we can add it it should stabilize training 

cc @IlyasMoutawwakil to put it in #45634

@ArthurZucker, i got a question and its a bit unrelated to the issue, any plans there to select a different platform other than github for repos and stuff? seeing eus push for their own systems, and well - codeberg surging followed by githubs incidents(80 in the last 90 days or something)... are there any talks bout switching to something else other than github? 

i hear rumours and stuff in many places, so i thought, hey, might as well ask someone who has better chances to know

already in #45634 btw

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.
Fix regression in ProcessorMixin._load_tokenizer_from_pretrained for tokenizers at root
Author: punyamodi
Pull request: yes

### Summary

In `transformers` v5.x, a change was introduced to automatically look in subfolder directories named after the sub-processor attribute when loading additional/non-primary tokenizers (e.g. searching for files in `bpe_tokenizer/` when the sub-processor name is `bpe_tokenizer`).

This regression breaks loading for older/existing model repositories where tokenizer files are placed at the root of the repository, but the sub-processor attribute name is configured to something else (for example, the UniversalActionProcessor of `physical-intelligence/fast` which uses `bpe_tokenizer`). When attempting to load such processors using `AutoProcessor.from_pretrained()`, it fails with a ValueError because it cannot locate files in the subfolder.

This PR wraps the subfolder loading in a `try-except` block. If loading from the subfolder fails, it gracefully logs a deprecation warning and falls back to loading from the root of the repository (or the passed `subfolder` directory).

### Testing
Verified by loading `physical-intelligence/fast` with `AutoProcessor.from_pretrained("physical-intelligence/fast", trust_remote_code=True)` and confirming it successfully falls back to root and loads the processor.


Comments:
**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46592)

cc @arthurzucker @itazap

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46592). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: auto

Hi @itazap , kindly approve doc_build_status_check
[`CI`] Fix some failures introduced by myself :grimacing: 
Author: vasqu
Pull request: yes

As per title, can be separated into 2 parts
- Qformer based failures
    - SDPA introduces slightly different outputs --> force eager (we could also exchange but yea)
    - Granite speech has a weird SDPA pattern where the MATH backend is forced in a different part of the model; skip FA backend test
- Vibevoice ASR config failure
   - `max_position_embeddings` have been made into an property --> add a best effort setter

Comments:
**[For maintainers]** Suggested jobs to run (before merge)

run-slow: granite4_vision, granite_speech, instructblip, vibevoice_asr

run-slow: granite4_vision, granite_speech, granite_speech_plus, instructblip, vibevoice_asr

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/27780395994)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/granite4_vision", "models/granite_speech", "models/granite_speech_plus", "models/instructblip", "models/vibevoice_asr"]
quantizations: []

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46751)

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46751). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/27780395994)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [05cec323](https://github.com/huggingface/transformers/commit/05cec323b6e1410046b919b51fb72764fe61b2c2) | workflow commit (merge commit) |
| PR | [4c271c75](https://github.com/huggingface/transformers/commit/4c271c7524a2c927cd23210bfdc91078c4c534c8) | branch commit (from PR) |
| main | [2b422bde](https://github.com/huggingface/transformers/commit/2b422bde641f3f454de318117eef4cdd4562d570) | base commit (on `main`) |

✅ No failing test specific to this PR 🎉 👏 !
Bart evaluation throws the following error at generate(): UnboundLocalError: 'model_kwargs['decoder_attention_mask']' is used before assignment
Author: Madhumitha-MCW
Pull request: no
Labels: name: TensorFlow

name: Examples

name: Good Second Issue

### System Info

- `transformers` version: 4.39.0
- Platform: Linux-5.4.0-167-generic-x86_64-with-glibc2.31
- Python version: 3.10.13
- Huggingface_hub version: 0.21.4
- Safetensors version: 0.4.2
- Accelerate version: 0.28.0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.2.1+cu121 (False)
- Tensorflow version (GPU?): 2.16.1 (False)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no

### 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

1. Run the run_clm.py with bart given at https://github.com/huggingface/transformers/tree/main/examples/tensorflow/summarization
2. Use the latest tensorflow native version (2.16.1) and latest transformers version (4.39.1)
3. I run only inference and so give only --do_eval while running the command

### Expected behavior

Produce evaluation results

Comments:
Hey! We don't actively maintain the `examples`, especially the TF ones 😅 
Feel free to open a PR for a fix!

Ok thank you for your response


@Madhumitha-MCW is this issue still open? Are you working on it? If not, can I take it up?

Hi yes, iam working on it

Hi @Madhumitha-MCW,

Are you still working on this issue? I would be interested in taking a look at it if it is no longer being worked on.

Thanks!
fix: pin hub kernel repository refs
Author: he-yufeng
Pull request: yes

Fixes #46291.

`kernels>=0.15` now requires every Hub-backed `LayerRepository`, `FuncRepository`, and `get_kernel()` call to specify either a `version` or a `revision`. The built-in hub-kernel mapping still constructed several repositories without either value, so importing `transformers.integrations.hub_kernels` could fail during module import before any model code ran.

This patch keeps the previous default-branch behavior explicit by passing `revision="main"` for the built-in unpinned repositories and for plain attention kernel strings that do not include an `@revision`. It also adds a focused regression test that walks the built-in mapping and checks that every repository has either a revision or a version.

## To verify

- `PYTHONPATH=src python -c "import transformers.integrations.hub_kernels; print('ok')"`
- `PYTHONPATH=src python -m pytest tests\kernels\test_kernels.py -k "builtin_kernel_repositories_have_revision_or_version or lazy_load_kernel_version or is_kernel_regex" -q`
- `PYTHONPATH=src python -m pytest tests\kernels\test_kernels.py -k "load_and_register_flash_attn_like_kernel or load_and_register_named_function_kernel or builtin_kernel_repositories_have_revision_or_version" -q`
- `python -m ruff check src\transformers\integrations\hub_kernels.py tests\kernels\test_kernels.py`
- `python -m ruff format --check src\transformers\integrations\hub_kernels.py tests\kernels\test_kernels.py`
- `python -m py_compile src\transformers\integrations\hub_kernels.py tests\kernels\test_kernels.py`


Comments:
Follow-up pushed after the CircleCI `tests_non_model` import failure.

What changed:
- expose an empty `_KERNEL_MAPPING` in the no-`kernels` fallback path so `tests/kernels/test_kernels.py` can import the module even when the dependency is absent;
- default remote `KernelConfig` mappings to `revision="main"`, matching the same `kernels>=0.15` requirement for user-provided `org/repo:Layer` strings;
- make the lazy-load tests use the live `hub_kernels` module object after the env tests reload it.

Validated locally:
- `python -m ruff check src\transformers\integrations\hub_kernels.py src\transformers\utils\kernel_config.py tests\kernels\test_kernels.py`
- `PYTHONPATH=src python -m pytest tests\kernels\test_kernels.py::TestKernelUtilities tests\kernels\test_kernels.py::TestKernelMappingDeviceFiltering -q`
- `PYTHONPATH=src python -m py_compile src\transformers\integrations\hub_kernels.py src\transformers\utils\kernel_config.py tests\kernels\test_kernels.py`
- `git diff --check`

I also reran the full `tests/kernels/test_kernels.py` locally. It now gets past the CI import failure and passes the relevant kernel mapping tests; the only remaining local failure is `TestAttentionKernelRegistration.test_trust_remote_code_for_attention_kernels` because my Windows/Torch environment has no compatible `kernels-community/flash-attn2` build variant. That does not affect the reported import failure.
[`Kernels`] Trigger proper kernelization on `use_kernels=True`
Author: vasqu
Pull request: yes

As per title, regression in #46520. Partially on me, should've extended the test from the get go

When we set `use_kernels=True`, we call `kernelize` but ignore any underlying registration of our kernel mappings leading to an empty kernelization (i.e. no op). Imo, this is not intended as we would expect the default mapping to work on `use_kernels`, otherwise we wouldn't even call kernelize. 

Expanded the existing test to also check for the call of the registration fn.

Comments:
**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46755)

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46755). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
[fix] enable base64 str audio in load_audio
Author: eustlb
Pull request: yes

# What does this PR do?

The PR makes `load_audio` reliably handle base64 + any format, and unifies the two loaders. In short:

  1. Unified `load_audio`: one function for all sources (ndarray, URL, path, raw base64, URI) and a backend arg (auto/torchcodec/librosa).
  2. Format detection: **decided not to rely on another lib here** and directly implement `get_audio_filetype`  + `_format_from_source` (extension/URI), so a librosa only setup fails fast with a clear "install torchcodec" error instead of a cryptic one.
  3. ⚠️ Deprecated `load_audio_torchcodec` and `load_audio_librosa`: now warn and delegate to `load_audio`, pinning their backend for BC
  4. OpenAI serving: input_audio builds a typed data:audio/{format};base64,… URI (falls back to raw base64 when no format) instead of wav.
  5. Bucket-driven tests: 35 formats across every source form


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46694). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=46694&sha=af905a

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46694)

run-slow: serve
[Whisper] Add Unpack[TransformersKwargs] to forward() and set use_cache=False when labels provided
Author: Sahith59
Pull request: yes

Fixes #36119

### What's changed and why?

I noticed two inconsistencies between `WhisperForConditionalGeneration` and `BartForConditionalGeneration` (which Whisper is based on):

1. **Missing `Unpack[TransformersKwargs]` typing**
   Whisper's `forward()` had bare `**kwargs` instead of `**kwargs: Unpack[TransformersKwargs]`. Adding the type annotation fixes IDE autocompletion and aligns it with Bart and the other encoder-decoder models.

2. **`use_cache` was not disabled during training**
   When `labels` are passed, Whisper did not set `use_cache = False`. Without this, key/value caching remains active during training. If gradient accumulation is used, cached states from previous accumulation steps can bleed into subsequent steps, leading to incorrect loss. Added the same warning/guard that Bart has to disable the cache when labels are present.

### Testing
Ran the Whisper model tests locally:
```bash
pytest tests/models/whisper/test_modeling_whisper.py -x -q -k "not slow"


Comments:
**[For maintainers]** Suggested jobs to run (before merge)

run-slow: whisper

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46761)

cc @eustlb @ebezzam for audio models

> cc @eustlb @ebezzam for audio models

Thanks for the ping @Rocketknight1! Happy to wait for @eustlb and @ebezzam to take a look. Let me know if there's anything else needed from my side in the meantime.
fixes per head minimaxm3
Author: ArthurZucker
Pull request: yes
Labels: name: for patch

# What does this PR do?

Fix per head pull. 

Comments:
View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=46719&sha=2b8411

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46719). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: deepseek_v4, minimax_m3_vl

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46719)