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

feat(stateful): Add NativeModule to all backends with the implementation of a custom tensorflow.keras.Model subclass for the tensorflow backend to follow ivy.Module's API #27955

Merged
merged 3 commits into from
Jan 22, 2024

Conversation

hmahmood24
Copy link
Contributor

PR Description

Adds tensorflow.keras.Model stateful class that inherits directly from tf.keras.Model and also implements the front-facing API following ivy.Module. Also adds an additional call method to the frontend nn.Module class.

Related Issue

Closes #

Checklist

  • Did you add a function?
  • Did you add the tests?
  • Did you run your tests and are your tests passing?
  • Did pre-commit not fail on any check?
  • Did you follow the steps we provided?

Socials

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

PR Compliance Checks

Thank you for your Pull Request! We have run several checks on this pull request in order to make sure it's suitable for merging into this project. The results are listed in the following section.

Issue Reference

In order to be considered for merging, the pull request description must refer to a specific issue number. This is described in our contributing guide and our PR template.
This check is looking for a phrase similar to: "Fixes #XYZ" or "Resolves #XYZ" where XYZ is the issue number that this PR is meant to address.

Protected Branch

In order to be considered for merging, the pull request changes must not be implemented on the "main" branch. This is described in our Contributing Guide. We are closing this pull request and we would suggest that you implement your changes as described in our Contributing Guide and open a new pull request.

@hmahmood24
Copy link
Contributor Author

Hey @vedpatwardhan, could you take a look? I didn't remove some more attributes, properties, arguments which I think can be safely removed for our use case but for the time being this version of the class works. We can then revisit and remove any unneeded code from the file

@ivy-leaves ivy-leaves added the PyTorch Frontend Developing the PyTorch Frontend, checklist triggered by commenting add_frontend_checklist label Jan 18, 2024
@@ -1,3 +1,4 @@
from . import backends
Copy link
Contributor

Choose a reason for hiding this comment

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

The only concern here is that we'd import tensorflow on importing ivy, thus adding it as a dependency. Let's probably do something like create a submodule named module.py in all the backends and add the keras model implementation in the tensorflow backend. After that we can just add a NativeModule to all the backend __init__.py files so that based on the backend, that particular model would be contained in ivy.NativeModule. After that we can just do the same thing as we're doing now except for the namespace change
Apologies for the delayed review @hmahmood24, let me know what you think, thanks 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah didn't think of it from that perspective. Thanks for the suggestion! 👍🏼

…a custom Model class for the tensorflow backend NativeModule
@hmahmood24
Copy link
Contributor Author

@vedpatwardhan For the time being, I've kept the module.py sub-module in all the backends empty except for tensorflow. For all the other backends, the NativeModule points to the backend native modules e.g. for torch points to torch.nn.Module, for paddle points to paddle.nn.Layer and so on. Let me know if this makes sense? Thanks!

@hmahmood24 hmahmood24 changed the title feat(stateful): Add tensorflow.keras.Model stateful class to follow ivy.Module's API feat(stateful): Add NativeModule to all backends with the implementation of a custom NativeModule class for the tensorflow backend to follow ivy.Module's API Jan 21, 2024
@hmahmood24 hmahmood24 changed the title feat(stateful): Add NativeModule to all backends with the implementation of a custom NativeModule class for the tensorflow backend to follow ivy.Module's API feat(stateful): Add NativeModule to all backends with the implementation of a custom tensorflow.keras.Model subclass for the tensorflow backend to follow ivy.Module's API Jan 21, 2024
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.

@vedpatwardhan For the time being, I've kept the module.py sub-module in all the backends empty except for tensorflow. For all the other backends, the NativeModule points to the backend native modules e.g. for torch points to torch.nn.Module, for paddle points to paddle.nn.Layer and so on. Let me know if this makes sense? Thanks!

Yep sounds good, tbh even if we had set NativeModule as None for those backends it wouldn't be a problem but setting it as the native module of the framework by default sounds good! Feel free to merge the PR, thanks @hmahmood24 😄

@hmahmood24 hmahmood24 merged commit 90bedc1 into Transpile-AI:main Jan 22, 2024
406 of 421 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Paddle Paddle Backend PyTorch Frontend Developing the PyTorch Frontend, checklist triggered by commenting add_frontend_checklist
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants