Skip to content

Commit d950245

Browse files
committed
include in docs
1 parent 0ed9f7d commit d950245

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

docs/src/reference.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pad_zeros
6363

6464
## Convolution
6565

66-
`Flux`'s `Conv` and `CrossCor` layers use `NNlib.DenseConvDims` and `NNlib.conv` internally.
66+
`Flux`'s `Conv` and `CrossCor` layers use `NNlib.DenseConvDims` and `NNlib.conv` internally.
6767

6868
```@docs
6969
conv
@@ -75,6 +75,22 @@ unfold
7575
fold
7676
```
7777

78+
## Normalization
79+
80+
These roughly correspond to Flux's `*Norm` layers.
81+
<!-- `Flux`'s `*Norm` layers use `NNlib.*norm` and helper functionality such as `NNlib.RunningStats` internally. -->
82+
83+
```@docs
84+
NNlib.layernorm
85+
NNlib.batchnorm
86+
NNlib.instancenorm
87+
NNlib.groupnorm
88+
NNlib.norm_stats
89+
NNlib.norm_helper
90+
NNlib.RunningStats
91+
NNlib.update_running_stats!
92+
```
93+
7894
## Upsampling
7995

8096
`Flux`'s `Upsample` layer uses `NNlib.upsample_nearest`, `NNlib.upsample_bilinear`, and `NNlib.upsample_trilinear` as its backend. Additionally, `Flux`'s `PixelShuffle` layer uses `NNlib.pixel_shuffle` as its backend.

src/normalization.jl

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
44
Calculates sample mean and (uncorrected) variance of `x` along `dims`.
55
6-
- `dims=(1,...,N-2,N)` for BatchNorm
7-
- `dims=(1,...,N-2)` for InstanceNorm and GroupNorm
8-
- `dims=(1,...,S)` where S < N for LayerNorm/Flux.jl/stable/
6+
- `dims=(1,...,N-2,N)` for batchnorm
7+
- `dims=(1,...,N-2)` for instancenorm and groupnorm
8+
- `dims=(1,...,S)` where S < N for layernorm
99
1010
This is more efficient than calling `mean(x; dims)` and `var(x; dims)` separately,
1111
because it can share some computation across both.
@@ -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 [`norm_stats`](@ref),
43-
or extracted from an existing collection such as [`RunningStats`](@ref).
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).
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 [`update_running_stats!`](@ref).
67+
See also [`NNlib.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 [`norm_stats`](@ref).
118-
`reduce_dims` should also match the `dims` argument of [`norm_stats`](@ref).
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).
119119
120-
See also [`RunningStats`](@ref).
120+
See also [`NNlib.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 [`batchnorm`](@ref), [`instancenorm`](@ref), and [`groupnorm`](@ref).
156+
See also [`NNlib.batchnorm`](@ref), [`NNlib.instancenorm`](@ref), and [`NNlib.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 [`RunningStats`](@ref) to fix a estimated mean and variance.
193+
Provide a [`NNlib.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 [`layernorm`](@ref), [`instancenorm`](@ref), and [`groupnorm`](@ref).
200+
See also [`NNlib.layernorm`](@ref), [`NNlib.instancenorm`](@ref), and [`NNlib.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 [`layernorm`](@ref), [`batchnorm`](@ref), and [`groupnorm`](@ref).
235+
See also [`NNlib.layernorm`](@ref), [`NNlib.batchnorm`](@ref), and [`NNlib.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 [`layernorm`](@ref), [`batchnorm`](@ref), and [`instancenorm`](@ref).
269+
See also [`NNlib.layernorm`](@ref), [`NNlib.batchnorm`](@ref), and [`NNlib.instancenorm`](@ref).
270270
271271
# Examples
272272

0 commit comments

Comments
 (0)