Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions torchx/schedulers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ def get_scheduler_factories(
The first scheduler in the dictionary is used as the default scheduler.
"""

default_schedulers: dict[str, SchedulerFactory] = {}
for scheduler, path in DEFAULT_SCHEDULER_MODULES.items():
default_schedulers[scheduler] = _defer_load_scheduler(path)

return load_group(
group,
default=default_schedulers,
skip_defaults=skip_defaults,
)
if skip_defaults:
default_schedulers = {}
else:
default_schedulers: dict[str, SchedulerFactory] = {}
for scheduler, path in DEFAULT_SCHEDULER_MODULES.items():
default_schedulers[scheduler] = _defer_load_scheduler(path)

return load_group(group, default=default_schedulers)


def get_default_scheduler_name() -> str:
Expand Down
7 changes: 1 addition & 6 deletions torchx/util/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def run(*args: object, **kwargs: object) -> object:
return run


def load_group(
group: str, default: Optional[Dict[str, Any]] = None, skip_defaults: bool = False
):
def load_group(group: str, default: Optional[Dict[str, Any]] = None):
"""
Loads all the entry points specified by ``group`` and returns
the entry points as a map of ``name (str) -> deferred_load_fn``.
Expand All @@ -90,7 +88,6 @@ def load_group(
1. ``load_group("foo")["bar"]("baz")`` -> equivalent to calling ``this.is.a_fn("baz")``
1. ``load_group("food")`` -> ``None``
1. ``load_group("food", default={"hello": this.is.c_fn})["hello"]("world")`` -> equivalent to calling ``this.is.c_fn("world")``
1. ``load_group("food", default={"hello": this.is.c_fn}, skip_defaults=True)`` -> ``None``


If the entrypoint is a module (versus a function as shown above), then calling the ``deferred_load_fn``
Expand All @@ -115,8 +112,6 @@ def load_group(
entrypoints = metadata.entry_points().get(group, ())

if len(entrypoints) == 0:
if skip_defaults:
return None
return default

eps = {}
Expand Down
5 changes: 0 additions & 5 deletions torchx/util/test/entrypoints_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ def test_load_group_with_default(self, _: MagicMock) -> None:
self.assertEqual("barbaz", eps["foo"]())
self.assertEqual("foobar", eps["bar"]())

eps = load_group(
"ep.grp.test.missing", {"foo": barbaz, "bar": foobar}, skip_defaults=True
)
self.assertIsNone(eps)

@patch(_METADATA_EPS, return_value=_ENTRY_POINTS)
def test_load_group_missing(self, _: MagicMock) -> None:
with self.assertRaises(AttributeError):
Expand Down
Loading