transformers - 💡(How to fix) Fix Your lazy loading and torchvision dependency in Wav2Vec2/Hubert is breaking PyInstaller builds. Stop forcing torchvision for audio tasks [1 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#44963Fetched 2026-04-08 01:21:24
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Timeline (top)
commented ×1labeled ×1
RAW_BUFFERClick to expand / collapse

Feature request

CẢNH BÁO "RÁC" CÔNG NGHỆ: KHI HUGGINGFACE TRANSFORMERS TỰ HỦY TRÊN PYINSTALLER Gửi anh em giới mộ điệu Python và AI, đặc biệt là những ai đang dùng WhisperX hoặc VieNeu-TTS để làm tool kiếm tiền Như JS Vinhka . Nếu anh em đang hì hục đóng gói .exe mà bị cái lỗi hãm tài:

⚠️ [WhisperX] Align lỗi: Could not import module 'Wav2Vec2ForCTC'. Are this object's requirements defined correctly?

Thì xin chúc mừng, anh em đã chính thức va phải sự "vô học" trong thiết kế của bộ thư viện transformers (bản 4.48 trở đi).

🛑 CÁI "NGU" CỦA HUGGINGFACE LÀ GÌ? Bọn Dev HuggingFace có một sở thích quái đản là "Râu ông nọ cắm cằm bà kia".

Lazy Loading bẩn: Tụi nó giấu sạch các Class quan trọng (Wav2Vec2ForCTC, HubertModel) vào trong chuỗi text để tải động. PyInstaller/Nuitka quét qua đéo thấy import rành rành là nó vứt mẹ file đi, dẫn đến lỗi "thiếu phụ tùng" khi chạy .exe.

Chuỗi Import rác: Muốn dùng model ÂM THANH (Wav2Vec2), nhưng thằng transformers lại âm thầm gọi cả họ nhà HÌNH ẢNH (torchvision) vào chỉ để lấy một cái biến InterpolationMode.

Phản bội Torch: Trong môi trường đóng gói, torchvision thường xuyên bị lỗi không nhận dạng được toán tử gốc (RuntimeError: operator torchvision::nms does not exist). Thằng transformers thấy torchvision lỗi là nó lăn đùng ra chết chùm, xong lại phun ra cái câu đạo lý: "Máy mày có cài đủ requirements không?" trong khi lỗi là do chính cái sự cẩu thả của nó!

🛠️ CÁCH VÁ "LỐI SỐNG SAI LẦM" NÀY: Để cứu vãn 30 phút cuộc đời mỗi lần build, anh em làm theo đúng 3 bước "diệt chủng" này:

Bước 1: Tuyệt tình với torchvision. Gỡ ngay thằng báo thủ này ra: pip uninstall torchvision -y. Nếu tool làm âm thanh thì đừng để nó dính líu đến hình ảnh.

Bước 2: Hạ cấp về thời đồ đá nhưng ổn định. Cài bản transformers==4.40.0. Đây là bản cuối cùng còn giữ được sự tự trọng, đéo lôi kéo torchvision lung tung.

Bước 3: Dùng "Bùa chú" Mock. Trong file chạy đầu tiên của App, dán ngay cái đoạn này vào để lừa thằng AI là torchvision đã có (nhưng thực chất là đồ giả):

Python import sys from unittest.mock import MagicMock mock_tv = MagicMock() mock_tv.transforms.InterpolationMode.BILINEAR = 0 sys.modules["torchvision"] = mock_tv sys.modules["torchvision.transforms"] = mock_tv.transforms Lời nhắn nhủ: Đừng để sự lười biếng của mấy ông Dev Pháp, Mỹ làm tốn nước cam và thuốc lá của anh em mình. Chúc anh em build phát ăn ngay, tiền về đầy túi!

Motivation

Lazy Loading bẩn: Tụi nó giấu sạch các Class quan trọng (Wav2Vec2ForCTC, HubertModel) vào trong chuỗi text để tải động. PyInstaller/Nuitka quét qua đéo thấy import rành rành là nó vứt mẹ file đi, dẫn đến lỗi "thiếu phụ tùng" khi chạy .exe.

Your contribution

Lazy Loading bẩn: Tụi nó giấu sạch các Class quan trọng (Wav2Vec2ForCTC, HubertModel) vào trong chuỗi text để tải động. PyInstaller/Nuitka quét qua đéo thấy import rành rành là nó vứt mẹ file đi, dẫn đến lỗi "thiếu phụ tùng" khi chạy .exe.

extent analysis

Fix Plan

To resolve the issue with HuggingFace Transformers and PyInstaller, follow these steps:

  • Uninstall torchvision: Run pip uninstall torchvision -y to remove the problematic package.
  • Downgrade transformers: Install version 4.40.0 using pip install transformers==4.40.0.
  • Use Mock to bypass torchvision: Add the following code to your main application file:
import sys
from unittest.mock import MagicMock
mock_tv = MagicMock()
mock_tv.transforms.InterpolationMode.BILINEAR = 0
sys.modules["torchvision"] = mock_tv
sys.modules["torchvision.transforms"] = mock_tv.transforms

This code creates a mock object for torchvision, allowing your application to run without actually loading the package.

Verification

After applying these fixes, re-run your PyInstaller command to package your application. The resulting executable should now run without errors related to missing modules or torchvision.

Extra Tips

  • Be cautious when using lazy loading in your application, as it can lead to issues with packaging tools like PyInstaller.
  • Consider using a virtual environment to manage dependencies and avoid conflicts between packages.
  • If you encounter further issues, try checking the HuggingFace Transformers documentation or seeking help from the community.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING