[Bug]: LoRA loading fails with "could not determine the shape of object type 'torch.storage.UntypedStorage'" when loading HF-style adapter_model.safetensors (PyTorch backend)
System Info
- CPU architecture: x86_64
- GPU: NVIDIA A100 40GB
- TensorRT-LLM: v1.1.0 (pip install)
- Python: 3.12
- PyTorch: 2.9.0+cu130
- safetensors: 0.7.0
- CUDA / Driver: Driver Version: 580.126.09 CUDA Version: 13.0
Who can help?
No response
Information
- [ ] The official example scripts
- [x] My own modified scripts
Tasks
- [ ] An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...) - [x] My own task or dataset (give details below)
Reproduction
Steps to reproduce:
- Create a HuggingFace-style LoRA adapter with PEFT: directory containing adapter_config.json and adapter_model.safetensors (see "How the LoRA was produced" below).
- Create a YAML with lora_config (lora_dir, max_lora_rank, lora_target_modules, trtllm_modules_to_hf_modules).
- Run trtllm-bench with PyTorch backend and --extra_llm_api_options pointing to that YAML:
trtllm-bench -m Meta-Llama-3.1-8B-Instruct --model_path /path/to/base throughput
--backend pytorch --extra_llm_api_options config_lora.yaml --dataset dataset.jsonl
- During model init, LoRA is loaded via tensorrt_llm.models.convert_utils.load_state_dict(adapter_model.safetensors) (from lora_manager.HfLoraLoader). Loading fails.
How the LoRA was produced (PEFT):
from peft import get_peft_model, LoraConfig, PeftType
model = get_peft_model( model, peft_config=LoraConfig( inference_mode=False, r=lora_r, lora_alpha=lora_alpha, lora_dropout=0, bias='none', target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"], peft_type=PeftType.LORA, ), ) model.save_pretrained(ckpt_dir)
So the failing adapter_model.safetensors is the default format from PEFT save_pretrained (safetensors).
Error message (full traceback):
ValueError: could not determine the shape of object type 'torch.storage.UntypedStorage'
File ".../tensorrt_llm/_torch/pyexecutor/model_loader.py", line 209, in load model = AutoModelForCausalLM.from_config(config_copy) ... File ".../tensorrt_llm/lora_manager.py", line 279, in init lora_weight = load_state_dict(model_path) File ".../tensorrt_llm/models/convert_utils.py", line 184, in load_state_dict tensor = f.get_tensor(name) ValueError: could not determine the shape of object type 'torch.storage.UntypedStorage'
Then "Fallback to regular model init" is logged and the run continues without LoRA (base model only). The failure occurs when reading the LoRA safetensors via safetensors.safe_open + get_tensor() or safetensors.torch.load_file(). The same file loads in PEFT/transformers.
### Expected behavior
LoRA weights load successfully from the HF-style adapter saved as **safetensors** (adapter_model.safetensors from PEFT save_pretrained), not the .npy format. trtllm-bench runs with the base model plus LoRA adapter applied, with no "Fallback to regular model init" due to this error.
### actual behavior
Loading adapter_model.safetensors raises ValueError: could not determine the shape of object type 'torch.storage.UntypedStorage' in convert_utils.load_state_dict (safetensors get_tensor path). The process falls back to regular model init without LoRA; the benchmark runs with the base model only.
### additional notes
The LoRA adapter was produced by PEFT get_peft_model + save_pretrained (see Reproduction); the same adapter_model.safetensors loads fine in PEFT/transformers. A workaround that avoids the failing path: load the safetensors via safetensors.deserialize(file_bytes) and build tensors from raw buffers (e.g. via numpy and torch.from_numpy) instead of safe_open + get_tensor or load_file(), which suggests the issue is in the get_tensor / PyTorch view path for this file format. Possible directions: (1) Make TensorRT-LLM LoRA safetensors loading more robust (e.g. fallback to deserialize+numpy when get_tensor fails), or (2) coordinate with safetensors/PyTorch if the root cause is there. Re-saving the adapter with safetensors.torch.save_file() after loading with PEFT is a user-side workaround.
### Before submitting a new issue...
- [x] Make sure you already searched for relevant issues, and checked the [documentation](https://nvidia.github.io/TensorRT-LLM/) and [examples](https://github.com/NVIDIA/TensorRT-LLM/tree/main/examples) for answers to frequently asked questions.
@langzhao-netizen can you try this fix? https://github.com/NVIDIA/TensorRT-LLM/pull/11339
I’m closing this issue since the #11339 has been merged. If the problem persists even after applying the patch, please feel free to open a new issue. Thank you!