noamaanMulla-03/transformers-issues huggingface dataset:
Preserve exception cause when hub kernel loading fails
Author: SebTardif
Pull request: yes

## What does this PR do?

Preserves the original exception cause when hub kernel loading fails.

When `get_kernel(...)` raises a non-`ValueError` exception, `load_and_register_attn_kernel` wraps it in a `ValueError` with a message that includes `str(e)`. Without `from e`, Python discards the original traceback (`__cause__` is `None`), so debugging a failed kernel download only shows the wrapper string and not the hub/network stack.

```python
try:
    kernel = get_kernel(...)
except ValueError:
    raise
except Exception as e:
    raise ValueError(f"An error occurred while trying to load from '{repo_id}': {e}.")  # no from e
```

**After:** `raise ValueError(...) from e` so `exc.__cause__` is the original error.

This matches the chaining pattern used elsewhere in the library (e.g. `utils/hub.py`, `model_debugging_utils.py`).

**Origin:** Introduced in [#40542](https://github.com/huggingface/transformers/pull/40542) (2025-08-29).

**Test:**
```
Red:  __cause__ is None without the fix
Green: pytest tests/kernels/test_kernels.py::TestAttentionKernelRegistration::test_load_and_register_preserves_exception_cause  # PASSED
```

- [x] I confirm that this is not a pure code agent PR.

## Before submitting
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request), Pull Request section?
- [x] Did you write any new necessary tests?

## Who can review?

@drbh (kernels)


Comments:
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/29503653969) for the exact violations.

A maintainer can review and manually approve CI if a finding is a false positive.
Make non-blocking serve uvicorn thread a daemon with force_exit
Author: SebTardif
Pull request: yes

## What does this PR do?

Prevents the Python process from hanging when the non-blocking `transformers serve` uvicorn thread does not exit within `kill_server()`'s 2s join timeout.

### Problem

`start_server()` creates a **non-daemon** background thread for uvicorn (`daemon=False`). `kill_server()` sets `server.should_exit = True` and joins with `timeout=2`. If uvicorn does not leave `serve()` within 2 seconds:

1. `join` returns while the thread is still alive
2. Because the thread is non-daemon, interpreter shutdown waits forever for it
3. Tests and other non-blocking callers hang after teardown

This path is used heavily by the serve test suite (`non_blocking=True` + `kill_server()` in `tearDownClass`).

### Fix

1. Mark the uvicorn thread as `daemon=True` so a stuck serve cannot block process exit after the join timeout.
2. Set `server.force_exit = True` in addition to `should_exit` so uvicorn abandons a stuck graceful shutdown when possible.

The default CLI path (`non_blocking=False`) still runs uvicorn on the main thread via `server.run()` and is unchanged.

**Origin:** Background thread introduced in [#41487](https://github.com/huggingface/transformers/pull/41487) (2025-10-16) with `daemon=False`.

**Test:**
```
Red:  daemon=False and missing force_exit fail new unit tests
Green: pytest tests/cli/test_serve.py::TestServeThreadLifecycle  # 2 passed
```

- [x] I confirm that this is not a pure code agent PR.

## Before submitting
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request), Pull Request section?
- [x] Did you write any new necessary tests?

## Who can review?

@LysandreJik @SunMarc (serve)


Comments:
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/29503652982) for the exact violations.

A maintainer can review and manually approve CI if a finding is a false positive.
Add Flax Models to Pipelines
Author: ncoop57
Pull request: no
Labels: name: Feature request

# 🚀 Feature request

Hi y'all, I am trying a GPTNeo Flax model and am wanting to use it in the text generation pipeline. However, it is currently not supported. From looking at the current implementation of flax models and the text generation pipeline, it should be a relatively easy (famous last words) addition.

## Motivation

HF is heavily integrating Flax models (which I think is awesome!) into the library and has parroted many of the already existing parts of the transformers library to flax models, similar to what was done for TF models. The addition of the support of Flax models in the pipeline API will help those who are working with pure Flax models, especially for applications that will be use the model to accomplish some task.

## Your contribution

I would be willing to open a PR if one is not currently underway (I looked for one and didn't find any). However, I am new to flax so if the task is more difficult than I expect I probably will be not able to complete it.


Comments:
Hey @ncoop57, apologies for the extremely late reply, we're catching up on a long backlog.

Since you opened this, TensorFlow and Flax/JAX support has been fully removed from transformers library-wide (see #40760, part of the v5 line), so there are no longer any Flax models to wire into the pipeline API. Pipelines are now PyTorch-only.

Because of that I'm closing this as outdated. Thanks for the thoughtful request (and the offer to contribute!) back in the day, sorry it didn't line up with where the library ended up going.
[docs] Inkling
Author: stevhliu
Pull request: yes

<!-- ci-dashboard-badge:start -->
[![CI](https://transformers-ci.lor-e.huggingface.cool/badge/pr?pr=47350)](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47350)
<!-- ci-dashboard-badge:end -->

Add model doc and update checkpoints in docstrings

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_47350). 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: inkling

<!-- ci-dashboard-recap:start -->

---

### CI recap

**Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47350)
**Latest run:** [29450862651:1](https://github.com/huggingface/transformers/actions/runs/29516109684)
**Result:** `success` | **Jobs:** 2 | **Tests:** 24 | **Failures:** 0 | **Duration:** 1m 59s

<!-- ci-dashboard-recap:end -->
Fix TimesFM 2.5 window_size AttributeError
Author: kashif
Pull request: yes

<!-- ci-dashboard-badge:start -->
[![CI](https://transformers-ci.lor-e.huggingface.cool/badge/pr?pr=47363)](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47363)
<!-- ci-dashboard-badge:end -->

Passing `window_size` to `TimesFm2_5ModelForPrediction` crashed because `forward` called `self._timesfm_moving_average`, but the modular converter renames the static method to `_timesfm2_5_moving_average`. Fixed the call site to match.

Fixes #46821

Repro from the issue now runs fine:
```python
model(past_values=forecast_input_tensor, window_size=5)
```

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

run-slow: timesfm2_5

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/29501577253) for the exact violations.

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

<!-- ci-dashboard-recap:start -->

---

### CI recap

**Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47363)
**Latest run:** [29501487908:1](https://github.com/huggingface/transformers/actions/runs/29501580599)
**Result:** `success` | **Jobs:** 2 | **Tests:** 10 | **Failures:** 0 | **Duration:** 40s

<!-- ci-dashboard-recap:end -->

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_47363). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Add Restormer
Author: tushdon2
Pull request: no
Labels: name: New model

### Model description

**Restormer: Efficient Transformer for High-Resolution Image Restoration** was published in CVPR 2022, which introduced a new Vision Transformer based architecture for Image Restoration tasks like Deraining, Motion Deblurring, Defocus Deblurring and Denoising. It reduced the time complexity of Self Attention in Vision Transformers from O(n<sup>2</sup>) to O(n) by introducing **Multi-Dconv Head Transposed Attention**.  It also introduced **Gated-Dconv Feed-Forward Network**. 

@manyana72 and I would like to add this model to Huggingface. 

cc: @NielsRogge 

### Open source status

- [X] The model implementation is available
- [X] The model weights are available

### Provide useful links for the implementation

[Paper](https://arxiv.org/pdf/2111.09881.pdf), [Code Implementation](https://github.com/swz30/Restormer) and [pretrained model weights](https://github.com/swz30/Restormer/releases/tag/v1.0)

Comments:
Hi @tushdon2, please let me know if and how can I contribute to this model.

Hey @tushdon2, sorry for the very slow reply, we're working through a large backlog.

Restormer is a solid architecture, but core transformers has since moved to a "model on the Hub first" path for new additions: you can host the modeling code next to the weights and load it today with `trust_remote_code=True`, no upstream merge required. Several Restormer checkpoints already live on the Hub (e.g. [deepinv/Restormer](https://huggingface.co/deepinv/Restormer), [VaishV/RestormerForTextDeblurring](https://huggingface.co/VaishV/RestormerForTextDeblurring)), so the model is usable right now. The relevant guides are [custom_models.md](https://github.com/huggingface/transformers/blob/main/docs/source/en/custom_models.md) and [add_new_model.md](https://github.com/huggingface/transformers/blob/main/docs/source/en/add_new_model.md).

Given that nothing has landed in the ~3 years since this was filed, I'm closing it to keep the issue tracker actionable. This isn't a "no", if you, @manyana72 or @atharvakavitkar want to pick it up, a Hub-hosted implementation is the fastest route, and we're happy to reopen or review a draft PR. Thanks for the request!
examples/training/distributed_training.py crashes on import: LOCAL_RANK/WORLD_SIZE/RANK are overwritten by OMPI_* vars
Author: berkgungor
Pull request: no

### System Info

- `transformers`: main (as of 2026-07-16)
- File: [`examples/training/distributed_training.py`](https://github.com/huggingface/transformers/blob/main/examples/training/distributed_training.py)

### Who can help?

@ArthurZucker @muellerzr — this looks like leftover WIP from the distributed training example.

### Reproduction

Run the example with the launcher the top comment says it supports (`torch.distributed.launch` / `torchrun`), i.e. **without** OpenMPI:

```bash
torchrun --nproc_per_node=2 --nnodes=1 examples/training/distributed_training.py --backend nccl
```

This immediately crashes with:

```
KeyError: 'OMPI_COMM_WORLD_LOCAL_RANK'
```

### Expected behavior

The script should run under either launcher (`torchrun`/`torch.distributed.launch` **or** `mpirun`), since the docstring at the bottom shows both.

### Root cause

At the top of the file the same three variables are assigned twice, back‑to‑back, from two different launcher conventions:

```python
# Environment variables set by torch.distributed.launch
LOCAL_RANK = int(os.environ["LOCAL_RANK"])
WORLD_SIZE = int(os.environ["WORLD_SIZE"])
WORLD_RANK = int(os.environ["RANK"])

LOCAL_RANK = int(os.environ["OMPI_COMM_WORLD_LOCAL_RANK"])
WORLD_SIZE = int(os.environ["OMPI_COMM_WORLD_SIZE"])
WORLD_RANK = int(os.environ["OMPI_COMM_WORLD_RANK"])
```

Effects:

1. The `LOCAL_RANK` / `WORLD_SIZE` / `RANK` block is dead code — it's immediately overwritten.
2. When launched with anything other than OpenMPI, the module raises `KeyError` on import, before `argparse` even runs.
3. When launched with `mpirun`, the first block still raises `KeyError` because `LOCAL_RANK`/`WORLD_SIZE`/`RANK` aren't set.

So as shipped, the example only works if **both** launcher conventions set their env vars at the same time, which is essentially never.

### Suggested fix

Pick the launcher based on which env vars are actually present, e.g.:

```python
if "OMPI_COMM_WORLD_LOCAL_RANK" in os.environ:
    LOCAL_RANK = int(os.environ["OMPI_COMM_WORLD_LOCAL_RANK"])
    WORLD_SIZE = int(os.environ["OMPI_COMM_WORLD_SIZE"])
    WORLD_RANK = int(os.environ["OMPI_COMM_WORLD_RANK"])
else:
    # torchrun / torch.distributed.launch
    LOCAL_RANK = int(os.environ["LOCAL_RANK"])
    WORLD_SIZE = int(os.environ["WORLD_SIZE"])
    WORLD_RANK = int(os.environ["RANK"])
```

Happy to send a PR if the maintainers agree with this direction.


Comments:
Closing this — on reflection this is a minor cleanup in an example script, not worth a separate issue. Will re‑file if there's an actionable, more critical problem to report.
[docs] Exporters
Author: stevhliu
Pull request: yes

<!-- ci-dashboard-badge:start -->
[![CI](https://transformers-ci.lor-e.huggingface.cool/badge/pr?pr=47374)](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47374)
<!-- ci-dashboard-badge:end -->

Refactors the exporters docs a bit by user intent (using exporters vs extending exporters) and make it shorter and more scannable.

- Split the doc by audience so the user guide is focused on using an exporter and a separate guide for contributors who want to patch/fix.
- Replace dense stages for every exporter with one concrete worked example and then a more compact stage reference for each exporter.
- Clearer distinction when to reach for patch vs fix and fold into one section instead of two separate ones.
- Add code snippet for `AutoHfExporter` and `AutoExportConfig`.
- Add ExecuTorch `cuda` backend requires CUDA and `xnnpack` works for CPU-only (#47201).

Comments:
<!-- ci-dashboard-recap:start -->

---

### CI recap

**Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47374)
**Latest run:** [29531796484:1](https://github.com/huggingface/transformers/actions/runs/29531796484)
**Result:** `success` | **Jobs:** 2 | **Tests:** 24 | **Failures:** 0 | **Duration:** 1m 44s

<!-- ci-dashboard-recap:end -->

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

<!-- ci-dashboard-badge:start -->
[![CI](https://transformers-ci.lor-e.huggingface.cool/badge/pr?pr=47320)](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47320)
<!-- ci-dashboard-badge:end -->

We prototyped response parsing using a `response_schema` attribute, but this had a few issues in practice: It was fragile, the regexes were hard to write, and it required a complete message to parse, so it didn't support streaming.

We've got a new and much more robust system now using the `response_template` attribute. The only models using `response_schema` are Gemma4, and there are PRs open to all of them to update that. Once that update is in, we should be able to merge this and drop `response_schema` entirely, and `response_template` is then the official and only way to do response parsing, and we can start adding those templates everywhere!

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

run-slow: gemma4_unified

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

Should be ready for review! This touches the serving code a bit so cc @sunmarc @remi-or @lysandrejik. Other than that it's mostly mechanical changes and deleting references/imports, plus updating the Gemma4 conversion scripts to only add new-style `response_template`, so it should be a pretty quick review

:rotating_light: Don't merge it yet, though - slow tests for Gemma4 will break until we've merged the PRs to update the model repos too

<!-- ci-dashboard-recap:start -->

---

### CI recap

**Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47320)
**Latest run:** [29343113953:1](https://github.com/huggingface/transformers/actions/runs/29343113953)
**Result:** `success` | **Jobs:** 15 | **Tests:** 165,327 | **Failures:** 0 | **Duration:** 14h 27m

<!-- ci-dashboard-recap:end -->

LGTM, thanks!
Experiments with Neuron
Author: michaelbenayoun
Pull request: yes

<!-- ci-dashboard-badge:start -->
[![CI](https://transformers-ci.lor-e.huggingface.cool/badge/pr?pr=47306)](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47306)
<!-- ci-dashboard-badge:end -->

# What does this PR do?

Just experiments for training on Neuron.
Do not review and do not merge.

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

<!-- ci-dashboard-recap:start -->

---

### CI recap

**Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47306)
**Latest run:** [29277071567:1](https://github.com/huggingface/transformers/actions/runs/29536516862)
**Result:** `failure` | **Jobs:** 2 | **Tests:** 24 | **Failures:** 0 | **Duration:** 1m 53s

> **Code quality check failed**: test jobs were skipped. Fix the code quality issues and push again to run tests.

<!-- ci-dashboard-recap:end -->
[serge] integration failure triage - 2026-07-13
Author: github-actions[bot]
Pull request: no

<!-- serge-triage-run:integration-failure-triage:2026-07-13 -->

Automated **integration-failure triage** for the daily CI window `2026-07-07 → 2026-07-13`.

This issue was generated by AI-assisted automation. The grouping, summaries, and recommended follow-up can be incomplete or misleading; verify the failures before acting.

Serge dispatched one task per failure group below — each opens or updates its own PR on a `serge/fix/itf-<fingerprint>` branch. This table is refreshed in place as Serge runs: a group links its `#<pr>` when opened, shows `🚫 no fix` when Serge found no safe change, `⚠️ task failed` on error, or `(pending)` while still running (a late PR links on the next nightly run).

## Dispatched failure groups

| Model | Error | Occurrences | PR |
| --- | --- | --- | --- |
| `whisper` | other — other (20), shape/size mismatch (2) | 22 | ⚠️ task failed |
| `whisper` | output_mismatch — list output differs (10), other (6), tensor values differ (4) | 20 | #47150 |
| `musicgen_melody` | output_mismatch — tensor values differ (16) | 16 | ⚠️ task failed |
| `gemma` | output_mismatch — list output differs (14) | 14 | ⚠️ task failed |
| `edgetam` | import_or_config — other (12) | 12 | #47122 |
| `glm46v` | other — other (12) | 12 | #47281 |
| `hunyuan_vl` | output_mismatch — list output differs (8), other (4) | 12 | ⚠️ task failed |
| `minimax_m3_vl` | load_error — other (12) | 12 | #47280 |
| `diffusion_gemma` | output_mismatch — tensor values differ (6), list output differs (4) | 10 | ⚠️ task failed |
| `gemma3` | output_mismatch — list output differs (8), other (2) | 10 | #47310 |
| `gemma3n` | output_mismatch — list output differs (10) | 10 | ⚠️ task failed |
| `glm_ocr` | output_mismatch — list output differs (10) | 10 | ⚠️ task failed |
| `deepseek_v32` | load_error — other (8) | 8 | #47266 |
| `falcon_mamba` | output_mismatch — other (6), list output differs (2) | 8 | #47124 |
| `grounding_dino` | output_mismatch — tensor values differ (6), other (2) | 8 | ⚠️ task failed |
| `higgs_audio_v2` | output_mismatch — tensor values differ (8) | 8 | ⚠️ task failed |
| `mamba2` | OOM — other (8) | 8 | ⚠️ task failed |
| `mllama` | output_mismatch — other (8) | 8 | ⚠️ task failed |
| `mpt` | other — other (8) | 8 | ⚠️ task failed |
| `peft_integration` | other — other (8) | 8 | ⚠️ task failed |

_Generated 2026-07-16T00:29:35+00:00._

Comments:
Superseded by #47377 — closing this stale nightly integration-failure triage issue. Open PRs stay linked from the current issue.