Skip to content

Commit 2c85487

Browse files
committed
test(export): pin that the index routes every key to the shard holding it
Tensor equality against a whole-model export never resolves the index, so a weight_map entry naming the wrong shard compares equal and still fails to load. That mapping is the one artifact per-layer export builds differently. Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
1 parent eed0019 commit 2c85487

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

tests/gpu/torch/export/test_layerwise_export.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,25 @@ def test_export_matches_whole_model_export(
232232
assert (export_dir / artifact).is_file(), f"{artifact} missing"
233233

234234

235+
def test_index_resolves_every_key_to_the_shard_holding_it(tmp_path):
236+
"""A loader resolves keys through the index; tensor equality never exercises that.
237+
238+
A weight_map entry naming the wrong shard compares equal to a whole-model export and
239+
still fails in vLLM or transformers.
240+
"""
241+
export_dir = tmp_path / "fused"
242+
mtq.quantize(_build_model(), _layerwise_cfg(export_dir, tmp_path / "ckpt"), _calib)
243+
244+
weight_map = json.loads((export_dir / "model.safetensors.index.json").read_text())["weight_map"]
245+
on_disk = {}
246+
for shard in sorted(set(weight_map.values())):
247+
assert (export_dir / shard).is_file(), f"index names a missing shard {shard}"
248+
on_disk.update(dict.fromkeys(load_file(export_dir / shard), shard))
249+
250+
assert set(weight_map) == set(on_disk), "index and shards disagree on which keys exist"
251+
assert all(on_disk[k] == v for k, v in weight_map.items()), "key routed to the wrong shard"
252+
253+
235254
def test_layerwise_export_replaces_resume_artifacts(tmp_path):
236255
"""The shards are the resume artifact, so per-layer weight copies are not written."""
237256
checkpoint_dir = tmp_path / "ckpt"

0 commit comments

Comments
 (0)