ImportError and TypeError Issues in Nougat OCR with BARTDecoder and cached_property

I’m facing issues while running an OCR process using Nougat with two different errors for two different users. The errors are related to importing cached_property and an unexpected keyword argument cache_position. Below are the full error messages for both cases:

Error 1: ImportError for cached_property

ImportError: cannot import name 'cached_property' from 'nougat.utils' (/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/utils/__init__.py)
OCRing with base model failed on /lfs/skampere1/0/emilyhyf/massive-evaporation-4-math/data/debug_pdfs/dummy_folder1/The_IMO_Compendium.pdf... trying small model
Traceback (most recent call last):
  File "/lfs/skampere1/0/emilyhyf/miniconda/bin/nougat", line 5, in <module>
    from predict import main
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/predict.py", line 18, in <module>
    from nougat import NougatModel
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/__init__.py", line 1, in <module>
    from nougat.app import Nougat
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/app.py", line 5, in <module>
    from nougat.asgi import serve
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/asgi.py", line 6, in <module>
    from nougat.context.request import Request
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/context/__init__.py", line 1, in <module>
    from nougat.context.request import Request
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/context/request.py", line 8, in <module>
    from nougat.utils import cached_property, File
ImportError: cannot import name 'cached_property' from 'nougat.utils' (/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/utils/__init__.py)
OCRing with small model failed on /lfs/skampere1/0/emilyhyf/massive-evaporation-4-math/data/debug_pdfs/dummy_folder1/The_IMO_Compendium.pdf
The following files failed OCRing and need manual review:
/lfs/skampere1/0/emilyhyf/massive-evaporation-4-math/data/debug_pdfs/putnam_and_beyond.pdf
/lfs/skampere1/0/emilyhyf/massive-evaporation-4-math/data/debug_pdfs/dummy_folder1/The_IMO_Compendium.pdf
Time taken: 8.497612476348877 seconds, 0.1416268746058146 minutes, 0.00236044791009691 hours

Error 2: TypeError for cache_position in BARTDecoder

TypeError: BARTDecoder.prepare_inputs_for_inference() got an unexpected keyword argument 'cache_position'
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
OCRing with base model failed on /lfs/skampere1/0/naveenkc/contest_scraper/test_nougat/731991.pdf... trying small model
/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/torch/functional.py:512: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3587.)
  return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
  0%|                                                 | 0/288 [00:24<?, ?it/s]
