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

Refactor MLP #3257

Merged
merged 16 commits into from
Mar 7, 2023
Merged

Refactor MLP #3257

merged 16 commits into from
Mar 7, 2023

Conversation

tonydavis629
Copy link
Collaborator

@tonydavis629 tonydavis629 commented Feb 24, 2023

Pull Request Template

Description

This PR allows the user to create an MLP with different sized hidden layers using a tuple, which was not previously possible. It also adds an activation on the final layer which would likely be expected. This change was made in an effort to unify the different feedforward network implementations in deepchem.

This PR also fixes a bug in the case of selecting to use 1 hidden layer. The current implementation produces a layer in the shape of [input_dim,hidden_dim], not the expected [input_dim,output_dim].

Type of change

Please check the option that is related to your PR.

  • 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

@tonydavis629 tonydavis629 changed the title MLP with 1 layer bug fix Refactor MLP Feb 24, 2023
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.

Have a couple of small stylistic comments here. Let's discuss offline? I'm not sure if this is standard style or not

self.model = nn.Sequential(*self.build_layers())
self.skip = nn.Linear(d_input, d_output) if skip_connection else None

def build_layers(self):
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a docstring here?

input = x
for layer in self.model:
x = layer(x)
if isinstance(layer, nn.Linear):
Copy link
Member

Choose a reason for hiding this comment

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

Maybe better to add the activations into the sequential model directly? Is this style off adding activations via a loop standard elsewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we do that, we will have to use the torch activations instead of the deepchem activations, since you cannot make a sequential model with anything but nn.modules.

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.

LGTM. Feel free to merge

@tonydavis629 tonydavis629 merged commit 8513f76 into deepchem:master Mar 7, 2023
@tonydavis629 tonydavis629 deleted the mlp_fix 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

3 participants