From: Nicolas Patry Date: Wed, 2 Nov 2022 15:53:16 +0000 (+0100) Subject: Adding M1 (mps) benchmarks (going first through CPU seems faster though? (#51) X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=d4aec9801561e168b6d71b55168de202b4114a3a;p=safetensors.git Adding M1 (mps) benchmarks (going first through CPU seems faster though? (#51) but PT is just as slow going directly on MPS.). --- diff --git a/bindings/python/benches/test_pt.py b/bindings/python/benches/test_pt.py index 49827a5..716d20c 100644 --- a/bindings/python/benches/test_pt.py +++ b/bindings/python/benches/test_pt.py @@ -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)