Traceback (most recent call last):
  File "/lfs/skampere1/0/naveenkc/miniconda/bin/nougat", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/predict.py", line 167, in main
    model_output = model.inference(
                   ^^^^^^^^^^^^^^^^
  File "/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/nougat/model.py", line 592, in inference
    decoder_output = self.decoder.model.generate(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/transformers/generation/utils.py", line 1758, in generate
    result = self._sample(
             ^^^^^^^^^^^^^
  File "/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/transformers/generation/utils.py", line 2394, in _sample
    model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BARTDecoder.prepare_inputs_for_inference() got an unexpected keyword argument 'cache_position'
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
OCRing with small model failed on /lfs/skampere1/0/naveenkc/contest_scraper/test_nougat/731991.pdf
The following files failed OCRing and need manual review:
/lfs/skampere1/0/naveenkc/contest_scraper/test_nougat/731991.pdf
Time taken: 65.70022702217102 seconds, 1.0950037837028503 minutes, 0.018250063061714172 hours

Environment:

  • Python 3.12
  • Nougat
  • Torch
  • Transformers

Questions:

  1. ImportError: How can I resolve the ImportError: cannot import name 'cached_property' from 'nougat.utils'? What could be causing this issue, and is there an alternative approach to import cached_property?

  2. TypeError: How can I address the TypeError: BARTDecoder.prepare_inputs_for_inference() got an unexpected keyword argument 'cache_position'? Is this due to a version mismatch between transformers and torch? How can I ensure compatibility?

Any guidance on these issues would be greatly appreciated! Thank you in advance!

I’m facing issues while running an OCR process using Nougat with two different errors for two different users. The errors are related to importing cached_property and an unexpected keyword argument cache_position. Below are the full error messages for both cases:

Error 1: ImportError for cached_property

ImportError: cannot import name 'cached_property' from 'nougat.utils' (/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/utils/__init__.py)
OCRing with base model failed on /lfs/skampere1/0/emilyhyf/massive-evaporation-4-math/data/debug_pdfs/dummy_folder1/The_IMO_Compendium.pdf... trying small model
Traceback (most recent call last):
  File "/lfs/skampere1/0/emilyhyf/miniconda/bin/nougat", line 5, in <module>
    from predict import main
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/predict.py", line 18, in <module>
    from nougat import NougatModel
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/__init__.py", line 1, in <module>
    from nougat.app import Nougat
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/app.py", line 5, in <module>
    from nougat.asgi import serve
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/asgi.py", line 6, in <module>
    from nougat.context.request import Request
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/context/__init__.py", line 1, in <module>
    from nougat.context.request import Request
  File "/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/context/request.py", line 8, in <module>
    from nougat.utils import cached_property, File
ImportError: cannot import name 'cached_property' from 'nougat.utils' (/lfs/skampere1/0/emilyhyf/miniconda/lib/python3.12/site-packages/nougat/utils/__init__.py)
OCRing with small model failed on /lfs/skampere1/0/emilyhyf/massive-evaporation-4-math/data/debug_pdfs/dummy_folder1/The_IMO_Compendium.pdf
The following files failed OCRing and need manual review:
/lfs/skampere1/0/emilyhyf/massive-evaporation-4-math/data/debug_pdfs/putnam_and_beyond.pdf
/lfs/skampere1/0/emilyhyf/massive-evaporation-4-math/data/debug_pdfs/dummy_folder1/The_IMO_Compendium.pdf
Time taken: 8.497612476348877 seconds, 0.1416268746058146 minutes, 0.00236044791009691 hours

Error 2: TypeError for cache_position in BARTDecoder

TypeError: BARTDecoder.prepare_inputs_for_inference() got an unexpected keyword argument 'cache_position'
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
OCRing with base model failed on /lfs/skampere1/0/naveenkc/contest_scraper/test_nougat/731991.pdf... trying small model
/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/torch/functional.py:512: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3587.)
  return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
  0%|                                                 | 0/288 [00:24<?, ?it/s]
Traceback (most recent call last):
  File "/lfs/skampere1/0/naveenkc/miniconda/bin/nougat", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/predict.py", line 167, in main
    model_output = model.inference(
                   ^^^^^^^^^^^^^^^^
  File "/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/nougat/model.py", line 592, in inference
    decoder_output = self.decoder.model.generate(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/transformers/generation/utils.py", line 1758, in generate
    result = self._sample(
             ^^^^^^^^^^^^^
  File "/lfs/skampere1/0/naveenkc/miniconda/lib/python3.12/site-packages/transformers/generation/utils.py", line 2394, in _sample
    model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BARTDecoder.prepare_inputs_for_inference() got an unexpected keyword argument 'cache_position'
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
-> Cannot close object, library is destroyed. This may cause a memory leak!
OCRing with small model failed on /lfs/skampere1/0/naveenkc/contest_scraper/test_nougat/731991.pdf
The following files failed OCRing and need manual review:
/lfs/skampere1/0/naveenkc/contest_scraper/test_nougat/731991.pdf
Time taken: 65.70022702217102 seconds, 1.0950037837028503 minutes, 0.018250063061714172 hours

Environment:

  • Python 3.12
  • Nougat
  • Torch
  • Transformers

Questions:

  1. ImportError: How can I resolve the ImportError: cannot import name 'cached_property' from 'nougat.utils'? What could be causing this issue, and is there an alternative approach to import cached_property?

  2. TypeError: How can I address the TypeError: BARTDecoder.prepare_inputs_for_inference() got an unexpected keyword argument 'cache_position'? Is this due to a version mismatch between transformers and torch? How can I ensure compatibility?

Any guidance on these issues would be greatly appreciated! Thank you in advance!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật