Skip to content

Commit bfa0fd4

Browse files
authored
Merge branch 'master' into chualan/fix-19658
2 parents 1c040d7 + 75d7357 commit bfa0fd4

File tree

238 files changed

+1499
-1372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+1499
-1372
lines changed

.actions/assistant.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
import shutil
1919
import tempfile
2020
import urllib.request
21+
from collections.abc import Iterable, Iterator, Sequence
2122
from itertools import chain
2223
from os.path import dirname, isfile
2324
from pathlib import Path
24-
from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Tuple
25+
from typing import Any, Optional
2526

2627
from packaging.requirements import Requirement
2728
from packaging.version import Version
@@ -127,7 +128,7 @@ def _parse_requirements(lines: Iterable[str]) -> Iterator[_RequirementWithCommen
127128
pip_argument = None
128129

129130

130-
def load_requirements(path_dir: str, file_name: str = "base.txt", unfreeze: str = "all") -> List[str]:
131+
def load_requirements(path_dir: str, file_name: str = "base.txt", unfreeze: str = "all") -> list[str]:
131132
"""Loading requirements from a file.
132133
133134
>>> path_req = os.path.join(_PROJECT_ROOT, "requirements")
@@ -222,7 +223,7 @@ def _load_aggregate_requirements(req_dir: str = "requirements", freeze_requireme
222223
fp.writelines([ln + os.linesep for ln in requires] + [os.linesep])
223224

224225

225-
def _retrieve_files(directory: str, *ext: str) -> List[str]:
226+
def _retrieve_files(directory: str, *ext: str) -> list[str]:
226227
all_files = []
227228
for root, _, files in os.walk(directory):
228229
for fname in files:
@@ -232,7 +233,7 @@ def _retrieve_files(directory: str, *ext: str) -> List[str]:
232233
return all_files
233234

234235

235-
def _replace_imports(lines: List[str], mapping: List[Tuple[str, str]], lightning_by: str = "") -> List[str]:
236+
def _replace_imports(lines: list[str], mapping: list[tuple[str, str]], lightning_by: str = "") -> list[str]:
236237
"""Replace imports of standalone package to lightning.
237238
238239
>>> lns = [
@@ -320,7 +321,7 @@ def copy_replace_imports(
320321
fo.writelines(lines)
321322

322323

323-
def create_mirror_package(source_dir: str, package_mapping: Dict[str, str]) -> None:
324+
def create_mirror_package(source_dir: str, package_mapping: dict[str, str]) -> None:
324325
"""Create a mirror package with adjusted imports."""
325326
# replace imports and copy the code
326327
mapping = package_mapping.copy()

.github/workflows/_legacy-checkpoints.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
- uses: actions/setup-python@v5
6161
with:
6262
# Python version here needs to be supported by all PL versions listed in back-compatible-versions.txt.
63-
python-version: 3.8
63+
python-version: "3.9"
6464

6565
- name: Install PL from source
6666
env:

.github/workflows/call-clear-cache.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ on:
2323
jobs:
2424
cron-clear:
2525
if: github.event_name == 'schedule' || github.event_name == 'pull_request'
26-
uses: Lightning-AI/utilities/.github/workflows/[email protected].8
26+
uses: Lightning-AI/utilities/.github/workflows/[email protected].9
2727
with:
2828
scripts-ref: v0.11.8
2929
dry-run: ${{ github.event_name == 'pull_request' }}
@@ -32,7 +32,7 @@ jobs:
3232

3333
direct-clear:
3434
if: github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request'
35-
uses: Lightning-AI/utilities/.github/workflows/[email protected].8
35+
uses: Lightning-AI/utilities/.github/workflows/[email protected].9
3636
with:
3737
scripts-ref: v0.11.8
3838
dry-run: ${{ github.event_name == 'pull_request' }}

.github/workflows/ci-check-md-links.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
jobs:
1616
check-md-links:
17-
uses: Lightning-AI/utilities/.github/workflows/[email protected].8
17+
uses: Lightning-AI/utilities/.github/workflows/[email protected].9
1818
with:
1919
config-file: ".github/markdown-links-config.json"
2020
base-branch: "master"

.github/workflows/ci-schema.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
check:
11-
uses: Lightning-AI/utilities/.github/workflows/[email protected].8
11+
uses: Lightning-AI/utilities/.github/workflows/[email protected].9
1212
with:
1313
# skip azure due to the wrong schema file by MSFT
1414
# https://github.com/Lightning-AI/lightning-flash/pull/1455#issuecomment-1244793607

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ repos:
7474
hooks:
7575
# try to fix what is possible
7676
- id: ruff
77-
args: ["--fix"]
77+
args: ["--fix", "--unsafe-fixes"]
7878
# perform formatting updates
7979
- id: ruff-format
8080
# validate if all is fine with preview mode

docs/source-pytorch/accelerators/tpu_faq.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ Unsupported datatype transfer to TPUs?
4040

4141
.. code-block::
4242
43-
File "/usr/local/lib/python3.8/dist-packages/torch_xla/utils/utils.py", line 205, in _for_each_instance_rewrite
43+
File "/usr/local/lib/python3.9/dist-packages/torch_xla/utils/utils.py", line 205, in _for_each_instance_rewrite
4444
v = _for_each_instance_rewrite(result.__dict__[k], select_fn, fn, rwmap)
45-
File "/usr/local/lib/python3.8/dist-packages/torch_xla/utils/utils.py", line 206, in _for_each_instance_rewrite
45+
File "/usr/local/lib/python3.9/dist-packages/torch_xla/utils/utils.py", line 206, in _for_each_instance_rewrite
4646
result.__dict__[k] = v
4747
TypeError: 'mappingproxy' object does not support item assignment
4848

docs/source-pytorch/advanced/post_training_quantization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Installation
3333
Prerequisites
3434
=============
3535

36-
Python version: 3.8, 3.9, 3.10
36+
Python version: 3.9, 3.10
3737

3838
Install Intel® Neural Compressor
3939
================================

examples/fabric/build_your_own_trainer/trainer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
2-
from collections.abc import Mapping
2+
from collections.abc import Iterable, Mapping
33
from functools import partial
4-
from typing import Any, Iterable, List, Literal, Optional, Tuple, Union, cast
4+
from typing import Any, Literal, Optional, Union, cast
55

66
import lightning as L
77
import torch
@@ -19,11 +19,11 @@ def __init__(
1919
self,
2020
accelerator: Union[str, Accelerator] = "auto",
2121
strategy: Union[str, Strategy] = "auto",
22-
devices: Union[List[int], str, int] = "auto",
22+
devices: Union[list[int], str, int] = "auto",
2323
precision: Union[str, int] = "32-true",
2424
plugins: Optional[Union[str, Any]] = None,
25-
callbacks: Optional[Union[List[Any], Any]] = None,
26-
loggers: Optional[Union[Logger, List[Logger]]] = None,
25+
callbacks: Optional[Union[list[Any], Any]] = None,
26+
loggers: Optional[Union[Logger, list[Logger]]] = None,
2727
max_epochs: Optional[int] = 1000,
2828
max_steps: Optional[int] = None,
2929
grad_accum_steps: int = 1,
@@ -465,7 +465,7 @@ def get_latest_checkpoint(checkpoint_dir: str) -> Optional[str]:
465465

466466
def _parse_optimizers_schedulers(
467467
self, configure_optim_output
468-
) -> Tuple[
468+
) -> tuple[
469469
Optional[L.fabric.utilities.types.Optimizable],
470470
Optional[Mapping[str, Union[L.fabric.utilities.types.LRScheduler, bool, str, int]]],
471471
]:

examples/fabric/reinforcement_learning/rl/agent.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import math
2-
from typing import Dict, Tuple
32

43
import gymnasium as gym
54
import torch
@@ -43,7 +42,7 @@ def __init__(self, envs: gym.vector.SyncVectorEnv, act_fun: str = "relu", ortho_
4342
layer_init(torch.nn.Linear(64, envs.single_action_space.n), std=0.01, ortho_init=ortho_init),
4443
)
4544

46-
def get_action(self, x: Tensor, action: Tensor = None) -> Tuple[Tensor, Tensor, Tensor]:
45+
def get_action(self, x: Tensor, action: Tensor = None) -> tuple[Tensor, Tensor, Tensor]:
4746
logits = self.actor(x)
4847
distribution = Categorical(logits=logits)
4948
if action is None:
@@ -58,12 +57,12 @@ def get_greedy_action(self, x: Tensor) -> Tensor:
5857
def get_value(self, x: Tensor) -> Tensor:
5958
return self.critic(x)
6059

61-
def get_action_and_value(self, x: Tensor, action: Tensor = None) -> Tuple[Tensor, Tensor, Tensor, Tensor]:
60+
def get_action_and_value(self, x: Tensor, action: Tensor = None) -> tuple[Tensor, Tensor, Tensor, Tensor]:
6261
action, log_prob, entropy = self.get_action(x, action)
6362
value = self.get_value(x)
6463
return action, log_prob, entropy, value
6564

66-
def forward(self, x: Tensor, action: Tensor = None) -> Tuple[Tensor, Tensor, Tensor, Tensor]:
65+
def forward(self, x: Tensor, action: Tensor = None) -> tuple[Tensor, Tensor, Tensor, Tensor]:
6766
return self.get_action_and_value(x, action)
6867

6968
@torch.no_grad()
@@ -77,7 +76,7 @@ def estimate_returns_and_advantages(
7776
num_steps: int,
7877
gamma: float,
7978
gae_lambda: float,
80-
) -> Tuple[Tensor, Tensor]:
79+
) -> tuple[Tensor, Tensor]:
8180
next_value = self.get_value(next_obs).reshape(1, -1)
8281
advantages = torch.zeros_like(rewards)
8382
lastgaelam = 0
@@ -143,7 +142,7 @@ def __init__(
143142
self.avg_value_loss = MeanMetric(**torchmetrics_kwargs)
144143
self.avg_ent_loss = MeanMetric(**torchmetrics_kwargs)
145144

146-
def get_action(self, x: Tensor, action: Tensor = None) -> Tuple[Tensor, Tensor, Tensor]:
145+
def get_action(self, x: Tensor, action: Tensor = None) -> tuple[Tensor, Tensor, Tensor]:
147146
logits = self.actor(x)
148147
distribution = Categorical(logits=logits)
149148
if action is None:
@@ -158,12 +157,12 @@ def get_greedy_action(self, x: Tensor) -> Tensor:
158157
def get_value(self, x: Tensor) -> Tensor:
159158
return self.critic(x)
160159

161-
def get_action_and_value(self, x: Tensor, action: Tensor = None) -> Tuple[Tensor, Tensor, Tensor, Tensor]:
160+
def get_action_and_value(self, x: Tensor, action: Tensor = None) -> tuple[Tensor, Tensor, Tensor, Tensor]:
162161
action, log_prob, entropy = self.get_action(x, action)
163162
value = self.get_value(x)
164163
return action, log_prob, entropy, value
165164

166-
def forward(self, x: Tensor, action: Tensor = None) -> Tuple[Tensor, Tensor, Tensor, Tensor]:
165+
def forward(self, x: Tensor, action: Tensor = None) -> tuple[Tensor, Tensor, Tensor, Tensor]:
167166
return self.get_action_and_value(x, action)
168167

169168
@torch.no_grad()
@@ -177,7 +176,7 @@ def estimate_returns_and_advantages(
177176
num_steps: int,
178177
gamma: float,
179178
gae_lambda: float,
180-
) -> Tuple[Tensor, Tensor]:
179+
) -> tuple[Tensor, Tensor]:
181180
next_value = self.get_value(next_obs).reshape(1, -1)
182181
advantages = torch.zeros_like(rewards)
183182
lastgaelam = 0
@@ -193,7 +192,7 @@ def estimate_returns_and_advantages(
193192
returns = advantages + values
194193
return returns, advantages
195194

196-
def training_step(self, batch: Dict[str, Tensor]):
195+
def training_step(self, batch: dict[str, Tensor]):
197196
# Get actions and values given the current observations
198197
_, newlogprob, entropy, newvalue = self(batch["obs"], batch["actions"].long())
199198
logratio = newlogprob - batch["logprobs"]

0 commit comments

Comments
 (0)