Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a dropout_mask method for ComplexF64 array types #1572

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion src/layers/normalise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ function dropout_mask(x, p; dims=:)
return y
end

function dropout_mask(x::Array{Complex{Float64}}, p; dims=:)
Copy link
Member

Choose a reason for hiding this comment

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

Seems a bit strict. Maybe we want to generalise the existing method? It should work the same for single precision.

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 agree, I just didn't want to introduce changes that would affect any other types

Copy link
Contributor Author

@ShoofLLC ShoofLLC Apr 10, 2021

Choose a reason for hiding this comment

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

I added a test with a complex array as an input, I could also just modify dropout_mask to always use a Float type when calling similar:

Modifying the dropout_mask function itself to always have a float32 type when calling similar:
function dropout_mask(x, p; dims=:) y = rand!(similar(x, Float32, _dropout_shape(x, dims))) y .= _dropout_kernel.(y, p, 1 - p) return y end

would make dropout work for any input type, currently using dropout for Int inputs would fail with an inexact error, but I didn't want to modify the main method just for this use-case.

This might actually save some memory because if a network uses double-precision the rand would be double as well, which is not really needed just for comparison with p.

y = rand!(similar(x, Float64, _dropout_shape(x, dims)))
y .= _dropout_kernel.(y, p, 1 - p)
return y
end

"""
Dropout(p; dims=:)

Expand Down Expand Up @@ -457,4 +463,4 @@ scale parameters, `false` otherwise.

See [`BatchNorm`](@ref), [`InstanceNorm`](@ref), [`GroupNorm`](@ref), and [`LayerNorm`](@ref).
"""
hasaffine(l::Union{BatchNorm, InstanceNorm, LayerNorm, GroupNorm}) = l.affine
hasaffine(l::Union{BatchNorm, InstanceNorm, LayerNorm, GroupNorm}) = l.affine