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

remove DepthwiseConv type in favor of Conv #1921

Merged
merged 2 commits into from
Apr 2, 2022
Merged

remove DepthwiseConv type in favor of Conv #1921

merged 2 commits into from
Apr 2, 2022

Conversation

CarloLucibello
Copy link
Member

@CarloLucibello CarloLucibello commented Mar 31, 2022

Implement @mcabbott's comment

Also adds the assertion

  @assert cin % groups == 0 "Input channel dimension must be divisible by groups."
  @assert cout % groups == 0 "Output channel dimension must be divisible by groups."

for standard convolutions.

Close #1667, close #459

@codecov-commenter
Copy link

Codecov Report

Merging #1921 (cab5f26) into master (57beb23) will increase coverage by 0.22%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1921      +/-   ##
==========================================
+ Coverage   86.43%   86.66%   +0.22%     
==========================================
  Files          18       18              
  Lines        1430     1417      -13     
==========================================
- Hits         1236     1228       -8     
+ Misses        194      189       -5     
Impacted Files Coverage Δ
src/layers/show.jl 72.72% <ø> (ø)
src/outputsize.jl 84.21% <ø> (ø)
src/utils.jl 95.30% <ø> (ø)
src/layers/conv.jl 81.76% <100.00%> (+1.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 57beb23...cab5f26. Read the comment docs.

@CarloLucibello
Copy link
Member Author

ready for review/merge

@CarloLucibello CarloLucibello mentioned this pull request Apr 1, 2022
@mcabbott
Copy link
Member

mcabbott commented Apr 1, 2022

Should what's left move to deprecations.jl too?

@CarloLucibello
Copy link
Member Author

I think it is good to have a convenience constructor like that, helps you understand what a depthwise convolution is

@ToucheSir
Copy link
Member

Would you mind running some microbenchmarks on CPU pre- and post-PR? If there's basically no difference between the two, let's merge asap :)

@mcabbott
Copy link
Member

mcabbott commented Apr 2, 2022

Xref FluxML/NNlib.jl#395 perhaps. The present code has 3 layers of multi-threading, not sure how carefully it was ever benchmarked.

@CarloLucibello
Copy link
Member Author

Performance here seems slightly better. We should remove the specialized depthwiseconv from NNlib.

This PR

julia> using Flux, BenchmarkTools

julia> x = randn(Float32, 128, 128, 32, 32);

julia> dconv = DepthwiseConv((3,3), 32 => 64)
Conv((3, 3), 32 => 64, groups=32)  # 640 parameters

julia> Threads.nthreads()
1

julia> @btime $dconv($x);
  169.259 ms (320 allocations: 265.55 MiB)
julia> Threads.nthreads()
4

julia> @btime $dconv($x);
  96.917 ms (366 allocations: 317.88 MiB)

On Master

julia> using Flux, BenchmarkTools

julia> x = randn(Float32, 128, 128, 32, 32);

julia> dconv = DepthwiseConv((3,3), 32 => 64)
DepthwiseConv((3, 3), 32 => 64)  # 640 parameters

julia> Threads.nthreads()
1

julia> @btime $dconv($x);
  180.530 ms (22 allocations: 265.51 MiB)
julia> Threads.nthreads()
4

julia> @btime $dconv($x);
  101.642 ms (37 allocations: 317.83 MiB)

Copy link
Member

@ToucheSir ToucheSir left a comment

Choose a reason for hiding this comment

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

Great, we can move the perf discussion (mainly figuring out where that extra memory usage comes from) to NNlib.

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.

deprecate DepthwiseConv once we have groups in standard conv DepthwiseConv does not run on GPU
4 participants