transformers - ✅(Solved) Fix [Bug] Bare `except:` in FuyuBatchFeature.convert_to_tensors() swallows KeyboardInterrupt and hides real errors [1 pull requests, 3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#45803Fetched 2026-05-07 03:31:18
View on GitHub
Comments
3
Participants
2
Timeline
11
Reactions
0
Timeline (top)
commented ×3mentioned ×3subscribed ×3cross-referenced ×1

Error Message

Exact pattern copied from image_processing_fuyu.py lines 99-108

def buggy_safe_convert_tensor(elem): def _convert_tensor(e): raise KeyboardInterrupt() # simulates Ctrl+C during processing key = "pixel_values" try: return _convert_tensor(elem) except: # noqa E722 # ← exact copy of the bug raise ValueError( "Unable to create tensor, you should probably activate padding " "with 'padding=True' to have batched tensors with the same length." )

try: buggy_safe_convert_tensor(None) except ValueError as e: print(f"SWALLOWED: KeyboardInterrupt became -> ValueError: {e}") except KeyboardInterrupt: print("KeyboardInterrupt escaped correctly")

Root Cause

Bare except: is used inside _safe_convert_tensor() in FuyuBatchFeature.convert_to_tensors(). Because bare except: catches all BaseException subclasses — including KeyboardInterrupt and SystemExit — pressing Ctrl+C during Fuyu image processing is silently swallowed and re-raised as a misleading ValueError. Real conversion errors are also hidden since the original exception is discarded.

Fix Action

Fixed

PR fix notes

PR #45808: [Fuyu] Remove FuyuBatchFeature subclass, use BatchFeature with skip_tensor_conversion

Description (problem / solution / changelog)

Fixes #45803

As suggested by @zucchini-nlp, removes the custom FuyuBatchFeature subclass from both image_processing_fuyu.py and image_processing_pil_fuyu.py and replaces it with plain BatchFeature using the existing skip_tensor_conversion parameter.

The FuyuBatchFeature subclass existed solely to:

  1. Handle overflowing_values key during tensor conversion (via a bare except: that also swallowed KeyboardInterrupt)
  2. Handle nested list[list[Tensor]] structures in .to()

Both are now handled cleanly:

  • _preprocess uses skip_tensor_conversion=["images", "overflowing_values"]
  • preprocess_with_tokenizer_info uses skip_tensor_conversion for all nested-list keys

Tested on Windows 11, Python 3.13.7, PyTorch 2.11.0+cu126.

Changed files

  • src/transformers/models/fuyu/image_processing_fuyu.py (modified, +13/-116)
  • src/transformers/models/fuyu/image_processing_pil_fuyu.py (modified, +13/-118)

Code Example

# image_processing_fuyu.py, lines 99108
def _safe_convert_tensor(elem):
    try:
        return _convert_tensor(elem)
    except:  # noqa E722   ← catches KeyboardInterrupt, SystemExit, etc.
        if key == "overflowing_values":
            raise ValueError("Unable to create tensor returning overflowing values of different lengths.")
        raise ValueError(
            "Unable to create tensor, you should probably activate padding "
            "with 'padding=True' to have batched tensors with the same length."
        )

---

# Exact pattern copied from image_processing_fuyu.py lines 99-108

def buggy_safe_convert_tensor(elem):
    def _convert_tensor(e):
        raise KeyboardInterrupt()  # simulates Ctrl+C during processing
    key = "pixel_values"
    try:
        return _convert_tensor(elem)
    except:  # noqa E722          # ← exact copy of the bug
        raise ValueError(
            "Unable to create tensor, you should probably activate padding "
            "with 'padding=True' to have batched tensors with the same length."
        )

try:
    buggy_safe_convert_tensor(None)
except ValueError as e:
    print(f"SWALLOWED: KeyboardInterrupt became -> ValueError: {e}")
except KeyboardInterrupt:
    print("KeyboardInterrupt escaped correctly")

---

SWALLOWED: KeyboardInterrupt became -> ValueError: Unable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length.

---

-     except:  # noqa E722
+     except Exception:

---

except Exception as exc:
    if key == "overflowing_values":
        raise ValueError(
            "Unable to create tensor returning overflowing values of different lengths."
        ) from exc
    raise ValueError(
        "Unable to create tensor, you should probably activate padding "
        "with 'padding=True' to have batched tensors with the same length."
    ) from exc
RAW_BUFFERClick to expand / collapse

System Info

transformers: 5.7.0.dev0 (main, commit 8659ae6245) Python: 3.13.7 Platform: Windows 11 AMD64 PyTorch: 2.11.0+cu126

Who can help?

@yonigozlan @molbap

Information

  • The official example scripts
  • My own modified scripts

Tasks

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

Reproduction

Bare except: is used inside _safe_convert_tensor() in FuyuBatchFeature.convert_to_tensors(). Because bare except: catches all BaseException subclasses — including KeyboardInterrupt and SystemExit — pressing Ctrl+C during Fuyu image processing is silently swallowed and re-raised as a misleading ValueError. Real conversion errors are also hidden since the original exception is discarded.

Affected files (identical bug in both):

  • src/transformers/models/fuyu/image_processing_fuyu.py
  • src/transformers/models/fuyu/image_processing_pil_fuyu.py
# image_processing_fuyu.py, lines 99–108
def _safe_convert_tensor(elem):
    try:
        return _convert_tensor(elem)
    except:  # noqa E722   ← catches KeyboardInterrupt, SystemExit, etc.
        if key == "overflowing_values":
            raise ValueError("Unable to create tensor returning overflowing values of different lengths.")
        raise ValueError(
            "Unable to create tensor, you should probably activate padding "
            "with 'padding=True' to have batched tensors with the same length."
        )

Minimal reproducer — verified on Windows 11, Python 3.13.7, PyTorch 2.11.0+cu126:

# Exact pattern copied from image_processing_fuyu.py lines 99-108

def buggy_safe_convert_tensor(elem):
    def _convert_tensor(e):
        raise KeyboardInterrupt()  # simulates Ctrl+C during processing
    key = "pixel_values"
    try:
        return _convert_tensor(elem)
    except:  # noqa E722          # ← exact copy of the bug
        raise ValueError(
            "Unable to create tensor, you should probably activate padding "
            "with 'padding=True' to have batched tensors with the same length."
        )

try:
    buggy_safe_convert_tensor(None)
except ValueError as e:
    print(f"SWALLOWED: KeyboardInterrupt became -> ValueError: {e}")
except KeyboardInterrupt:
    print("KeyboardInterrupt escaped correctly")

Output:

SWALLOWED: KeyboardInterrupt became -> ValueError: Unable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length.

The # noqa E722 comment on line 102 shows the bare except: was already flagged by linters — but suppressing the warning does not fix the runtime behavior.

Expected behavior

KeyboardInterrupt (Ctrl+C) should propagate normally and stop the process cleanly.

Real conversion errors should surface with their original exception type and traceback — not be silently replaced by a generic padding message regardless of the actual cause.

Suggested fix — one-line change, identical in both files:

-     except:  # noqa E722
+     except Exception:

Optionally with exception chaining to preserve the original traceback:

except Exception as exc:
    if key == "overflowing_values":
        raise ValueError(
            "Unable to create tensor returning overflowing values of different lengths."
        ) from exc
    raise ValueError(
        "Unable to create tensor, you should probably activate padding "
        "with 'padding=True' to have batched tensors with the same length."
    ) from exc

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

KeyboardInterrupt (Ctrl+C) should propagate normally and stop the process cleanly.

Real conversion errors should surface with their original exception type and traceback — not be silently replaced by a generic padding message regardless of the actual cause.

Suggested fix — one-line change, identical in both files:

-     except:  # noqa E722
+     except Exception:

Optionally with exception chaining to preserve the original traceback:

except Exception as exc:
    if key == "overflowing_values":
        raise ValueError(
            "Unable to create tensor returning overflowing values of different lengths."
        ) from exc
    raise ValueError(
        "Unable to create tensor, you should probably activate padding "
        "with 'padding=True' to have batched tensors with the same length."
    ) from exc

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

transformers - ✅(Solved) Fix [Bug] Bare `except:` in FuyuBatchFeature.convert_to_tensors() swallows KeyboardInterrupt and hides real errors [1 pull requests, 3 comments, 2 participants]