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

Implement grouped convolutions #116

Merged

Conversation

purefunctor
Copy link
Contributor

Closes #114. This adds the groups_of parameter and an alternative implementation for forward that works on grouped convolutions. I had to conditionally define forward depending on the value of groups_of since I had trouble reconciling the implementation with groups_of=1

@purefunctor
Copy link
Contributor Author

TODO:

  • Implement for non-templated Conv1D
  • Implement for other backends

@jatinchowdhury18
Copy link
Owner

Nice! I haven't had time yet to go through the PR in detail, but at first glance, everything looks great! I wouldn't worry about the other backends just yet, and I'm happy to help with those implementation as well.

Copy link
Owner

@jatinchowdhury18 jatinchowdhury18 left a comment

Choose a reason for hiding this comment

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

Looking good! I did a little bit of work on another branch mostly just rebasing from main and messing with the test code a little bit. I think this weekend I can go through and work more on the other implementations.

RTNeural/conv1d/conv1d.h Outdated Show resolved Hide resolved
python/conv1d_torch_group.py Outdated Show resolved Hide resolved
jsonStream >> modelJson;

RTNeural::ModelT<T, 6, 3, RTNeural::Conv1DT<T, 6, 3, 1, 1, 3, false>> model;
RTNeural::torch_helpers::loadConv1D<T>(modelJson, "", model.template get<0>());
Copy link
Owner

Choose a reason for hiding this comment

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

Do you know if TensorFlow also has a "groups" concept for their Conv1D layer? That might be a good thing to test for also, although we can add that in a future PR if it turns out to be complicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe so, and it's functionally the same as PyTorch's

Copy link
Owner

Choose a reason for hiding this comment

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

Okay cool! I can take a look at adding a test case on the Tensorflow side.

@purefunctor
Copy link
Contributor Author

I also pushed my attempt at implementing microTCN 9d6545c but inference isn't correct yet. Do you reckon there's something I'm missing?

This definition makes it so that an apparent off-by-one error is
fixed by instead making the `start` index be the difference between
the target and the current length.

For example, given a tensor with 1000 elements, and a target of 970,
the function would instead crop with `x[..., 30:]`, rather than the
previous behaviour of `x[..., 29:999]`.

This seems to be more correct in that the previous behaviour takes
items from index 29 (inclusive) to index 999 (exclusive, so 998).

Meanwhile, the new behaviour makes it so that it's index 30 (inclusive)
until the end, which is the index 999.
@codecov-commenter
Copy link

codecov-commenter commented Nov 22, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (37fde44) 95.64% compared to head (7aebcac) 95.70%.
Report is 2 commits behind head on main.

Files Patch % Lines
RTNeural/model_loader.h 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #116      +/-   ##
==========================================
+ Coverage   95.64%   95.70%   +0.06%     
==========================================
  Files          58       58              
  Lines        3860     3891      +31     
==========================================
+ Hits         3692     3724      +32     
+ Misses        168      167       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jatinchowdhury18
Copy link
Owner

Nice work on getting the TCN working!

I think I have the necessary changes for the non-templated STL implementation and other backends more or less ready to go, but I wanted to ask what you think is the best way to get those changes merged into your branch. I could continue working on this branch, but it's probably a bit out of date since your latest changes on this branch.

By the way, I think I'm also going to re-write the unit tests in Catch2 or something this weekend, so hopefully we can get this PR merged-in before then :).

@jatinchowdhury18
Copy link
Owner

Sorry, just getting back to this today. On my branch I've added:

  • A TensorFlow test case
  • STL non-templated implementation
  • XSIMD implementations (template and non-templated)

Hopefully I can finish up the Eigen implementations tonight or tomorrow, and then we should be good to merge! I'd like to get the MicroTCN test case working for all the backends as well, but I'm okay with doing that after we merge this PR depending on when I get around to it.

@jatinchowdhury18
Copy link
Owner

Update: The Eigen implementation is now working as well, so the only work left to do should be some documentation and to finish up the MicroTCN test. That said, I think I'm going to wait until #119 is merged before merging these changes, just to avoid some tricky merge conflicts.

@purefunctor
Copy link
Contributor Author

I can merge your branch into this one so it's easier to do the merge into main 👍🏼

purefunctor and others added 24 commits November 28, 2023 13:28
This definition makes it so that an apparent off-by-one error is
fixed by instead making the `start` index be the difference between
the target and the current length.

For example, given a tensor with 1000 elements, and a target of 970,
the function would instead crop with `x[..., 30:]`, rather than the
previous behaviour of `x[..., 29:999]`.

This seems to be more correct in that the previous behaviour takes
items from index 29 (inclusive) to index 999 (exclusive, so 998).

Meanwhile, the new behaviour makes it so that it's index 30 (inclusive)
until the end, which is the index 999.
@jatinchowdhury18
Copy link
Owner

Alrighty! The other branch should be ready to merge, if you'd like to pull those changes into this PR. Also feel free to add yourself to the contributors list if you'd like!

@jatinchowdhury18
Copy link
Owner

Looks like everything is good to go except for formatting. I'll go ahead and merge, and I can take care of formatting later.

Thanks again for your work on this!

@jatinchowdhury18 jatinchowdhury18 merged commit 1e81449 into jatinchowdhury18:main Nov 29, 2023
20 of 21 checks passed
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.

groups support for Conv1D?
3 participants