Skip to content

Commit 75b42c3

Browse files
committed
fix CI on 1.6 and MacOS
1 parent d950245 commit 75b42c3

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/normalization.jl

+11-11
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ _apply_scale_bias(x, scale, bias) = x .* scale .+ bias
3939
4040
Shared code path for all built-in norm functions.
4141
42-
`μ` and `σ²` should be calculated on the fly using [`NNlib.norm_stats`](@ref),
43-
or extracted from an existing collection such as [`NNlib.RunningStats`](@ref).
42+
`μ` and `σ²` should be calculated on the fly using [`norm_stats`](@ref),
43+
or extracted from an existing collection such as [`RunningStats`](@ref).
4444
`bias` and `scale` are consistent with cuDNN and Flux.Scale.
4545
We opt for `scale` over `weight` to avoid confusion with dense layers.
4646
If the size of the statistics and affine parameters differ,
@@ -64,7 +64,7 @@ Contains running mean and variance estimates for stateful norm functions.
6464
If the parameters are mutable, they will be updated in-place.
6565
Otherwise, they will be replaced wholesale.
6666
67-
See also [`NNlib.update_running_stats!`](@ref).
67+
See also [`update_running_stats!`](@ref).
6868
"""
6969
mutable struct RunningStats{M <: AbstractArray, V <: AbstractArray, MT <: Real}
7070
mean::M
@@ -114,10 +114,10 @@ end
114114
reduce_dims) where {N}
115115
116116
Performs a moving average update for layers with tracked statistics.
117-
`μ` and `σ²` are the sample mean and variance, most likely from [`NNlib.norm_stats`](@ref).
118-
`reduce_dims` should also match the `dims` argument of [`NNlib.norm_stats`](@ref).
117+
`μ` and `σ²` are the sample mean and variance, most likely from [`norm_stats`](@ref).
118+
`reduce_dims` should also match the `dims` argument of [`norm_stats`](@ref).
119119
120-
See also [`NNlib.RunningStats`](@ref).
120+
See also [`RunningStats`](@ref).
121121
"""
122122
function update_running_stats!(stats::RunningStats, x, μ, σ², reduce_dims::Dims)
123123
V = eltype(σ²)
@@ -153,7 +153,7 @@ Normalizes `x` along the first `S` dimensions.
153153
154154
For an additional learned affine transform, provide a `S`-dimensional `scale` and `bias`.
155155
156-
See also [`NNlib.batchnorm`](@ref), [`NNlib.instancenorm`](@ref), and [`NNlib.groupnorm`](@ref).
156+
See also [`batchnorm`](@ref), [`instancenorm`](@ref), and [`groupnorm`](@ref).
157157
158158
# Examples
159159
@@ -190,14 +190,14 @@ Functional [Batch Normalization](https://arxiv.org/abs/1502.03167) operation.
190190
Normalizes `x` along each ``D_1×...×D_{N-2}×1×D_N`` input slice,
191191
where `N-1` is the "channel" (or "feature", for 2D inputs) dimension.
192192
193-
Provide a [`NNlib.RunningStats`](@ref) to fix a estimated mean and variance.
193+
Provide a [`RunningStats`](@ref) to fix a estimated mean and variance.
194194
`batchnorm` will renormalize the input using these statistics during inference,
195195
and update them using batch-level statistics when training.
196196
To override this behaviour, manually set a value for `training`.
197197
198198
If specified, `scale` and `bias` will be applied as an additional learned affine transform.
199199
200-
See also [`NNlib.layernorm`](@ref), [`NNlib.instancenorm`](@ref), and [`NNlib.groupnorm`](@ref).
200+
See also [`layernorm`](@ref), [`instancenorm`](@ref), and [`groupnorm`](@ref).
201201
"""
202202
function batchnorm(x::AbstractArray{<:Any, N},
203203
running_stats::Union{RunningStats, Nothing} = nothing,
@@ -232,7 +232,7 @@ To override this behaviour, manually set a value for `training`.
232232
233233
If specified, `scale` and `bias` will be applied as an additional learned affine transform.
234234
235-
See also [`NNlib.layernorm`](@ref), [`NNlib.batchnorm`](@ref), and [`NNlib.groupnorm`](@ref).
235+
See also [`layernorm`](@ref), [`batchnorm`](@ref), and [`groupnorm`](@ref).
236236
"""
237237
function instancenorm(x::AbstractArray{<:Any, N},
238238
running_stats::Union{RunningStats, Nothing} = nothing,
@@ -266,7 +266,7 @@ The number of channels must be an integer multiple of the number of groups.
266266
267267
If specified, `scale` and `bias` will be applied as an additional learned affine transform.
268268
269-
See also [`NNlib.layernorm`](@ref), [`NNlib.batchnorm`](@ref), and [`NNlib.instancenorm`](@ref).
269+
See also [`layernorm`](@ref), [`batchnorm`](@ref), and [`instancenorm`](@ref).
270270
271271
# Examples
272272

test/normalization.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ end
3535

3636
# Group/InstanceNorm dimensions
3737
let W = 128, C = 2, N = 2, shape = (W, W, 1, 1)
38-
x = [randn_sample(shape, 1, 1);;; randn_sample(shape, 2, 2);;;;
39-
randn_sample(shape, 3, 3);;; randn_sample(shape, 4, 4)]
38+
# Tile to W x W x 2 x 2
39+
x = cat(cat(randn_sample(shape, 1, 1), randn_sample(shape, 2, 2); dims = 3),
40+
cat(randn_sample(shape, 3, 3), randn_sample(shape, 4, 4); dims = 3);
41+
dims = 4)
4042
μ, σ² = NNlib.norm_stats(x, (1, 2))
4143
@test vec(μ)1:(C * N) rtol=0.05
4244
@test vec(σ²)abs2.(1:(C * N)) rtol=0.05
@@ -60,7 +62,7 @@ end
6062
(running_stats, true, y_ns, y_ns, dx_ns),
6163
(running_stats, false, meanvar, meanvar, NoTangent()),
6264
]
63-
@test NNlib.maybe_norm_stats(stats, x, dims, !training) == y
65+
@test NNlib.maybe_norm_stats(stats, x, dims, !training)y rtol=1e-5
6466
ŷ, back = rrule(NNlib.maybe_norm_stats, stats, x, dims, !training)
6567
@test== y_ad
6668
@test back(meanvar) == (NoTangent(), NoTangent(), dx, NoTangent(), NoTangent())
@@ -170,8 +172,7 @@ end
170172
@testset for use_stats in (true, false)
171173
stats = use_stats ? NNlib.RunningStats(zeros(2), ones(2), 0.1) : nothing
172174
y, back = Zygote.pullback(NNlib.instancenorm, x, stats, scale, bias, 1e-5)
173-
@test y[-1.22474 -1.22474; 0.0 0.0; 1.22474 1.22474;;;
174-
-1.22474 -1.22474; 0.0 0.0; 1.22474 1.22474] rtol=1e-5
175+
@test yrepeat([-1.22474, 0.0, 1.22474], 1, 2, 2) rtol=1e-5
175176

176177
expected_mean, expected_var = [0.5, 0.8], [1.0, 1.0]
177178
if use_stats
@@ -197,8 +198,7 @@ end
197198
end
198199

199200
dx, dstats, dscale, dbias, _ = back(fill!(similar(y), 1))
200-
@test dx[3.6742 3.6742; 1.22474 1.22474; -1.22474 -1.22474;;;
201-
3.6742 3.6742; 1.22474 1.22474; -1.22474 -1.22474] rtol=1e-5
201+
@test dxrepeat([3.6742, 1.22474, -1.22474], 1, 2, 2) rtol=1e-5
202202
@test dscale == zeros(2)
203203
@test dbias == fill(6.0, 2)
204204
@test dstats === nothing

0 commit comments

Comments
 (0)