]> khamidou — GitHub mirrors - safetensors.git/commitdiff
Adding M1 (mps) benchmarks (going first through CPU seems faster though? (#51)
authorNicolas Patry <patry.nicolas@protonmail.com>
Wed, 2 Nov 2022 15:53:16 +0000 (16:53 +0100)
committerGitHub <noreply@github.com>
Wed, 2 Nov 2022 15:53:16 +0000 (16:53 +0100)
but PT is just as slow going directly on MPS.).

bindings/python/benches/test_pt.py

index 49827a5ea5832833c447dc91d25fa51406aa3be1..716d20c8a4838c4616ec454ee21a012e70b2abdd 100644 (file)
@@ -79,3 +79,31 @@ def test_pt_sf_load_gpu(benchmark):
         v = v.cuda()
         tv = result[k]
         assert torch.allclose(v, tv)
+
+
+@pytest.mark.skipif(not torch.backends.mps.is_available(), reason="requires mps")
+def test_pt_pt_load_mps(benchmark):
+    # benchmark something
+    weights = create_gpt2(12)
+    with tempfile.NamedTemporaryFile() as f:
+        torch.save(weights, f)
+        result = benchmark(torch.load, f.name, map_location="mps")
+
+    for k, v in weights.items():
+        v = v.to(device="mps")
+        tv = result[k]
+        assert torch.allclose(v, tv)
+
+
+@pytest.mark.skipif(not torch.backends.mps.is_available(), reason="requires mps")
+def test_pt_sf_load_mps(benchmark):
+    # benchmark something
+    weights = create_gpt2(12)
+    with tempfile.NamedTemporaryFile() as f:
+        save_file(weights, f.name)
+        result = benchmark(load_file, f.name, device="mps")
+
+    for k, v in weights.items():
+        v = v.to(device="mps")
+        tv = result[k]
+        assert torch.allclose(v, tv)