@@ -1008,6 +1008,23 @@ def dribbling_read(fd: int, length: int) -> bytes:
10081008 assert meta .tensors ["a0" ].shape == [4 , 8 ]
10091009
10101010
1011+ def test_from_file_empty_metadata (tmp_dir , framework ) -> None :
1012+ # Regression test: a safetensors file whose header carries an empty
1013+ # __metadata__: {} object must parse without raising. Previously,
1014+ # __metadata__ was stripped only when truthy, so {} survived into the
1015+ # tensor sort and raised KeyError: 'data_offsets' (see e.g. loading
1016+ # MiniMaxAI/MiniMax-M3-MXFP8 via vLLM --load-format fastsafetensors).
1017+ device , _ = get_and_check_device (framework )
1018+ filename = os .path .join (tmp_dir , "empty_metadata.safetensors" )
1019+ a0 = framework .randn ((4 , 8 ), device = device , dtype = DType .F32 )
1020+ save_safetensors_file ({"a0" : a0 .get_raw ()}, filename , {}, framework )
1021+
1022+ meta = SafeTensorsMetadata .from_file (filename , framework )
1023+ assert "a0" in meta .tensors
1024+ assert meta .tensors ["a0" ].shape == [4 , 8 ]
1025+ assert meta .metadata == {}
1026+
1027+
10111028def test_no_module_level_torch_import_outside_frameworks () -> None :
10121029 # Policy: framework-specific imports live behind the frameworks
10131030 # abstraction. Only the torch backend (frameworks/_torch.py) may import
0 commit comments