Skip to content

Commit 7088682

Browse files
authored
Remove greek-letter keyword from normalise (#2252)
* use _greek_ascii_depwarn in normalise * also a better example * change use in LayerNorm
1 parent d5a0643 commit 7088682

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/layers/normalise.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ function (a::LayerNorm)(x::AbstractArray)
208208
end
209209
end
210210
eps = convert(float(eltype(x)), a.ϵ) # avoids promotion for Float16 data, but should ε chage too?
211-
a.diag(normalise(x, dims=1:length(a.size), ϵ=eps))
211+
a.diag(normalise(x; dims=1:length(a.size), eps))
212212
end
213213

214214
function Base.show(io::IO, l::LayerNorm)

src/layers/stateless.jl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
11

22
"""
3-
normalise(x; dims=ndims(x), ϵ=1e-5)
3+
normalise(x; dims=ndims(x), eps=1e-5)
44
55
Normalise `x` to mean 0 and standard deviation 1 across the dimension(s) given by `dims`.
66
Per default, `dims` is the last dimension.
7-
`ϵ` is a small additive factor added to the denominator for numerical stability.
7+
`eps` is a small term added to the denominator for numerical stability.
88
99
# Examples
1010
```jldoctest
1111
julia> using Statistics
1212
13-
julia> x = [9, 10, 20, 60];
13+
julia> x = [90, 100, 110, 130, 70];
1414
15-
julia> y = Flux.normalise(x);
15+
julia> mean(x), std(x; corrected=false)
16+
(100.0, 20.0)
1617
17-
julia> isapprox(std(y), 1, atol=0.2) && std(y) != std(x)
18+
julia> y = Flux.normalise(x)
19+
5-element Vector{Float64}:
20+
-0.49999975000012503
21+
0.0
22+
0.49999975000012503
23+
1.499999250000375
24+
-1.499999250000375
25+
26+
julia> isapprox(std(y; corrected=false), 1, atol=1e-5)
1827
true
1928
20-
julia> x = rand(1:100, 10, 2);
29+
julia> x = rand(10:100, 10, 10);
2130
2231
julia> y = Flux.normalise(x, dims=1);
2332
24-
julia> isapprox(std(y, dims=1), ones(1, 2), atol=0.2) && std(y, dims=1) != std(x, dims=1)
33+
julia> isapprox(std(y; dims=1, corrected=false), ones(1, 10), atol=1e-5)
2534
true
2635
```
2736
"""
28-
@inline function normalise(x::AbstractArray; dims=ndims(x), ϵ=ofeltype(x, 1e-5))
37+
@inline function normalise(x::AbstractArray; dims=ndims(x), eps=ofeltype(x, 1e-5), ϵ=nothing)
38+
ε = _greek_ascii_depwarn=> eps, :InstanceNorm, "ϵ" => "eps")
2939
μ = mean(x, dims=dims)
3040
σ = std(x, dims=dims, mean=μ, corrected=false)
31-
return @. (x - μ) /+ ϵ)
41+
return @. (x - μ) /+ ε)
3242
end
3343

3444
"""

0 commit comments

Comments
 (0)