Bug Report
Model: OpenGVLab/VideoMAEv2-Base
File: modeling_videomaev2.py — VisionTransformer.__init__() line 389
Severity: Blocks AutoModel.from_pretrained() — the standard HuggingFace loading API
Minimal Reproducible Example
from transformers import AutoModel
model = AutoModel.from_pretrained(
"OpenGVLab/VideoMAEv2-Base",
trust_remote_code=True
)
Full Traceback
RuntimeError: Tensor.item() cannot be called on meta tensors
File "modeling_videomaev2.py", line 389, in __init__
dpr = [x.item() for x in torch.linspace(0, drop_path_rate, depth)]
Root Cause
Hugging Face Transformers wraps every model constructor inside torch.device("meta") for memory-efficient loading:
with torch.device("meta"):
model = cls(config) # ← VisionTransformer.__init__() runs here
A meta tensor has shape and dtype but no actual data values. Line 389 calls .item() to extract a scalar — which is impossible on a meta tensor.
| Call |
Meta context? |
Result |
VideoMAEv2(config) |
❌ No |
✅ Works |
AutoModel.from_pretrained(...) |
✅ Yes |
❌ Crashes |
Proposed Fix
- dpr = [x.item() for x in torch.linspace(0, drop_path_rate, depth)]
+ # Meta-safe: no PyTorch tensor needed here
+ if depth > 1:
+ dpr = [drop_path_rate * i / (depth - 1) for i in range(depth)]
+ else:
+ dpr = [0.0] * depth
Produces numerically identical values. No tensor operations during construction.
Environment
| Item |
Version |
transformers |
latest |
torch |
2.x |
| OS |
Any |
Happy to open a PR with this fix if maintainers confirm the approach.
Bug Report
Model:
OpenGVLab/VideoMAEv2-BaseFile:
modeling_videomaev2.py—VisionTransformer.__init__()line 389Severity: Blocks
AutoModel.from_pretrained()— the standard HuggingFace loading APIMinimal Reproducible Example
Full Traceback
Root Cause
Hugging Face Transformers wraps every model constructor inside
torch.device("meta")for memory-efficient loading:A meta tensor has shape and dtype but no actual data values. Line 389 calls
.item()to extract a scalar — which is impossible on a meta tensor.VideoMAEv2(config)AutoModel.from_pretrained(...)Proposed Fix
Produces numerically identical values. No tensor operations during construction.
Environment
transformerstorchHappy to open a PR with this fix if maintainers confirm the approach.