-
Notifications
You must be signed in to change notification settings - Fork 1
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
Imlemented set_config and added test cases #20
Imlemented set_config and added test cases #20
Conversation
Implemented set_config and ran test cases
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
For a case where no arguments are passed into set_config, do we want it to return default values or raise an error? |
nbs/00_utils.ipynb
Outdated
@@ -12,17 +12,27 @@ | |||
}, |
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.
Line #15. if rng_reserve_size is not None:
Here, you are basically assiging values to config. Write it as a separate function so that we can reuse it for assigning global_seed
.
In addition, let's not check typing and value for now. It will raise error anyway. A better way of type checking is to refactor Config
class using pydantic. See DataModuleConfig as an example. I don't want you to refactor Config
in this PR.
Reply via ReviewNB
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.
Completed
nbs/00_utils.ipynb
Outdated
@@ -12,17 +12,27 @@ | |||
}, |
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.
Line #29. for k, v in kwargs.items():
Delete this entire for-loop. First, rng_reserve_size
and global_seed
will not appear in kwargs (python will prevent it at compile time). Second, passing kwargs
is mostly for backward compatibility. Say in the future version, we have other config attributes. We can run the code for the future version in the current version of library.
Reply via ReviewNB
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.
Deleted the for loop
nbs/00_utils.ipynb
Outdated
@@ -12,17 +12,27 @@ | |||
}, |
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.
Line #11. test_fail(set_config, kwargs={'rng_reserve_size': -1}, contains='must be non-negative')
Adjust test cases accordingly. Test cases before this line looks good.
Reply via ReviewNB
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.
You should probably change your fourth test cases. I think we shouldn't change the behavior of Config
if nothing is passed to set_config
.
So the test case should be
assert get_config().rng_reserve_size == 2 and get_config().global_seed == 234
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.
I have changed the implementation so that if a user passes no arguments to set config, then no change occurs and the previous values are still valid.
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.
Please address these comments. Also, before you commit, you should run nbdev_export
& nbdev_clean
everytime.
I think if you pass nothing, you should not change main_config (not simply returning default values). |
nbs/00_utils.ipynb
Outdated
@@ -12,17 +12,27 @@ | |||
}, |
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.
Line #8.
Write documentation for this function. See jax-relax - Contribute (birkhoffg.github.io)
Reply via ReviewNB
Set_config modified and arg_check() added
relax/utils.py
Outdated
:param kwargs: A dictionary of keyword arguments, where the keys are the config keys to set and the values are the new values for those keys. | ||
""" | ||
|
||
def arg_check(arg, arg_value, arg_min): |
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.
I would write the function as this:
def set_val(arg_name: str, arg_value: int, arg_min: int) -> None:
"""Checks the validity of the argument and returns the argument value."""
if arg_value is None or not hasattr(main_config, arg_name):
return
if not isinstance(arg_value, int):
raise TypeError(f"`{arg_name}` must be an integer, but got {type(arg_value).__name__}.")
if arg_value < arg_min:
raise ValueError(f"`{arg_name}` must be non-negative, but got {arg_value}.")
setattr(main_config, arg_name, arg_value)
set_val('rng_reserve_size', rng_reserve_size, 1)
set_val('global_seed', global_seed, 0)
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.
Please fix the indent issue. Looks good to me for the rest of changes.
) -> None: | ||
"""Sets the global configurations.""" | ||
|
||
def set_val( |
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.
Can you fix the indent for the arguments? It should be exactly one tab.
Imlemented set_config and added test cases (#20)
Implemented set_config and added test cases.