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

Stateful changes 2 #21246

Merged
merged 47 commits into from
Aug 17, 2023
Merged

Conversation

RickSanchezStoic
Copy link
Contributor

@RickSanchezStoic RickSanchezStoic commented Aug 3, 2023

Added buffer variables support for ivy Module. Methods such as _set_buffers,_get_buffers,_register_buffers,_buffer_tracker, _create_buffers added. Also _call was modified to account for the 'buffers' passed during the call.

RickSanchezStoic and others added 21 commits July 13, 2023 09:31
…ation on demand, modified container methods container identity methods to have build_callable and assert and assign arguments to build any callables as modules and assign them immediately
…s, rather than having it in the main module class
…d some corner cases in Module _init_var to account for absence and deleting it when done
…,_get_buffers,_register_buffers,_buffer_tracker, _create_buffers added. Alos _call was modified to account for the 'buffers' passed during call
@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2023

Thanks for contributing to Ivy! 😊👏
Here are some of the important points from our Contributing Guidelines 📝:
1. Feel free to ignore the run_tests (1), run_tests (2), … jobs, and only look at the display_test_results job. 👀 It contains the following two sections:
- Combined Test Results: This shows the results of all the ivy tests that ran on the PR. ✔️
- New Failures Introduced: This lists the tests that are passing on master, but fail on the PR Fork. Please try to make sure that there are no such tests. 💪
2. The lint / Check formatting / check-formatting tests check for the formatting of your code. 📜 If it fails, please check the exact error message in the logs and fix the same. ⚠️🔧
3. Finally, the test-docstrings / run-docstring-tests check for the changes made in docstrings of the functions. This may be skipped, as well. 📚
Happy coding! 🎉👨‍💻

@vedpatwardhan vedpatwardhan self-requested a review August 4, 2023 06:43
ivy/data_classes/container/base.py Show resolved Hide resolved
ivy/stateful/module.py Outdated Show resolved Hide resolved
else:
setattr(self, "buffers", {buffer})

def _register_buffers(self, var_name, value):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make this public, and remove variables.

Copy link
Contributor

Choose a reason for hiding this comment

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

could you please rename register_buffers to register_buffer, set_buffers to set_buffer and others and make the necessary ones public?

@vedpatwardhan vedpatwardhan self-requested a review August 11, 2023 06:52
Copy link
Contributor

@vedpatwardhan vedpatwardhan left a comment

Choose a reason for hiding this comment

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

Hey @RickSanchezStoic, just made a few suggestions, seems like we need to clean it up a bit. Thanks 😄

@@ -144,6 +145,9 @@ def __init__(
self._target = None
self._lazy_compiled = False
self._dynamic_backend = dynamic_backend
if hasattr(self, "_create_buffers"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we're still using _create_buffers and _buffer_tracker, could you please remove it as we'd only need to allow users to register buffers "on-spot"?


return
self.build(*args, dynamic_backend=dynamic_backend, **kwargs)
self.build(*args, dynamic_backend=dynamic_backend, buffers=buffers**kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax error, , to be added

Copy link
Contributor

Choose a reason for hiding this comment

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

.

Copy link
Contributor

Choose a reason for hiding this comment

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

this throws an error right?

wrapper.buffers_tracked = True
return wrapper

def _get_buffers(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why we need this method actually, given that we are already using _find_buffers while building, won't self.buffers be a container or arrays anyway?

else:
setattr(self, "buffers", {buffer})

def _register_buffers(self, var_name, value):
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please rename register_buffers to register_buffer, set_buffers to set_buffer and others and make the necessary ones public?

@vedpatwardhan vedpatwardhan self-requested a review August 14, 2023 06:03
ivy/stateful/module.py Outdated Show resolved Hide resolved
Copy link
Contributor

@vedpatwardhan vedpatwardhan left a comment

Choose a reason for hiding this comment

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

Hey @RickSanchezStoic, just requested a final few changes, thanks 😄

ivy/data_classes/container/base.py Show resolved Hide resolved

return
self.build(*args, dynamic_backend=dynamic_backend, **kwargs)
self.build(*args, dynamic_backend=dynamic_backend, buffers=buffers**kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

.

@@ -646,8 +699,9 @@ def build(
True for successfully built a module.
"""
self._dev = ivy.default(device, self._dev)
# build buffers if any
self._create_buffers()
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that ivy.Module._create_buffers has been removed, we should also remove this

@@ -798,9 +862,27 @@ def __getattribute__(self, name):
self._build_and_return_v(
self._args, dynamic_backend=self._dynamic_backend, **self._kwargs
)

if name == "buffers":
Copy link
Contributor

Choose a reason for hiding this comment

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

This if block is redundant right?

if name in self.buffers:
self.buffers[name] = value
return

Copy link
Contributor

Choose a reason for hiding this comment

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

extra blank line

Copy link
Contributor

@vedpatwardhan vedpatwardhan left a comment

Choose a reason for hiding this comment

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

Final couple of changes left from the previous review, thanks @RickSanchezStoic 😄

ivy/data_classes/container/base.py Show resolved Hide resolved

return
self.build(*args, dynamic_backend=dynamic_backend, **kwargs)
self.build(*args, dynamic_backend=dynamic_backend, buffers=buffers**kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

this throws an error right?

Copy link
Contributor

@vedpatwardhan vedpatwardhan left a comment

Choose a reason for hiding this comment

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

lgtm! Feel free to merge, thanks @RickSanchezStoic 😄

@RickSanchezStoic RickSanchezStoic merged commit f698db5 into ivy-llc:main Aug 17, 2023
236 of 265 checks passed
sushmanthreddy pushed a commit to sushmanthreddy/ivy that referenced this pull request Aug 17, 2023
Co-authored-by: Rishabh Kumar <[email protected]>

Adds buffer support to Module
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.

2 participants