-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(torchx/components) Fix entrypoint loading to deal with deferred load… #695
Conversation
@kiukchung lots of CI failures (docs, pyre, unit) are the relevant ones I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
||
|
||
When you register your own components, TorchX will not include its own builtins. To add TorchX's | ||
builtin components you must specify another entry as: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may want to mention you can do this in the config as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the one supported by .torchxconfig
is super weird (I want to deprecate it in favor of supporting "alias" -> "module_name" style custom components from .torchxconfig
). Currently what you can do is to have a section like
# .torchxconfig
[torchx.file]
get_file_contents = my.custom.file_reader:read
And when you run
torchx run my/custom.py:component_fn
We call my.custom.file_reader.read("my/custom.py")
which we expect to load the component_fn
into the global namespace. Took me a while to wrap my head around it, so I don't expect anyone to actually use it.
Instead I'd like to support something like this from .torchxconfig
:
# .torchxconfig
[torchx.components]
foo = my.custom.component
_ = torchx.components
which would be the same as doing
# setup.py
entrypoints = {
"torchx.components": [
"foo = my.custom.component",
"_ = torchx.components",
],
}
entry_points={ | ||
"torchx.components": [ | ||
"foo = my_project.bar", | ||
"torchx = torchx.components", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this now works recursively? got it, interesting OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was always loading recursively (by file not by module though)
entry_points={ | ||
"torchx.components": [ | ||
"_0 = my_project.bar", | ||
"_1 = torchx.components", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to drop the dist. and utils. prefixes for TorchX components now? not a blocker for this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah so we could drop the "module" name from the builtin components (as discussed offline we'd have to keep the alias dist.*
,util.*
etc while hiding them from torchx builtins
). Should be easy to do now since we can make the builtins load:
ModuleComponentsFinder("torchx.components.dist", group="")
ModuleComponentsFinder("torchx.components.utils", group="")
# ... and so on...
f524756
to
0e0eab0
Compare
Codecov Report
@@ Coverage Diff @@
## main #695 +/- ##
==========================================
+ Coverage 92.39% 92.46% +0.06%
==========================================
Files 83 86 +3
Lines 5670 5666 -4
==========================================
Hits 5239 5239
+ Misses 431 427 -4
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
c675569
to
6cf97e9
Compare
…ing of modules to enable component registration to work properly
Also resolves: #694 by passing |
Fixes a bug + enhances custom component registration.
[bugfix] torchx not allowing components to be registered via
[torchx.components]
entrypoint because of a change inutils.entrypoints.load_entrypoints()
that defers the entrypoint load by wrapping the entrypoints with a_defer_load_fn()
but assumes that all entrypoints are functions (e.g.foo.bar:baz
) and does not handle modules (e.g.foo.bar
). Adds graceful handling of module entrypoints.[enhancement] Allows users to specify an "empty" group (e.g. no prefix) for component names by using the
_*
"special" prefix in the alias key (similar to "hidden" variables in python). Examplenames
dist.ddp
as justddp
andutils.python
as justpython
[change] If custom components are registered via entrypoints, skips loading builtins. Users can still load the builtins by adding an extra line in their entrypoint as:
[docs] Reflected the changes above in the docs page
[todo fix] resolves [file-linter] Refactor file-linter and components-finder #261 since we no longer have
components_base.py
fileTest plan:
Added unittests + revised unittests for
utils.entrypoints
andspecs.finder