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

Locally connected layer #201

Merged
merged 30 commits into from
Mar 14, 2025

Conversation

ricor07
Copy link
Collaborator

@ricor07 ricor07 commented Feb 13, 2025

Continuing milancurcic#2 (comment) on the right repository. Reshape_generalized works, locally_connected_1d still does not. This is, of course, still a draft. My final goal will be making the layer work and generalizing ALL the 1d-3d function which are horrible to see.

Edit: sorry, I mistakenly closed the other PR.

@ricor07
Copy link
Collaborator Author

ricor07 commented Feb 14, 2025

Hello, a tiny update: now, locally_connected_1d is a conv1d layer. Since layers that take a 2d array as input are not very supported in this repository, in the next days I'll provide an implementation which will make this work. Then, I'll add the passages which iwll transform the convolution in a locally_connected layer.

@OneAdder
Copy link
Collaborator

@ricor07 It seems, most of the problems with 2D will resolved with this: #198

@ricor07
Copy link
Collaborator Author

ricor07 commented Feb 15, 2025

Great. Tomorrow I'm going to try your implementation

@ricor07 ricor07 force-pushed the locally_connected_layer branch from f4c4412 to 9ae50ee Compare February 16, 2025 12:55
@ricor07 ricor07 self-assigned this Feb 16, 2025
@ricor07 ricor07 force-pushed the locally_connected_layer branch from ad592da to b5e7f74 Compare February 16, 2025 18:35
@ricor07
Copy link
Collaborator Author

ricor07 commented Feb 16, 2025

Hello, after the recent updates I think that my reshape_generalized ceased to work. For these reasons, I preferred to switch to a reshape2d implementation. Of course, after making this work the goal would be to create a unique reshape file. The cnn mnist 1d file, with the locally_connected_1d layer, does still not work but it is normal since I have not worked on its connection to layer and network yet. Tomorrow I will. Sorry for the delay but I had some difficulties.

I'd be glad if someone wants to have a look and apply some changes. It shouldn't be too complicated

@ricor07 ricor07 force-pushed the locally_connected_layer branch from 3a8cecc to eb4079d Compare February 17, 2025 15:08
@ricor07
Copy link
Collaborator Author

ricor07 commented Feb 23, 2025

Hello, sorry for not having given updates but I had been busy. I almost finished. I only have to fix one bug in cnn_network and then this draft will be ready for review, i think already tomorrow.

@ricor07 ricor07 marked this pull request as ready for review February 24, 2025 16:07
@ricor07 ricor07 requested review from milancurcic and jvdp1 February 24, 2025 16:07
Copy link
Collaborator

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Here are some suggestions.

real, intent(in) :: gradient(:,:)
! The `input` dummy argument is not used but nevertheless declared
! because the abstract type requires it.
self % gradient = pack(gradient, .true.)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the purpose of this?
Would the following not more eefficient?

Suggested change
self % gradient = pack(gradient, .true.)
real :: g_(:) => null()
g_(1:size(gradient)) => gradient
self % gradient = g_
nullify(g_)

pure module subroutine forward(self, input)
class(reshape2d_layer), intent(in out) :: self
real, intent(in) :: input(:)
self % output = reshape(input, self % output_shape)
Copy link
Collaborator

Choose a reason for hiding this comment

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

A pointer could be used here, instead of reshape to avoid a tmp copy of input

@OneAdder
Copy link
Collaborator

@ricor07 Great job! I really like it!

@ricor07
Copy link
Collaborator Author

ricor07 commented Feb 25, 2025

@OneAdder thank you for your review, I did the adjustments you suggested.

@ricor07
Copy link
Collaborator Author

ricor07 commented Feb 26, 2025

I tried to solve conflicts with main but i think i have to merge more accurately. Is that needed, since you only have to merge the branch?

@milancurcic
Copy link
Member

If there were conflicts of this branch with main, then they had to be reconciled by merging main into here. There don't seem to be merge conflict now.

@milancurcic
Copy link
Member

But, it does seem like the merge conflicts may not have been properly resolved because now there are compilation errors. You can still resolve them by hand, or if you want you can revert to the previous commit and I can help merge main here.

@ricor07 ricor07 force-pushed the locally_connected_layer branch from 78d26e4 to b69ba9a Compare February 26, 2025 16:23
@ricor07
Copy link
Collaborator Author

ricor07 commented Feb 26, 2025

Ok, solved. But I still get reminded that this branch has conflicts. Do i have to update main?

@milancurcic
Copy link
Member

No, main is protected so it can only be changed by merging a PR. Now we have to resolve conflicts in this branch. There are a few very small conflicts here: https://github.com/modern-fortran/neural-fortran/pull/201/conflicts. You can resolve them by hand, or I can resolve them later, it's not a big issue.

@ricor07
Copy link
Collaborator Author

ricor07 commented Feb 26, 2025

Choose the layout you prefer. Thank you

@milancurcic
Copy link
Member

Thank you for this PR, it's a great addition! I'll take a day or two more to review in more detail as it's so big. I'd also like to look whether it's feasible to hide conv1d/2d, maxpool1d/2d, and reshape2d/3d behind generic layer constructors conv, maxpool, and reshape, since the specific implementations depending on the input rank seem to be an internal detail. Do you think it would be a nicer UI to have generic names?

@ricor07
Copy link
Collaborator Author

ricor07 commented Mar 5, 2025

Yes, I do. In a few days I'll start implementing other stuff like averagepooling and i will also group those under generic names.

If you have time, I think i made a mistake with naming locally_connected_layer. I think that 1d does not need an underline before it. Could you fix this? Thanks

Copy link
Member

@milancurcic milancurcic left a comment

Choose a reason for hiding this comment

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

Thank you!

@milancurcic milancurcic merged commit 5cf14eb into modern-fortran:main Mar 14, 2025
4 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.

4 participants