-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Improve ludwig feature dict #3904
base: master
Are you sure you want to change the base?
Improve ludwig feature dict #3904
Conversation
Unit Test Results 4 files - 2 4 suites - 2 2m 58s ⏱️ - 11m 42s For more details on these failures, see this check. Results for commit acfa198. ± Comparison against base commit 0a24d0a. This pull request skips 2 tests.
♻️ This comment has been updated with latest results. |
ludwig/models/llm.py
Outdated
@@ -65,13 +65,13 @@ def __iter__(self) -> None: | |||
return iter(self.obj.keys()) | |||
|
|||
def keys(self) -> List[str]: | |||
return self.obj.keys() | |||
return self.obj.key_list() |
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.
@dennisrall Do you think it might be simpler to retain the coding pattern of returning list(my_object.keys())
or list(my_object.items())
, etc., instead of introducing a special additional methods item_list()
and value_list()
? It seems to me that doing so will be consistent with other cases in these Ludwig modules as well as general Python collection patterns. Thank you.
@@ -157,7 +158,7 @@ def get_name_from_module_dict_key(key: str, feature_name_suffix_length: int = FE | |||
return name[:-feature_name_suffix_length] | |||
|
|||
|
|||
class LudwigFeatureDict(torch.nn.Module): | |||
class LudwigFeatureDict(torch.nn.Module, MutableMapping): |
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.
@dennisrall Thank you for incorporating my previous suggestion -- I think that part looks clean now. Thank you for the idea and the implementation!
For this one, I am not sure if the benefits due to adding the MutableMapping subclassing justify taking the risk brought about the multiple inheritance. Do the test cover all the eventualities that might happen with this change?
Thank you. /cc @justinxzhao @arnavgarg1 @Infernaught
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.
No problem, I was just playing around a bit.
I can't think of any problems about the multiple inheritance, but you know the code better than me😉
It is also possible to remove the MutableMapping
inheritance and implement the other methods by hand. But I think this way it is a bit cleaner, if it doesn't cause any problems...
|
||
|
||
@pytest.fixture | ||
def type_module() -> torch.nn.Module: |
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.
@dennisrall This fixture and the to_module()
one appear the same, and just instantiate the PyTorch
Module()
class. Without a docstring, it is a bit difficult to justify it having them. Thank you.
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.
Thanks for your feedback. I added a docstring for both fixtures and also for the hash
method of the LudwigFeatureDict
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.
Overall PR LGTM, thanks for the change @dennisrall.
I pushed up a couple of commits, largely around fixing the CI.
It appears we'll need to bump up integration tests CI to torch==2.1.0, which we're absolutely ok also since that's what our Docker images are using now.
LGTM can be merged as soon as possible |
Some minor improvements to the
LudwigFeatureDict
:__next__
methodinternal_key_to_original_name_map
dict as the values were never readMutableMapping
from thecollections.abc
→ get useful and more performant methods