[Bug] _load_bin_or_path_file hides the real torch.load error behind UnboundLocalError
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 75/100
Direzione di ricerca
Il bug si trova in tensorrt_llm/_torch/models/checkpoints/hf/weight_loader.py nel metodo _load_bin_or_path_file. Leggere la funzione per comprendere il flusso try/except/finally. La correzione consiste nel rimuovere il blocco finally e la parte di return, e restituire part_weights dopo il blocco except. Testare creando una directory di checkpoint contenente solo file .bin e assicurandosi che venga segnalato l'errore originale di torch.load, non un UnboundLocalError.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
System Info
Code inspection plus a reproduction of the control flow; observed on main (134fa245).
Who can help?
Code owners for tensorrt_llm/_torch/models (@NVIDIA/trt-llm-models-devs per CODEOWNERS).
Information
- The official example scripts
- My own modified scripts
Reproduction
HfWeightLoader._load_bin_or_path_file (tensorrt_llm/_torch/models/checkpoints/hf/weight_loader.py) returns from a finally block:
@staticmethod
def _load_bin_or_path_file(file):
try:
part_weights = torch.load(file, weights_only=True, map_location='cpu', mmap=True)
except Exception:
logger.warning(f"Failed to load {file} with mmap=True, fallback to mmap=False")
part_weights = torch.load(file, weights_only=True, map_location='cpu', mmap=False)
finally:
return part_weights
When the mmap=False retry also raises, part_weights was never assigned, so the return in finally raises UnboundLocalError and replaces the real error. This path is taken whenever a checkpoint has no *.safetensors and the loader falls back to *.bin/*.pth.
For example, a .bin-only directory that contains HF Trainer's training_args.bin fails torch.load(..., weights_only=True) with UnpicklingError: Weights only load failed ... Unsupported global: ... TrainingArguments, but the user sees:
[ERROR] Error executing _load_bin_or_path_file with args ('.../training_args.bin',): cannot access local variable 'part_weights' where it is not associated with a value
The load fails either way; the problem is that the error reported points at the loader rather than at the file and the real cause. Python 3.14 also emits SyntaxWarning: 'return' in a 'finally' block for this function (PEP 765).
Expected behavior
The original torch.load exception propagates.
Actual behavior
UnboundLocalError: cannot access local variable 'part_weights' ...
Additional notes
The fix is to drop the finally: and return after the try/except, which keeps the successful paths unchanged. This was also pointed out by an automated review on #7171. I have a PR ready and will link it here.
Written with AI assistance and reviewed line by line.
- Lingua principale
- Python
- Stelle
- 14.8k
- Fork
- 2.8k
- Merge medio
- 3g 17h
- PR unite (30g)
- 471
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di NVIDIA/TensorRT-LLM
-
[Performance]: Beam search re-materializes Result.output_token_ids from pybind once per beamForse già presa Una pull request collegata a questa issue è aperta o già unita. ApertaGeneral perf
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
NVIDIA/TensorRT-LLM#20236 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] Static disaggregated worker addresses cannot round trip bracketed IPv6Forse già presa @bojiang-li l’ha presa 5 giorni fa. ApertaDisaggregated serving
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
NVIDIA/TensorRT-LLM#20126 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Kimi Linear / Kimi K3 fail to load from the release container: No module named 'fla'Forse già presa @lorenzozanee l’ha presa 6 giorni fa. ApertaCustomized kernels
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
NVIDIA/TensorRT-LLM#19893 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: guided response_format is silently ignored without guided_decoding_backendForse già presa @lorenzozanee l’ha presa 21 giorni fa. Apertabug Inference runtime
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
NVIDIA/TensorRT-LLM#19635 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: AutoDeploy logger treats verbose and internal_error as infoForse già presa @RahulDeoghare l’ha presa 25 giorni fa. ApertaAutoDeploy bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
NVIDIA/TensorRT-LLM#19491 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di NVIDIA/TensorRT-LLM
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
omegaup/omegaup#10353 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
bot-triaged module: LrScheduler module: optimizer triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
documentation glm5 llm-model
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vllm-project/vllm-ascend#19062 ·
I maintainer di solito rispondono entro 1 giorno
-
Author Page: shuai-zhao-llmApertaauthor-page correction
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
acl-org/acl-anthology#10496 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno