generated from VectorInstitute/aieng-template-poetry
-
Notifications
You must be signed in to change notification settings - Fork 12
[Feature] Add DittoPersonalizedMixin
#385
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
0765492
add ditto mixin
nerdai c811fbc
reimports and public api for mixins.personalized
nerdai 2d22847
don't cover protocols
nerdai 9e82518
tests for ensure_protocol_compliance and add unit tests
nerdai 0894136
unit test for make_it_personal factory method
nerdai bfe1dda
wip
nerdai 1f00d95
don't cover protocols
nerdai 789cb1b
test raise no warnings
nerdai 5e64570
test get params
nerdai 26553fa
test get params uninitialized
nerdai 066ae4a
test set params
nerdai f367007
test get optimizers
nerdai 097d82f
predict unit test
nerdai 19b9557
test extract pred
nerdai 7975cc5
test update before train
nerdai 30a895c
test predict private delegation
nerdai 85ee409
wip
nerdai 6c02563
unit test train step
nerdai 68c9da7
update tornado
nerdai 2b578f4
cr
nerdai 6556076
cr
nerdai acb279c
cr
nerdai 7df26eb
cr
nerdai e3a86d6
cr
nerdai b49e4e0
cr
nerdai bb63f1a
cr
nerdai 2032e14
cr
nerdai 71c41bf
cr
nerdai cefdd82
cr
nerdai 8a6ac3e
cr
nerdai 496d14b
cr
nerdai eeb9096
name change to PersonalizedMode
nerdai 58c9244
cr
nerdai e124499
cr
nerdai 137c9c6
cr
nerdai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from enum import Enum | ||
|
||
from fl4health.clients.basic_client import BasicClient | ||
from fl4health.mixins.personalized.ditto import DittoPersonalizedMixin, DittoPersonalizedProtocol | ||
|
||
|
||
class PersonalizedMode(Enum): | ||
DITTO = "ditto" | ||
|
||
|
||
PersonalizedMixinRegistry = {PersonalizedMode.DITTO: DittoPersonalizedMixin} | ||
|
||
|
||
def make_it_personal(client_base_type: type[BasicClient], mode: PersonalizedMode) -> type[BasicClient]: | ||
"""A mixed class factory for converting basic clients to personalized versions.""" | ||
if mode == PersonalizedMode.DITTO: | ||
|
||
return type( | ||
f"Ditto{client_base_type.__name__}", | ||
( | ||
PersonalizedMixinRegistry[mode], | ||
client_base_type, | ||
), | ||
{ | ||
# Special flag to bypass validation | ||
"_dynamically_created": True | ||
}, | ||
) | ||
else: | ||
raise ValueError("Unrecognized personalized mode.") | ||
|
||
|
||
__all__ = [ | ||
"DittoPersonalizedMixin", | ||
"DittoPersonalizedProtocol", | ||
"PersonalizedMode", | ||
"PersonalizedMixinRegistry", | ||
"make_it_personal", | ||
] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it normal to put such things in the
__init__.py
? I'm not sure of the co, but this feels kind of weird.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.
That is, why put this in here instead of something like a utility file or something else?
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, I have seen this adopted in practice, by engineers more experienced than me; and in other libraries. That is, I am treating this as a factory/registry, which I have seen be put in these module-level init files. I think so long as we're not baking in the actual logic here, then we're okay... but i'm also not married to this. If you really prefer to outsource this to some other module, say
factory
orregistry
, then I'm not picky. :)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 main reason I think that these factories/registries are created here is because often all of the classes you need are already being re-imported (i.e., and being exposed in the public api "all")
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.
That's fair. I honestly have no idea what best practices apply to
__init__.py
files. Seems kind of wild west ha.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.
Yea me too... I just go with things I have seen before in libraries i've worked in, or have read source code in, and how past teammates have used
__init__.py
.