-
Notifications
You must be signed in to change notification settings - Fork 79
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
Pydantic config #976
base: master
Are you sure you want to change the base?
Pydantic config #976
Conversation
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
@@ -253,7 +253,7 @@ def __init__(self, parameters) -> None: | |||
) | |||
|
|||
# all BatchNorm should be replaced with InstanceNorm for DP experiments | |||
if "differential_privacy" in parameters: | |||
if parameters["differential_privacy"] is not None: |
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.
Perhaps this check can be simpler, like this?
if parameters["differential_privacy"] is not None: | |
if parameters.get("differential_privacy"): |
Would that work?
GANDLF/utils/pydantic_config.py
Outdated
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 file badly needs documentation and comments.
Also, please take a look at the warnings from Codacy to see if any can be fixed: https://app.codacy.com/gh/mlcommons/GaNDLF/pull-requests/976/issues |
@sarthakpati, what do you think about the current approach? Right now, we only use the Parameters object for parsing, and convert to dictionary. For me, it is better to return a Parameters object with all the necessary parameters, and not a dictionary, |
Can you provide a brief pro/con reasoning as to why this would be the case? Especially since changing to a different data structure would require significant amount of changes throughout the code. |
I took a look at the source code, and it is required a lot of changes. So, it is not a good idea. I thought it might offer a better code experience, because Pydantic provides some extra features. |
Hey there! class LossFunction(BaseModel):
name: Literal["ce","cel" ... ] # (and so on for all the values available in the losses dict)
reduction: Optional[Literal["mean", "sum"]] = "mean" # here we allow to specify only those we support in our losses impl and also provide default values
some_other_param_our_losses_use : Optional[Literal["some_value_we_allow",...] = "some_default_value"
class Parameters:
....
loss_function: LossFunction Not sure if this will work if the loss is only a string without a name keyword, but you get the point.
And this way we have the parameters in the What you guys think? If I was unclear on something ping me, and we can discuss it further. Cheers! |
Thanks for the detailed explanation, @szmazurek! I updated your answer with some edits to make it clearer for myself. BTW, since you are working on the Lightning integration, this might be relevant since could perhaps be some overlap between that and this PR. Also, we should do 2 separate tags for them so that we have distinct points of references for the users. @benmalef: any thoughts on what Szymon has put forth? |
Fixes #758
Proposed Changes
Checklist
CONTRIBUTING
guide has been followed.typing
is used to provide type hints, including and not limited to usingOptional
if a variable has a pre-defined value).pip install
step is needed for PR to be functional), please ensure it is reflected in all the files that control the CI, namely: python-test.yml, and all docker files [1,2,3].logging
library is being used and noprint
statements are left.