Skip to content

Incompatible with transformers 5.x: find_pruneable_heads_and_indices removed #492

@vittorio-prodomo

Description

@vittorio-prodomo

Description

Surya 0.17.1 fails when installed with transformers>=5.0. Two separate breakages:

1. Donut encoder import error

The table recognition module imports find_pruneable_heads_and_indices from transformers.pytorch_utils, which was removed in transformers 5.x:

from torch import nn
from transformers.activations import ACT2FN
from transformers.pytorch_utils import (
find_pruneable_heads_and_indices,

ImportError: cannot import name 'find_pruneable_heads_and_indices' from 'transformers.pytorch_utils'

2. Layout predictor config attribute error

The layout predictor accesses bbox_size on the model config, which no longer exists under transformers 5.x:

batch_size = settings.LAYOUT_BATCH_SIZE

AttributeError: 'EfficientViTConfig' object has no attribute 'bbox_size'

Steps to reproduce

pip install surya-ocr==0.17.1 transformers==5.3.0
python -c "from surya.table_rec import TableRecPredictor"

Root cause

pyproject.toml specifies transformers >= "4.56.1" with no upper bound, so pip/uv will resolve to 5.x:

pre-commit = "^4.2.0"

Workaround

Pin transformers>=4.56.1,<5 in your project dependencies.

Environment

  • surya-ocr 0.17.1
  • transformers 5.3.0
  • Python 3.12.12
  • torch 2.10.0
  • Linux x86_64

Suggested fix

Either add an upper bound (transformers>=4.56.1,<5) to pyproject.toml, or update the imports/config access to use the transformers 5.x API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions