MCPcopy Create free account
hub / github.com/ml-explore/mlx / test_load_f8_e4m3

Method test_load_f8_e4m3

python/tests/test_load.py:167–189  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

165 self.assertTrue(mx.array_equal(load_dict["test"], save_dict["test"]))
166
167 def test_load_f8_e4m3(self):
168 if not os.path.isdir(self.test_dir):
169 os.mkdir(self.test_dir)
170
171 expected = [
172 0,
173 448,
174 -448,
175 -0.875,
176 0.4375,
177 -0.005859,
178 -1.25,
179 -1.25,
180 -1.5,
181 -0.0039,
182 ]
183 expected = mx.array(expected, dtype=mx.bfloat16)
184 contents = b'H\x00\x00\x00\x00\x00\x00\x00{"tensor":{"dtype":"F8_E4M3","shape":[10],"data_offsets":[0,10]}} \x00~\xfe\xb6.\x83\xba\xba\xbc\x82'
185 with tempfile.NamedTemporaryFile(suffix=".safetensors") as f:
186 f.write(contents)
187 f.seek(0)
188 out = mx.load(f)["tensor"]
189 self.assertTrue(mx.allclose(mx.from_fp8(out), expected))
190
191 @unittest.skipIf(platform.system() == "Windows", "GGUF is disabled on Windows")
192 def test_save_and_load_gguf_metadata_basic(self):

Callers

nothing calls this directly

Calls 4

arrayMethod · 0.60
writeMethod · 0.45
seekMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected