Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformers 4.26.0 onwards not working #65

Closed
igrodfer opened this issue Apr 25, 2023 · 1 comment
Closed

Transformers 4.26.0 onwards not working #65

igrodfer opened this issue Apr 25, 2023 · 1 comment

Comments

@igrodfer
Copy link

Whenever I try to run a query on a document with transformers>=4.26 an exception is raised:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[1], line 5
      3 doc = document.load_document("https://templates.invoicehome.com/invoice-template-us-neat-750px.png")
      4 for q in ["What is the invoice number?", "What is the invoice total?"]:
----> 5     print(q, p(question=q, **doc.context))

File [~/Documents/repos/doqry/venv/lib/python3.10/site-packages/docquery/ext/pipeline_document_question_answering.py:232](https://file+.vscode-resource.vscode-cdn.net/home/user/Documents/repos/doqry/~/Documents/repos/doqry/venv/lib/python3.10/site-packages/docquery/ext/pipeline_document_question_answering.py:232), in DocumentQuestionAnsweringPipeline.__call__(self, image, question, **kwargs)
    229 else:
    230     normalized_images = [(image, None)]
--> 232 return super().__call__({"question": question, "pages": normalized_images}, **kwargs)

File [~/Documents/repos/doqry/venv/lib/python3.10/site-packages/transformers/pipelines/base.py:1076](https://file+.vscode-resource.vscode-cdn.net/home/user/Documents/repos/doqry/~/Documents/repos/doqry/venv/lib/python
[requirements.txt](https://github.com/impira/docquery/files/11320270/requirements.txt)
3.10/site-packages/transformers/pipelines/base.py:1076), in Pipeline.__call__(self, inputs, num_workers, batch_size, *args, **kwargs)
   1074     return self.iterate(inputs, preprocess_params, forward_params, postprocess_params)
   1075 elif self.framework == "pt" and isinstance(self, ChunkPipeline):
-> 1076     return next(
   1077         iter(
   1078             self.get_iterator(
   1079                 [inputs], num_workers, batch_size, preprocess_params, forward_params, postprocess_params
   1080             )
   1081         )
   1082     )
   1083 else:
   1084     return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)

File [~/Documents/repos/doqry/venv/lib/python3.10/site-packages/transformers/pipelines/pt_utils.py:124](https://file+.vscode-resource.vscode-cdn.net/home/user/Documents/repos/doqry/~/Documents/repos/doqry/venv/lib/python3.10/site-packages/transformers/pipelines/pt_utils.py:124), in PipelineIterator.__next__(self)
    121     return self.loader_batch_item()
    123 # We're out of items within a batch
--> 124 item = next(self.iterator)
    125 processed = self.infer(item, **self.params)
    126 # We now have a batch of "inferred things".

File [~/Documents/repos/doqry/venv/lib/python3.10/site-packages/transformers/pipelines/pt_utils.py:291](https://file+.vscode-resource.vscode-cdn.net/home/user/Documents/repos/doqry/~/Documents/repos/doqry/venv/lib/python3.10/site-packages/transformers/pipelines/pt_utils.py:291), in PipelinePackIterator.__next__(self)
    289     else:
    290         item = processed
--> 291         is_last = item.pop("is_last")
    292         accumulator.append(item)
    293 return accumulator

File [~/Documents/repos/doqry/venv/lib/python3.10/site-packages/transformers/utils/generic.py:281](https://file+.vscode-resource.vscode-cdn.net/home/user/Documents/repos/doqry/~/Documents/repos/doqry/venv/lib/python3.10/site-packages/transformers/utils/generic.py:281), in ModelOutput.pop(self, *args, **kwargs)
    280 def pop(self, *args, **kwargs):

requirements.txt
requirements.txt

--> 281     raise Exception(f"You cannot use ``pop`` on a {self.__class__.__name__} instance.")

Exception: You cannot use ``pop`` on a ModelOutput instance..
@PeterHuGC
Copy link

Hi,

In the setup.py file, this shows us the dependencies for the packages.

install_requires = [
    "torch >= 1.0",
    "pdf2image",
    "pdfplumber",
    "Pillow",
    "pydantic",
    "pytesseract",  # TODO: Test what happens if the host machine does not have tesseract installed
    "requests",
    "easyocr",
    "transformers >= 4.23",
]

Just run:

pip install transformers==4.23

The problem comes from the version of the transfomers. So installing the minimal version should fix this issue. The setup.py dependencies should be updated in the repo to reflect this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants