Startup fails under current transformers: the Janus vision tower calls .item() on a meta tensor while loading

#1
by nootxlm - opened

This Space currently fails at startup, during AutoModelForCausalLM.from_pretrained("deepseek-ai/Janus-Pro-7B", trust_remote_code=True). The traceback ends with:

File ".../janus/models/siglip_vit.py", line 391, in __init__
    x.item() for x in torch.linspace(0, drop_path_rate, depth)
RuntimeError: Tensor.item() cannot be called on meta tensors

reached through janus/models/clip_encoder.py (build_vision_tower → create_siglip_vit) from modeling_vlm.py's __init__, itself called by transformers' from_pretrained, which constructs the model on the meta device first.

The mechanism is a version pairing. Current transformers builds the model under meta tensors before loading weights, and the Janus vision tower's constructor reads a concrete value (.item()) out of a tensor during construction, which a meta tensor cannot provide. requirements.txt here pins neither transformers nor the Janus dependency (git+https://github.com/deepseek-ai/Janus, unpinned), so the platform pairs today's transformers with that code and the load dies before any weights move.

Two fixes, either sufficient:

  • Pin transformers in requirements.txt to a release this demo is known to start under, instead of taking whatever the platform resolves today, or
  • Carry a small patch on the Janus side: compute the drop-path rates as plain Python floats instead of reading them out of a tensor — the values of torch.linspace(0, drop_path_rate, depth) are drop_path_rate * i / (depth - 1) elementwise (and [0.] when depth == 1), so a list comprehension over the range produces the identical list without touching a tensor during construction.

To confirm: restart the Space — startup should get past model construction to the weight-loading step.

Sign up or log in to comment