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

Add support for flattening to the pytorch parser #852

Merged
merged 5 commits into from
Aug 22, 2023

Conversation

JanFSchulte
Copy link
Contributor

Currently, Flatten layers are skipped in the pytorch parser. Additionally, this operation is not flagged as unsupported, so the model will parse, but exhibit incorrect behavior. This PR adds support for these layers by adding them to the parser. The optimizer pass that converts the operations to channels_last for pytorch models is adapted to transpose the input to the flattener so the output elements are in the correct order.

Type of change

For a new feature or function, please create an issue first to discuss it
with us before submitting a pull request.

Note: Please delete options that are not relevant.

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change which adds functionality)

Tests

Verified that a simple model with a Conv2D and a Flatten operation give correct results, both for the torch.nn.Flatten and torch.flatten() interfaces to this operation in pytorch. Pytest has been added to verify this.

Checklist

  • I have read the guidelines for contributing.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have installed and run pre-commit on the files I edited or added.
  • I have added tests that prove my fix is effective or that my feature works.

@vloncar vloncar added the please test Trigger testing by creating local PR branch label Aug 21, 2023
@vloncar
Copy link
Contributor

vloncar commented Aug 21, 2023

LGTM. I also added support for fully parsing start_dim and end_dim of nn.Flatten to our Reshape. Once tests pass, I'll merge this if there are no objections in the meantime.

@vloncar vloncar merged commit 8c327d4 into fastmachinelearning:main Aug 22, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please test Trigger testing by creating local PR branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants