Skip to content

Commit 5cc8471

Browse files
authored
Improve performance of available_accelerators by returning a set (#20672)
perf[registry]: update available_accelerators to return a set
1 parent df5dee6 commit 5cc8471

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/lightning/fabric/accelerators/registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ def remove(self, name: str) -> None:
107107
"""Removes the registered accelerator by name."""
108108
self.pop(name)
109109

110-
def available_accelerators(self) -> list[str]:
111-
"""Returns a list of registered accelerators."""
112-
return list(self.keys())
110+
def available_accelerators(self) -> set[str]:
111+
"""Returns a set of registered accelerators."""
112+
return set(self.keys())
113113

114114
def __str__(self) -> str:
115115
return "Registered Accelerators: {}".format(", ".join(self.available_accelerators()))

tests/tests_fabric/accelerators/test_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ def is_available():
7070

7171

7272
def test_available_accelerators_in_registry():
73-
assert ACCELERATOR_REGISTRY.available_accelerators() == ["cpu", "cuda", "mps", "tpu"]
73+
assert ACCELERATOR_REGISTRY.available_accelerators() == {"cpu", "cuda", "mps", "tpu"}

tests/tests_pytorch/accelerators/test_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
def test_available_accelerators_in_registry():
1818
"""Tests the accelerators available by default, not including external, third-party accelerators."""
19-
available = set(AcceleratorRegistry.available_accelerators())
19+
available = AcceleratorRegistry.available_accelerators()
2020
expected = {"cpu", "cuda", "mps", "tpu"}
2121
# Note: the registry is global, other tests may register new strategies as a side effect
2222
assert expected.issubset(available)

0 commit comments

Comments
 (0)