|
6 | 6 | from tests_pytorch.helpers.runif import RunIf
|
7 | 7 |
|
8 | 8 |
|
9 |
| -def create_boring_checkpoint(): |
| 9 | +def create_boring_checkpoint(tmpdir): |
10 | 10 | model = BoringModel()
|
11 | 11 | trainer = pl.Trainer(accelerator="auto", max_epochs=1, enable_model_summary=False, enable_progress_bar=False)
|
12 | 12 | trainer.fit(model)
|
13 |
| - trainer.save_checkpoint("./boring.ckpt") |
| 13 | + trainer.save_checkpoint(f"{tmpdir}/boring.ckpt") |
14 | 14 |
|
15 | 15 |
|
16 | 16 | @pytest.mark.parametrize("map_location", ("cpu", torch.device("cpu"), lambda storage, loc: storage, {"cpu": "cpu"}))
|
17 |
| -def test_load_from_checkpoint_map_location_cpu(map_location): |
18 |
| - create_boring_checkpoint() |
19 |
| - model = BoringModel.load_from_checkpoint("./boring.ckpt", map_location=map_location) |
| 17 | +def test_load_from_checkpoint_map_location_cpu(tmpdir, map_location): |
| 18 | + create_boring_checkpoint(tmpdir) |
| 19 | + model = BoringModel.load_from_checkpoint(f"{tmpdir}/boring.ckpt", map_location=map_location) |
20 | 20 | assert model.device.type == "cpu"
|
21 | 21 |
|
22 | 22 |
|
23 | 23 | @RunIf(min_cuda_gpus=1)
|
24 | 24 | @pytest.mark.parametrize(
|
25 | 25 | "map_location", ("cuda", torch.device("cuda"), lambda storage, loc: storage.cuda(), {"cpu": "cuda"})
|
26 | 26 | )
|
27 |
| -def test_load_from_checkpoint_map_location_gpu(map_location): |
28 |
| - create_boring_checkpoint() |
29 |
| - model = BoringModel.load_from_checkpoint("./boring.ckpt", map_location=map_location) |
| 27 | +def test_load_from_checkpoint_map_location_gpu(tmpdir, map_location): |
| 28 | + create_boring_checkpoint(tmpdir) |
| 29 | + model = BoringModel.load_from_checkpoint(f"{tmpdir}/boring.ckpt", map_location=map_location) |
30 | 30 | assert model.device.type == "cuda"
|
0 commit comments