@@ -950,6 +950,23 @@ def dribbling_read(fd: int, length: int) -> bytes:
950950 assert meta .tensors ["a0" ].shape == [4 , 8 ]
951951
952952
953+ def test_from_file_empty_metadata (tmp_dir , framework ) -> None :
954+ # Regression test: a safetensors file whose header carries an empty
955+ # __metadata__: {} object must parse without raising. Previously,
956+ # __metadata__ was stripped only when truthy, so {} survived into the
957+ # tensor sort and raised KeyError: 'data_offsets' (see e.g. loading
958+ # MiniMaxAI/MiniMax-M3-MXFP8 via vLLM --load-format fastsafetensors).
959+ device , _ = get_and_check_device (framework )
960+ filename = os .path .join (tmp_dir , "empty_metadata.safetensors" )
961+ a0 = framework .randn ((4 , 8 ), device = device , dtype = DType .F32 )
962+ save_safetensors_file ({"a0" : a0 .get_raw ()}, filename , {}, framework )
963+
964+ meta = SafeTensorsMetadata .from_file (filename , framework )
965+ assert "a0" in meta .tensors
966+ assert meta .tensors ["a0" ].shape == [4 , 8 ]
967+ assert meta .metadata == {}
968+
969+
953970def test_no_module_level_torch_import_outside_frameworks () -> None :
954971 # Policy: framework-specific imports live behind the frameworks
955972 # abstraction. Only the torch backend (frameworks/_torch.py) may import
0 commit comments