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

objax.variable.VarCollection.update fails when passing Dict[str, Any] #253

Open
alvarobartt opened this issue Dec 26, 2022 · 1 comment
Open

Comments

@alvarobartt
Copy link

alvarobartt commented Dec 26, 2022

Hi everyone! Thanks for the awesome work with objax and the JAX environment, and happy holidays!

I was playing around for objax for a bit, and realized that if you try to update the model.vars() which is a VarCollection using the VarCollection.update method overwriting the default dict.update method, if what you pass to the function is a Python dictionary and not a VarCollection it fails, as it's being cast into a Python list, and then we're trying to loop over the items of a list as if it was a Python dictionary, so it throws a ValueError: too many values to unpack (expected 2).

objax/objax/variable.py

Lines 311 to 318 in 53b391b

def update(self, other: Union['VarCollection', Iterable[Tuple[str, BaseVar]]]):
"""Overload dict.update method to catch potential conflicts during assignment."""
if not isinstance(other, self.__class__):
other = list(other)
else:
other = other.items()
conflicts = set()
for k, v in other:

Is this intended? Shouldn't VarCollection.update just loop over classes that allow .items()?

@alvarobartt
Copy link
Author

Hi @AlexeyKurakin (sorry for mentioning you here in case you're not actively working on this), can you confirm whether the expected behavior of .update is to also allow VarCollection, because according to the typing of the .update function it is, I can work on this issue as well as the referenced one if you want 😄 Thanks!

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

No branches or pull requests

1 participant