Repository navigation
Conversation
…int directory The weight_map of a sharded checkpoint index is read as shard file names inside the checkpoint directory, but the loader joined the value to the directory without checking where it lands. An index that maps a tensor to ../outside/file.safetensors, or to an absolute path, made the loader read a file outside the package; the exported draft then carried those weights, and a package holding no weight file at all still exported successfully. Refuse such an index instead of following it: an absolute value is rejected outright, and a relative one must resolve inside the checkpoint directory. Every sharded load goes through load_checkpoint_tensors, so the check lives in _read_weight_map_file next to the existing weight_map validation. Test added in test_checkpoint_loading.py covers both escape forms, the absolute form, and the in-package control that must keep loading. Signed-off-by: li-lizhe <147392333@qq.com>
li-lizhe
requested review from
FlamingoPg,
FrankLeeeee,
shuaills and
sleepcoo
as code owners
October 30, 2026 17:24
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
read_weight_map/load_checkpoint_tensorsread theweight_mapof a sharded checkpoint index asshard file names, then join them to the checkpoint directory:
Nothing checks where that join lands. An index that maps a tensor to
../outside/weights.safetensors, or to an absolute path, makes the loader read a weight file outsidethe directory the caller pointed at.
Eagle3DraftModel.load_embeddingandexport_to_hfuse exactlythis path for
--embedding-source, so the tensor ends up inembed_tokens.weightof the exporteddraft: a package that contains only
config.jsonandmodel.safetensors.index.jsonstill exports,carrying weights that came from somewhere else.
Reported in #1041 with a reproduction I confirmed independently on CPU: with the index pointing at
../private/licensed.safetensors,load_checkpoint_tensors(pkg, keys=["model.embed_tokens.weight"])returns the outside tensor (
7.3125marker), while the in-package control returns its own shard'svalue.
Modifications
_read_weight_map_filenow rejects aweight_mapvalue that does not stay inside the checkpointdirectory, next to the existing
weight_mapvalidation:os.path.realpath+os.path.commonpath),which also covers
..hidden in the middle of a value and symlinks that point out.The check sits in the one place every sharded load passes through, so
load_checkpoint_tensors,read_weight_mapandlist_checkpoint_keysall get it. Single-file checkpoints are unaffected: theirpath comes from the fixed layout table, not from the index.
The error names the index file, the offending value, and the directory, so a legitimate package is not
left guessing.
Related Issues
Fixes #1041
Accuracy Test
No model-side or kernel code is touched. The new test covers the three escape forms (parent-relative,
..in the middle, absolute) plus the in-package control that must keep loading:ValueError not raisedfor each escapeform), 8 passed, 16 subtests passed
Environment for that run: Windows 11, Python 3.11,
torch 2.8.0+cpu,safetensors 0.8.0.tests/test_utils/test_mtp.py(the other caller ofread_weight_map) could not be collected herebecause this machine has no
transformers; it only exercises in-package shard names, which thein-package control case reproduces, and it is left to CI.
Checklist
black/isortclean on both files (repo pre-commit config)valid input