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

ModularTorchModel #3242

Merged
merged 23 commits into from
Feb 22, 2023
Merged

ModularTorchModel #3242

merged 23 commits into from
Feb 22, 2023

Conversation

tonydavis629
Copy link
Collaborator

@tonydavis629 tonydavis629 commented Feb 15, 2023

Pull Request Template

Description

This PR adds in a new abstract model, ModularTorchModel. The premise of ModularTorchModel is that we may want to take components from different models and combine them, or modify a model to work with a different task. This is useful for transfer learning where we may want to take an embedding from a pretrained model, or modify a model's prediction head to work with a pretraining task.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • In this case, we recommend to discuss your modification on GitHub issues before creating the PR
  • Documentations (modification for documents)

Checklist

  • My code follows the style guidelines of this project
    • Run yapf -i <modified file> and check no errors (yapf version must be 0.32.0)
    • Run mypy -p deepchem and check no errors
    • Run flake8 <modified file> --count and check no errors
    • Run python -m doctest <modified file> and check no errors
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Copy link
Member

@rbharath rbharath left a comment

Choose a reason for hiding this comment

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

I think this is basically ready to merge once all tests look stable and my minor comment about the function name is fixed

self.model = self.build_model()
self.model.to(self.device)

def load_from_modular(self,
Copy link
Member

Choose a reason for hiding this comment

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

I think it may be better to just call this load_from_pretrained and disable the mypy complaint? Feels like introducing a new API is more confusing than a slight mismatch in the call structure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But we're still introducing a new API. We're just naming it the same as an old one.

@rbharath
Copy link
Member

It looks like some additional tests are failing as well. By comparison to #3241 which has 20 green, we only have 15 tests green suggesting there may be some breakages

@tonydavis629
Copy link
Collaborator Author

@rbharath I believe this is ready for a final review

Copy link
Member

@rbharath rbharath left a comment

Choose a reason for hiding this comment

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

Almost at the finish line I think. Just needs a unit test for unfreeze_components

raise NotImplementedError("Subclass must define the loss function")

def freeze_components(self, components: List[str]):
"""Freezes or unfreezes the parameters of the specified components.
Copy link
Member

Choose a reason for hiding this comment

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

Slight edit, "unfreezes" should no longer be in this docstring

self.model = self.build_model()
self.model.to(self.device)

def unfreeze_components(self, components: List[str]):
Copy link
Member

Choose a reason for hiding this comment

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

We should add a unit test for unfreeze_components

Copy link
Member

@rbharath rbharath left a comment

Choose a reason for hiding this comment

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

I think this all looks good. Only question we are at 22 passing and not 23. If that's transient I think we are good to merge

@tonydavis629 tonydavis629 merged commit a734136 into deepchem:master Feb 22, 2023
@tonydavis629 tonydavis629 deleted the modular branch March 30, 2023 14:21
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.

None yet

2 participants