Use get_input_embeddings() Instead of Accessing .embed_tokens Directly
#8
by
Zhenzhao
- opened
No description provided.
Problem
Code was previously accessing self.base.model.embed_tokens(input_ids)
directly, which works on transformers < 4.51.0
, but raises:
AttributeError: 'Qwen2VLModel' object has no attribute 'embed_tokens'
in transformers >= 4.51.0
due to internal API refactoring.
✅ Solution
Switched to the standardized HuggingFace API:
inputs_embeds = self.base.get_input_embeddings()(input_ids)
This makes the code compatible across all transformers >= 4.0
, and avoids reliance on internal attributes that may change.
🧪 Tested
- Confirmed working on both
transformers==4.50.0
and4.52.3
. - No behavior changes, but now forward-compatible.