Skip to content

Commit a4b0095

Browse files
authored
Merge branch 'master' into feature-save-ckpt
2 parents 2aece26 + cae3335 commit a4b0095

File tree

9 files changed

+103
-48
lines changed

9 files changed

+103
-48
lines changed

.github/checkgroup.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ subprojects:
1919
- "!*.md"
2020
- "!**/*.md"
2121
checks:
22-
- "pl-cpu (macOS-13, lightning, 3.9, 2.1, oldest)"
22+
- "pl-cpu (macOS-14, lightning, 3.9, 2.1, oldest)"
2323
- "pl-cpu (macOS-14, lightning, 3.10, 2.1)"
2424
- "pl-cpu (macOS-14, lightning, 3.11, 2.2.2)"
2525
- "pl-cpu (macOS-14, lightning, 3.11, 2.3)"
@@ -40,9 +40,9 @@ subprojects:
4040
- "pl-cpu (macOS-14, pytorch, 3.9, 2.1)"
4141
- "pl-cpu (ubuntu-20.04, pytorch, 3.9, 2.1)"
4242
- "pl-cpu (windows-2022, pytorch, 3.9, 2.1)"
43-
- "pl-cpu (macOS-13, pytorch, 3.10, 2.1)"
44-
- "pl-cpu (ubuntu-22.04, pytorch, 3.10, 2.1)"
45-
- "pl-cpu (windows-2022, pytorch, 3.10, 2.1)"
43+
- "pl-cpu (macOS-14, pytorch, 3.12, 2.5.1)"
44+
- "pl-cpu (ubuntu-22.04, pytorch, 3.12, 2.5.1)"
45+
- "pl-cpu (windows-2022, pytorch, 3.12, 2.5.1)"
4646

4747
- id: "pytorch_lightning: Azure GPU"
4848
paths:
@@ -171,7 +171,7 @@ subprojects:
171171
- "!*.md"
172172
- "!**/*.md"
173173
checks:
174-
- "fabric-cpu (macOS-13, lightning, 3.9, 2.1, oldest)"
174+
- "fabric-cpu (macOS-14, lightning, 3.9, 2.1, oldest)"
175175
- "fabric-cpu (macOS-14, lightning, 3.10, 2.1)"
176176
- "fabric-cpu (macOS-14, lightning, 3.11, 2.2.2)"
177177
- "fabric-cpu (macOS-14, lightning, 3.11, 2.3)"
@@ -192,9 +192,9 @@ subprojects:
192192
- "fabric-cpu (macOS-14, fabric, 3.9, 2.1)"
193193
- "fabric-cpu (ubuntu-20.04, fabric, 3.9, 2.1)"
194194
- "fabric-cpu (windows-2022, fabric, 3.9, 2.1)"
195-
- "fabric-cpu (macOS-13, fabric, 3.10, 2.1)"
196-
- "fabric-cpu (ubuntu-22.04, fabric, 3.10, 2.1)"
197-
- "fabric-cpu (windows-2022, fabric, 3.10, 2.1)"
195+
- "fabric-cpu (macOS-14, fabric, 3.12, 2.5.1)"
196+
- "fabric-cpu (ubuntu-22.04, fabric, 3.12, 2.5.1)"
197+
- "fabric-cpu (windows-2022, fabric, 3.12, 2.5.1)"
198198

199199
- id: "lightning_fabric: Azure GPU"
200200
paths:
@@ -266,14 +266,14 @@ subprojects:
266266
- "install-pkg (ubuntu-22.04, lightning, 3.11)"
267267
- "install-pkg (ubuntu-22.04, notset, 3.9)"
268268
- "install-pkg (ubuntu-22.04, notset, 3.11)"
269-
- "install-pkg (macOS-13, fabric, 3.9)"
270-
- "install-pkg (macOS-13, fabric, 3.11)"
271-
- "install-pkg (macOS-13, pytorch, 3.9)"
272-
- "install-pkg (macOS-13, pytorch, 3.11)"
273-
- "install-pkg (macOS-13, lightning, 3.9)"
274-
- "install-pkg (macOS-13, lightning, 3.11)"
275-
- "install-pkg (macOS-13, notset, 3.9)"
276-
- "install-pkg (macOS-13, notset, 3.11)"
269+
- "install-pkg (macOS-14, fabric, 3.9)"
270+
- "install-pkg (macOS-14, fabric, 3.11)"
271+
- "install-pkg (macOS-14, pytorch, 3.9)"
272+
- "install-pkg (macOS-14, pytorch, 3.11)"
273+
- "install-pkg (macOS-14, lightning, 3.9)"
274+
- "install-pkg (macOS-14, lightning, 3.11)"
275+
- "install-pkg (macOS-14, notset, 3.9)"
276+
- "install-pkg (macOS-14, notset, 3.11)"
277277
- "install-pkg (windows-2022, fabric, 3.9)"
278278
- "install-pkg (windows-2022, fabric, 3.11)"
279279
- "install-pkg (windows-2022, pytorch, 3.9)"

.github/workflows/ci-pkg-install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
strategy:
4343
fail-fast: false
4444
matrix:
45-
os: ["ubuntu-22.04", "macOS-13", "windows-2022"]
45+
os: ["ubuntu-22.04", "macOS-14", "windows-2022"]
4646
pkg-name: ["fabric", "pytorch", "lightning", "notset"]
4747
python-version: ["3.9", "3.11"]
4848
steps:

.github/workflows/ci-tests-fabric.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ jobs:
5656
- { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" }
5757
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" }
5858
# only run PyTorch latest with Python latest, use Fabric scope to limit dependency issues
59-
- { os: "macOS-13", pkg-name: "fabric", python-version: "3.10", pytorch-version: "2.1" }
60-
- { os: "ubuntu-22.04", pkg-name: "fabric", python-version: "3.10", pytorch-version: "2.1" }
61-
- { os: "windows-2022", pkg-name: "fabric", python-version: "3.10", pytorch-version: "2.1" }
59+
- { os: "macOS-14", pkg-name: "fabric", python-version: "3.12", pytorch-version: "2.5.1" }
60+
- { os: "ubuntu-22.04", pkg-name: "fabric", python-version: "3.12", pytorch-version: "2.5.1" }
61+
- { os: "windows-2022", pkg-name: "fabric", python-version: "3.12", pytorch-version: "2.5.1" }
6262
# "oldest" versions tests, only on minimum Python
63-
- { os: "macOS-13", pkg-name: "lightning", python-version: "3.9", pytorch-version: "2.1", requires: "oldest" }
63+
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.9", pytorch-version: "2.1", requires: "oldest" }
6464
- {
6565
os: "ubuntu-20.04",
6666
pkg-name: "lightning",
@@ -101,7 +101,10 @@ jobs:
101101

102102
- name: Set min. dependencies
103103
if: ${{ matrix.requires == 'oldest' }}
104-
run: python .actions/assistant.py replace_oldest_ver
104+
run: |
105+
python .actions/assistant.py replace_oldest_ver
106+
pip install "cython<3.0" wheel
107+
pip install "pyyaml==5.4" --no-build-isolation
105108
106109
- name: Adjust PyTorch versions in requirements files
107110
if: ${{ matrix.requires != 'oldest' }}

.github/workflows/ci-tests-pytorch.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ jobs:
6060
- { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" }
6161
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" }
6262
# only run PyTorch latest with Python latest, use PyTorch scope to limit dependency issues
63-
- { os: "macOS-13", pkg-name: "pytorch", python-version: "3.10", pytorch-version: "2.1" }
64-
- { os: "ubuntu-22.04", pkg-name: "pytorch", python-version: "3.10", pytorch-version: "2.1" }
65-
- { os: "windows-2022", pkg-name: "pytorch", python-version: "3.10", pytorch-version: "2.1" }
63+
- { os: "macOS-14", pkg-name: "pytorch", python-version: "3.12", pytorch-version: "2.5.1" }
64+
- { os: "ubuntu-22.04", pkg-name: "pytorch", python-version: "3.12", pytorch-version: "2.5.1" }
65+
- { os: "windows-2022", pkg-name: "pytorch", python-version: "3.12", pytorch-version: "2.5.1" }
6666
# "oldest" versions tests, only on minimum Python
67-
- { os: "macOS-13", pkg-name: "lightning", python-version: "3.9", pytorch-version: "2.1", requires: "oldest" }
67+
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.9", pytorch-version: "2.1", requires: "oldest" }
6868
- {
6969
os: "ubuntu-20.04",
7070
pkg-name: "lightning",
@@ -106,7 +106,10 @@ jobs:
106106

107107
- name: Set min. dependencies
108108
if: ${{ matrix.requires == 'oldest' }}
109-
run: python .actions/assistant.py replace_oldest_ver
109+
run: |
110+
python .actions/assistant.py replace_oldest_ver
111+
pip install "cython<3.0" wheel
112+
pip install "pyyaml==5.4" --no-build-isolation
110113
111114
- name: Adjust PyTorch versions in requirements files
112115
if: ${{ matrix.requires != 'oldest' }}

src/lightning/fabric/utilities/throughput.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,14 @@ def measure_flops(
347347
torch.int8: 389.9e12,
348348
"int4": 779.8e12,
349349
},
350+
"rtx 4080 super": {
351+
torch.float32: 52.2e12,
352+
"tfloat32": 52.2e12,
353+
torch.bfloat16: 52.2e12,
354+
torch.float16: 52.2e12,
355+
torch.int8: 417.6e12,
356+
"int4": 835.2e12,
357+
},
350358
"l4": {
351359
torch.float32: 30.3e12,
352360
"tfloat32": 60e12,

src/lightning/pytorch/loggers/mlflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def save_dir(self) -> Optional[str]:
299299
300300
"""
301301
if self._tracking_uri.startswith(LOCAL_FILE_URI_PREFIX):
302-
return self._tracking_uri.lstrip(LOCAL_FILE_URI_PREFIX)
302+
return self._tracking_uri[len(LOCAL_FILE_URI_PREFIX) :]
303303
return None
304304

305305
@property

src/lightning/pytorch/utilities/data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ def _is_dataloader_shuffled(dataloader: object) -> bool:
349349
if not hasattr(dataloader, "sampler"):
350350
# shuffling is enabled via a sampler. No sampler, no shuffling
351351
return False
352-
sampler = dataloader.sampler
352+
batch_sampler = dataloader.batch_sampler
353+
sampler = batch_sampler.sampler if batch_sampler is not None else dataloader.sampler
353354
if isinstance(sampler, SequentialSampler):
354355
return False
355356
return isinstance(sampler, RandomSampler)

tests/tests_pytorch/test_cli.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -871,18 +871,27 @@ def test_lightning_cli_load_from_checkpoint_dependency_injection(cleandir):
871871
hparams_path = Path(cli.trainer.log_dir) / "hparams.yaml"
872872
assert hparams_path.is_file()
873873
hparams = yaml.safe_load(hparams_path.read_text())
874-
expected = {
875-
"_instantiator": "lightning.pytorch.cli.instantiate_module",
876-
"optimizer": "torch.optim.Adam",
877-
"scheduler": "torch.optim.lr_scheduler.ConstantLR",
878-
"activation": {"class_path": "torch.nn.LeakyReLU", "init_args": {"negative_slope": 0.05, "inplace": False}},
879-
}
880-
assert hparams == expected
874+
875+
expected_keys = ["_instantiator", "activation", "optimizer", "scheduler"]
876+
expected_instantiator = "lightning.pytorch.cli.instantiate_module"
877+
expected_activation = "torch.nn.LeakyReLU"
878+
expected_optimizer = "torch.optim.Adam"
879+
expected_scheduler = "torch.optim.lr_scheduler.ConstantLR"
880+
881+
assert sorted(hparams.keys()) == expected_keys
882+
assert hparams["_instantiator"] == expected_instantiator
883+
assert hparams["activation"]["class_path"] == expected_activation
884+
assert hparams["optimizer"] == expected_optimizer or hparams["optimizer"]["class_path"] == expected_optimizer
885+
assert hparams["scheduler"] == expected_scheduler or hparams["scheduler"]["class_path"] == expected_scheduler
881886

882887
checkpoint_path = next(Path(cli.trainer.log_dir, "checkpoints").glob("*.ckpt"), None)
883888
assert checkpoint_path.is_file()
884-
ckpt = torch.load(checkpoint_path, weights_only=True)
885-
assert ckpt["hyper_parameters"] == expected
889+
hparams = torch.load(checkpoint_path, weights_only=True)["hyper_parameters"]
890+
assert sorted(hparams.keys()) == expected_keys
891+
assert hparams["_instantiator"] == expected_instantiator
892+
assert hparams["activation"]["class_path"] == expected_activation
893+
assert hparams["optimizer"] == expected_optimizer or hparams["optimizer"]["class_path"] == expected_optimizer
894+
assert hparams["scheduler"] == expected_scheduler or hparams["scheduler"]["class_path"] == expected_scheduler
886895

887896
model = TestModelSaveHparams.load_from_checkpoint(checkpoint_path)
888897
assert isinstance(model, TestModelSaveHparams)
@@ -898,18 +907,23 @@ def test_lightning_cli_load_from_checkpoint_dependency_injection_subclass_mode(c
898907
cli = LightningCLI(TestModelSaveHparams, run=False, auto_configure_optimizers=False, subclass_mode_model=True)
899908
cli.trainer.fit(cli.model)
900909

901-
expected = {
902-
"_instantiator": "lightning.pytorch.cli.instantiate_module",
903-
"_class_path": f"{__name__}.TestModelSaveHparams",
904-
"optimizer": "torch.optim.Adam",
905-
"scheduler": "torch.optim.lr_scheduler.ConstantLR",
906-
"activation": {"class_path": "torch.nn.LeakyReLU", "init_args": {"negative_slope": 0.05, "inplace": False}},
907-
}
910+
expected_keys = ["_class_path", "_instantiator", "activation", "optimizer", "scheduler"]
911+
expected_instantiator = "lightning.pytorch.cli.instantiate_module"
912+
expected_class_path = f"{__name__}.TestModelSaveHparams"
913+
expected_activation = "torch.nn.LeakyReLU"
914+
expected_optimizer = "torch.optim.Adam"
915+
expected_scheduler = "torch.optim.lr_scheduler.ConstantLR"
908916

909917
checkpoint_path = next(Path(cli.trainer.log_dir, "checkpoints").glob("*.ckpt"), None)
910918
assert checkpoint_path.is_file()
911-
ckpt = torch.load(checkpoint_path, weights_only=True)
912-
assert ckpt["hyper_parameters"] == expected
919+
hparams = torch.load(checkpoint_path, weights_only=True)["hyper_parameters"]
920+
921+
assert sorted(hparams.keys()) == expected_keys
922+
assert hparams["_instantiator"] == expected_instantiator
923+
assert hparams["_class_path"] == expected_class_path
924+
assert hparams["activation"]["class_path"] == expected_activation
925+
assert hparams["optimizer"] == expected_optimizer or hparams["optimizer"]["class_path"] == expected_optimizer
926+
assert hparams["scheduler"] == expected_scheduler or hparams["scheduler"]["class_path"] == expected_scheduler
913927

914928
model = LightningModule.load_from_checkpoint(checkpoint_path)
915929
assert isinstance(model, TestModelSaveHparams)

tests/tests_pytorch/utilities/test_data.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from lightning.pytorch.trainer.states import RunningStage
1313
from lightning.pytorch.utilities.data import (
1414
_get_dataloader_init_args_and_kwargs,
15+
_is_dataloader_shuffled,
1516
_update_dataloader,
1617
extract_batch_size,
1718
has_len_all_ranks,
@@ -20,7 +21,7 @@
2021
from lightning.pytorch.utilities.exceptions import MisconfigurationException
2122
from lightning_utilities.test.warning import no_warning_call
2223
from torch import Tensor
23-
from torch.utils.data import BatchSampler, DataLoader, RandomSampler
24+
from torch.utils.data import BatchSampler, DataLoader, RandomSampler, SequentialSampler
2425

2526

2627
def test_extract_batch_size():
@@ -304,6 +305,31 @@ def __init__(self, extra_arg):
304305
_ = _update_dataloader(dataloader, dataloader.sampler, mode=RunningStage.PREDICTING)
305306

306307

308+
def test_batch_sampler_shuffle_setting():
309+
"""Test whether the `shuffle` state is correctly set in the `BatchSampler`."""
310+
311+
random_sampler = RandomSampler(range(10))
312+
seq_sampler = SequentialSampler(range(10))
313+
shuffled_dataloader = DataLoader(
314+
range(10), batch_sampler=BatchSampler(random_sampler, batch_size=2, drop_last=False)
315+
)
316+
sequential_dataloader = DataLoader(
317+
range(10), batch_sampler=BatchSampler(seq_sampler, batch_size=2, drop_last=False)
318+
)
319+
320+
# if batch_size is 1, the pytorch init a default SequentialSampler and set BatchSampler to None
321+
single_dataloader = DataLoader(range(10), batch_sampler=BatchSampler(seq_sampler, batch_size=1, drop_last=False))
322+
assert _is_dataloader_shuffled(shuffled_dataloader)
323+
assert not _is_dataloader_shuffled(sequential_dataloader)
324+
assert not _is_dataloader_shuffled(single_dataloader)
325+
326+
# if batch_size is 1, and no batch_sampler is set, the pytorch will set BatchSampler to None
327+
single_dataloader = DataLoader(range(10), batch_size=1)
328+
shuffled_single_dataloader = DataLoader(range(10), batch_size=1, shuffle=True)
329+
assert not _is_dataloader_shuffled(single_dataloader)
330+
assert _is_dataloader_shuffled(shuffled_single_dataloader)
331+
332+
307333
@pytest.mark.parametrize("mode", [RunningStage.TRAINING, RunningStage.PREDICTING, RunningStage.TESTING])
308334
def test_dataloader_kwargs_replacement_with_iterable_dataset(mode):
309335
"""Test that DataLoader kwargs are not replaced when using Iterable Dataset."""

0 commit comments

Comments
 (0)