Skip to content

Commit d022b9f

Browse files
authored
Remove greek-letter keyword arguments (#2139)
* rm greek letter keywords * step 2, with _greek_ascii_depwarn * also for normalisation layers * move _greek_ascii_depwarn * wording
1 parent 7e329f3 commit d022b9f

File tree

6 files changed

+94
-58
lines changed

6 files changed

+94
-58
lines changed

src/Flux.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ include("loading.jl")
7070
include("outputsize.jl")
7171
export @autosize
7272

73+
include("deprecations.jl")
74+
7375
include("losses/Losses.jl")
7476
using .Losses
7577

76-
include("deprecations.jl")
77-
7878
include("cuda/cuda.jl")
7979

8080
end # module

src/deprecations.jl

+11
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ function trainmode!(m, active::Bool)
203203
testmode!(m, !active)
204204
end
205205

206+
# Greek-letter keywords deprecated in Flux 0.13
207+
# Arguments (old => new, :function, "β" => "beta")
208+
function _greek_ascii_depwarn(βbeta::Pair, func = :loss, names = "" => "")
209+
Base.depwarn("""function $func no longer accepts greek-letter keyword $(names.first)
210+
please use ascii $(names.second) instead""", func)
211+
βbeta.first
212+
end
213+
_greek_ascii_depwarn(βbeta::Pair{Nothing}, _...) = βbeta.second
214+
215+
ChainRulesCore.@non_differentiable _greek_ascii_depwarn(::Any...)
216+
206217

207218
# v0.14 deprecations
208219

src/layers/normalise.jl

+24-17
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,12 @@ testmode!(m::AlphaDropout, mode=true) =
152152
(m.active = isnothing(_tidy_active(mode)) ? nothing : !mode; m)
153153

154154
"""
155-
LayerNorm(size..., λ=identity; affine=true, ϵ=1fe-5)
155+
LayerNorm(size..., λ=identity; affine=true, eps=1f-5)
156156
157157
A [normalisation layer](https://arxiv.org/abs/1607.06450) designed to be
158158
used with recurrent hidden states.
159159
The argument `size` should be an integer or a tuple of integers.
160+
160161
In the forward pass, the layer normalises the mean and standard
161162
deviation of the input, then applies the elementwise activation `λ`.
162163
The input is normalised along the first `length(size)` dimensions
@@ -190,9 +191,10 @@ struct LayerNorm{F,D,T,N}
190191
affine::Bool
191192
end
192193

193-
function LayerNorm(size::Tuple{Vararg{Int}}, λ=identity; affine::Bool=true, ϵ::Real=1f-5)
194+
function LayerNorm(size::Tuple{Vararg{Int}}, λ=identity; affine::Bool=true, eps::Real=1f-5, ϵ=nothing)
195+
ε = _greek_ascii_depwarn=> eps, :LayerNorm, "ϵ" => "eps")
194196
diag = affine ? Scale(size..., λ) : λ!=identity ? Base.Fix1(broadcast, λ) : identity
195-
return LayerNorm(λ, diag, ϵ, size, affine)
197+
return LayerNorm(λ, diag, ε, size, affine)
196198
end
197199
LayerNorm(size::Integer...; kw...) = LayerNorm(Int.(size); kw...)
198200
LayerNorm(size_act...; kw...) = LayerNorm(Int.(size_act[1:end-1]), size_act[end]; kw...)
@@ -269,7 +271,7 @@ ChainRulesCore.@non_differentiable _track_stats!(::Any...)
269271
BatchNorm(channels::Integer, λ=identity;
270272
initβ=zeros32, initγ=ones32,
271273
affine=true, track_stats=true, active=nothing,
272-
ϵ=1f-5, momentum= 0.1f0)
274+
eps=1f-5, momentum= 0.1f0)
273275
274276
[Batch Normalization](https://arxiv.org/abs/1502.03167) layer.
275277
`channels` should be the size of the channel dimension in your data (see below).
@@ -321,16 +323,18 @@ end
321323

322324
function BatchNorm(chs::Int, λ=identity;
323325
initβ=zeros32, initγ=ones32,
324-
affine=true, track_stats=true, active::Union{Bool,Nothing}=nothing,
325-
ϵ=1f-5, momentum=0.1f0)
326+
affine::Bool=true, track_stats::Bool=true, active::Union{Bool,Nothing}=nothing,
327+
eps::Real=1f-5, momentum::Real=0.1f0, ϵ=nothing)
328+
329+
ε = _greek_ascii_depwarn=> eps, :BatchNorm, "ϵ" => "eps")
326330

327331
β = affine ? initβ(chs) : nothing
328332
γ = affine ? initγ(chs) : nothing
329333
μ = track_stats ? zeros32(chs) : nothing
330334
σ² = track_stats ? ones32(chs) : nothing
331335

332336
return BatchNorm(λ, β, γ,
333-
μ, σ², ϵ, momentum,
337+
μ, σ², ε, momentum,
334338
affine, track_stats,
335339
active, chs)
336340
end
@@ -361,7 +365,7 @@ end
361365
InstanceNorm(channels::Integer, λ=identity;
362366
initβ=zeros32, initγ=ones32,
363367
affine=false, track_stats=false,
364-
ϵ=1f-5, momentum=0.1f0)
368+
eps=1f-5, momentum=0.1f0)
365369
366370
[Instance Normalization](https://arxiv.org/abs/1607.08022) layer.
367371
`channels` should be the size of the channel dimension in your data (see below).
@@ -411,16 +415,18 @@ end
411415

412416
function InstanceNorm(chs::Int, λ=identity;
413417
initβ=zeros32, initγ=ones32,
414-
affine=false, track_stats=false, active::Union{Bool,Nothing}=nothing,
415-
ϵ=1f-5, momentum=0.1f0)
418+
affine::Bool=false, track_stats::Bool=false, active::Union{Bool,Nothing}=nothing,
419+
eps::Real=1f-5, momentum::Real=0.1f0, ϵ=nothing)
420+
421+
ε = _greek_ascii_depwarn=> eps, :InstanceNorm, "ϵ" => "eps")
416422

417423
β = affine ? initβ(chs) : nothing
418424
γ = affine ? initγ(chs) : nothing
419425
μ = track_stats ? zeros32(chs) : nothing
420426
σ² = track_stats ? ones32(chs) : nothing
421427

422428
return InstanceNorm(λ, β, γ,
423-
μ, σ², ϵ, momentum,
429+
μ, σ², ε, momentum,
424430
affine, track_stats,
425431
active, chs)
426432
end
@@ -450,7 +456,7 @@ end
450456
GroupNorm(channels::Integer, G::Integer, λ=identity;
451457
initβ=zeros32, initγ=ones32,
452458
affine=true, track_stats=false,
453-
ϵ=1f-5, momentum=0.1f0)
459+
eps=1f-5, momentum=0.1f0)
454460
455461
[Group Normalization](https://arxiv.org/abs/1803.08494) layer.
456462
@@ -508,12 +514,13 @@ trainable(gn::GroupNorm) = hasaffine(gn) ? (β = gn.β, γ = gn.γ) : (;)
508514

509515
function GroupNorm(chs::Int, G::Int, λ=identity;
510516
initβ=zeros32, initγ=ones32,
511-
affine=true, track_stats=false, active::Union{Bool,Nothing}=nothing,
512-
ϵ=1f-5, momentum=0.1f0)
517+
affine::Bool=true, track_stats::Bool=false, active::Union{Bool,Nothing}=nothing,
518+
eps::Real=1f-5, momentum::Real=0.1f0, ϵ=nothing)
513519

514-
if track_stats
520+
if track_stats
515521
Base.depwarn("`track_stats=true` will be removed from GroupNorm in Flux 0.14. The default value is `track_stats=false`, which will work as before.", :GroupNorm)
516-
end
522+
end
523+
ε = _greek_ascii_depwarn=> eps, :GroupNorm, "ϵ" => "eps")
517524

518525
chs % G == 0 || error("The number of groups ($(G)) must divide the number of channels ($chs)")
519526

@@ -525,7 +532,7 @@ end
525532
return GroupNorm(G, λ,
526533
β, γ,
527534
μ, σ²,
528-
ϵ, momentum,
535+
ε, momentum,
529536
affine, track_stats,
530537
active, chs)
531538
end

src/losses/Losses.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using Statistics
44
using Zygote
55
using Zygote: @adjoint
66
using ChainRulesCore
7-
using ..Flux: ofeltype, epseltype
7+
using ..Flux: ofeltype, epseltype, _greek_ascii_depwarn
88
using CUDA
99
using NNlib: logsoftmax, logσ, ctc_loss, ctc_alpha, ∇ctc_loss
1010
import Base.Broadcast: broadcasted

0 commit comments

Comments
 (0)