Skip to content
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

Merged
merged 14 commits into from
Nov 14, 2023

Conversation

FirdausChoudhury
Copy link
Collaborator

Implemented set_config and added test cases.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Collaborator Author

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 Show resolved Hide resolved
@@ -12,17 +12,27 @@
},
Copy link
Owner

@BirkhoffG BirkhoffG Nov 10, 2023

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed

@@ -12,17 +12,27 @@
},
Copy link
Owner

@BirkhoffG BirkhoffG Nov 10, 2023

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted the for loop

@@ -12,17 +12,27 @@
},
Copy link
Owner

@BirkhoffG BirkhoffG Nov 10, 2023

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

Copy link
Owner

@BirkhoffG BirkhoffG Nov 10, 2023

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

Copy link
Collaborator Author

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.

Copy link
Owner

@BirkhoffG BirkhoffG left a 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.

@BirkhoffG
Copy link
Owner

For a case where no arguments are passed into set_config, do we want it to return default values or raise an error?

I think if you pass nothing, you should not change main_config (not simply returning default values).

@@ -12,17 +12,27 @@
},
Copy link
Owner

@BirkhoffG BirkhoffG Nov 10, 2023

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

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):
Copy link
Owner

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)

Copy link
Owner

@BirkhoffG BirkhoffG left a 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(
Copy link
Owner

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.

@BirkhoffG BirkhoffG linked an issue Nov 14, 2023 that may be closed by this pull request
@BirkhoffG BirkhoffG merged commit 3def34b into BirkhoffG:18-implement-set_config Nov 14, 2023
4 checks passed
BirkhoffG added a commit that referenced this pull request Nov 14, 2023
Imlemented set_config and added test cases (#20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement set_config
2 participants