[Bug Report] `boot_transformers(hf_model=...)` without `device=` can record the wrong `cfg.device`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 56/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- backend, machine-learning
Hướng nghiên cứu
Start in transformer_lens/model_bridge/sources/transformers/source.py at the device selection and pre-loaded model fallback noted in the report. Compare that flow with build_bridge_from_module, which takes cfg.device from the model. Reproduce with a pre-loaded model on a different device and check bridge calls, run_with_hooks, and generate; done when cfg.device matches the weights' device and those calls no longer fail.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
Without device=, TransformerBridge.boot_transformers(..., hf_model=model) keeps cfg.device at get_device() unless the model has an hf_device_map, but never moves the model. When the weights are on another device, calls that move their inputs to cfg.device fail, including bridge("text"), run_with_hooks on text and generate. run_with_cache with a single-string input works, because it moves the tokenized inputs to the weights' device.
Code example
from transformers import AutoModelForCausalLM
from transformer_lens.model_bridge import TransformerBridge
hf_model = AutoModelForCausalLM.from_pretrained("gpt2").to("mps")
bridge = TransformerBridge.boot_transformers("gpt2", hf_model=hf_model)
print(bridge.cfg.device) # cpu
bridge("Hello world")
# RuntimeError: Placeholder storage has not been allocated on MPS device!
Loading with device_map="auto" instead of .to("mps") fails the same way, because a single-device load sets no hf_device_map. A model left on the CPU, where from_pretrained puts it by default, fails with TRANSFORMERLENS_ALLOW_MPS=1 (cfg.device is mps). On a CUDA machine, get_device() returns cuda, so the same CPU model gets cfg.device cuda.
System Info
- Source checkout installed with
uv,devat34c5d77f. - macOS 27.2, Apple M5; Python 3.12.14; PyTorch 2.11.0; transformers 5.13.0; CPU and MPS.
Additional context
The get_device() default applies whenever no device map resolves (transformer_lens/model_bridge/sources/transformers/source.py:261-264), which is always the case with hf_model=, since device_map, n_devices and max_memory are rejected alongside it. The fallback for a pre-loaded model without an hf_device_map, which reads its first parameter (:414-419), only runs while cfg.device is None, which it never is here. build_bridge_from_module already takes cfg.device from the model.
Proposed fix: call get_device() only when boot_transformers loads the model itself, so that cfg.device stays None for hf_model without device= until it is read from the model after the load. An explicit device= keeps its current behavior: it is recorded but not applied to a pre-loaded model.
The MODEL_PATH cells in demos/LLaMA.ipynb and demos/LLaMA_GPU_Quantized.ipynb load the model on the CPU and pass device=device, so on CUDA or MPS their generate call gets inputs on the accelerator and weights on the CPU. Should boot_transformers move a pre-loaded model to an explicit device=?
Checklist
- I have checked that there is no similar issue in the repo.
- Ngôn ngữ chính
- Python
- Star
- 3.9k
- Fork
- 708
- Merge trung bình
- 2 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 88
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TransformerLensOrg/TransformerLens
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
TransformerLensOrg/TransformerLens#1939 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Proposal] Whisper adapter for TransformerBridgeCó thể đã có người làm @dipo101 đã nhận 3 ngày trước. Đang mởcomplexity-moderate new-architecture TransformerBridge
TransformerLensOrg/TransformerLens#1938 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug Report] Granite MoE Hybrid grouped experts produce incorrect or unstable outputs on MPSCó thể đã có người làm @janmenjayap đã nhận 13 ngày trước. Đang mởbug complexity-simple TransformerBridge
TransformerLensOrg/TransformerLens#1886 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Community Feedback Requested Research Reproduction seen_by_maintainers TransformerBridge
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
TransformerLensOrg/TransformerLens#1884 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Proposal] Contextual Decomposition: Nonlinear Source Attribution and Dataset-Wide Ranking on GPT-2Đang mởCommunity Feedback Requested Research Reproduction seen_by_maintainers
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
TransformerLensOrg/TransformerLens#1883 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TransformerLensOrg/TransformerLens
Issue tương tự
-
README.zh-CN/ja/es still hard-code 501 test counts after README.md went count-freeCó thể đã có người làm @Aaqibhafeezkhan đã nhận hôm nay. Đang mởbeginner documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
BistaDinesh03/critique#164 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug IO
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
MrNeRF/LichtFeld-Studio#3824 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug confirmed issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
open-webui/open-webui#33200 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Lychee link check failedĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
-
The changelog workflow excludes otelbot but not dependabot, so every Dependabot pull request fails the changelog checkCó thể đã có người làm @ocelotl đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
open-telemetry/opentelemetry-python#5825 ·
Maintainer thường phản hồi trong vòng 2 ngày