Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/lib/nnlib.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NNlib
import NNlib: softmax, ∇softmax, logsoftmax, ∇logsoftmax, conv, depthwiseconv, ∇conv_data, ∇depthwiseconv_data, maxpool, meanpool, σ, relu
import NNlib: softmax, ∇softmax, logsoftmax, ∇logsoftmax, conv, depthwiseconv, ∇conv_data, maxpool, meanpool, σ, relu

@adjoint function Base.Broadcast.broadcasted(::typeof(relu), x::Numeric)
relu.(x), Δ -> (nothing, ifelse.(x .> 0, Δ, zero.(x)))
Expand All @@ -14,8 +14,8 @@ end

@adjoint logsoftmax(xs) = logsoftmax(xs), Δ -> (∇logsoftmax(Δ, xs),)

@adjoint NNlib.DenseConvDims(args...; kwargs...) = NNlib.DenseConvDims(args...; kwargs...), _ -> nothing
@adjoint NNlib.DepthwiseConvDims(args...; kwargs...) = NNlib.DepthwiseConvDims(args...; kwargs...), _ -> nothing
@adjoint NNlib.ConvDims(args...; kwargs...) = NNlib.ConvDims(args...; kwargs...), _ -> nothing
# @adjoint NNlib.DepthwiseConvDims(args...; kwargs...) = NNlib.DepthwiseConvDims(args...; kwargs...), _ -> nothing
@adjoint NNlib.PoolDims(args...; kwargs...) = NNlib.PoolDims(args...; kwargs...), _ -> nothing

@adjoint conv(x, w, cdims; kw...) =
Expand All @@ -38,25 +38,25 @@ end
)
end

@adjoint depthwiseconv(x, w, cdims; kw...) =
depthwiseconv(x, w, cdims; kw...),
Δ -> begin
return (
NNlib.∇depthwiseconv_data(Δ, w, cdims; kw...),
NNlib.∇depthwiseconv_filter(x, Δ, cdims; kw...),
nothing,
)
end

@adjoint ∇depthwiseconv_data(x, w, cdims; kw...) =
∇depthwiseconv_data(x, w, cdims; kw...),
Δ -> begin
return (
NNlib.depthwiseconv(Δ, w, cdims; kw...),
NNlib.∇depthwiseconv_filter(Δ, x, cdims; kw...),
nothing,
)
end
# @adjoint depthwiseconv(x, w, cdims; kw...) =
# depthwiseconv(x, w, cdims; kw...),
# Δ -> begin
# return (
# NNlib.∇depthwiseconv_data(Δ, w, cdims; kw...),
# NNlib.∇depthwiseconv_filter(x, Δ, cdims; kw...),
# nothing,
# )
# end
#
# @adjoint ∇depthwiseconv_data(x, w, cdims; kw...) =
# ∇depthwiseconv_data(x, w, cdims; kw...),
# Δ -> begin
# return (
# NNlib.depthwiseconv(Δ, w, cdims; kw...),
# NNlib.∇depthwiseconv_filter(Δ, x, cdims; kw...),
# nothing,
# )
# end

@adjoint function maxpool(x, pdims; kw...)
y = maxpool(x, pdims; kw...)
Expand Down