Skip to content

Commit 806b0ef

Browse files
authored
Add minimal infrastructure for the docs (#431)
* Add minimal infrastructure for the docs * Add `glu` * Add reference Flux layers * Fix a couple of docstring references
1 parent 5dd04df commit 806b0ef

File tree

10 files changed

+345
-36
lines changed

10 files changed

+345
-36
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,28 @@ jobs:
7272
with:
7373
file: lcov.info
7474

75-
# docs:
76-
# name: Documentation
77-
# runs-on: ubuntu-latest
78-
# steps:
79-
# - uses: actions/checkout@v2
80-
# - uses: julia-actions/setup-julia@v1
81-
# with:
82-
# version: '1'
83-
# - run: julia --project=docs .ci/develop.jl
84-
# - run: julia --project=docs docs/make.jl
85-
# env:
86-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87-
# DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
88-
89-
# doctests:
90-
# name: Doctests
91-
# runs-on: ubuntu-latest
92-
# steps:
93-
# - uses: actions/checkout@v2
94-
# - uses: julia-actions/setup-julia@v1
95-
# with:
96-
# version: '1'
97-
# - run: julia --project=docs .ci/develop.jl
98-
# - run: |
99-
# julia --project=docs -e '
100-
# using Documenter
101-
# using NNlib
102-
# # using NNlibCUDA
103-
# DocMeta.setdocmeta!(NNlib, :DocTestSetup, :(using NNlib); recursive=true)
104-
# # DocMeta.setdocmeta!(NNlibCUDA, :DocTestSetup, :(using NNlib, CUDA); recursive=true)
105-
# doctest(NNlib)
106-
# # doctest(NNlibCUDA)'
75+
docs:
76+
name: Documentation
77+
runs-on: ubuntu-latest
78+
steps:
79+
- uses: actions/checkout@v2
80+
- uses: julia-actions/setup-julia@v1
81+
with:
82+
version: '1.6'
83+
- run: |
84+
julia --project=docs -e '
85+
using Pkg
86+
Pkg.develop(PackageSpec(path=pwd()))
87+
Pkg.instantiate()'
88+
- run: |
89+
julia --color=yes --project=docs/ -e '
90+
using NNlib
91+
# using Pkg; Pkg.activate("docs")
92+
using Documenter
93+
using Documenter: doctest
94+
DocMeta.setdocmeta!(NNlib, :DocTestSetup, :(using NNlib); recursive=true)
95+
doctest(NNlib)'
96+
- run: julia --project=docs docs/make.jl
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

.github/workflows/clean_preview.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# from https://github.com/CliMA/ClimaTimeSteppers.jl
2+
name: Doc Preview Cleanup
3+
4+
on:
5+
pull_request:
6+
types: [closed]
7+
8+
jobs:
9+
doc-preview-cleanup:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout gh-pages branch
13+
uses: actions/checkout@v2
14+
with:
15+
ref: gh-pages
16+
- name: Delete preview and history + push changes
17+
run: |
18+
if [ -d "previews/PR$PRNUM" ]; then
19+
git config user.name "Documenter.jl"
20+
git config user.email "[email protected]"
21+
git rm -rf "previews/PR$PRNUM"
22+
git commit -m "delete preview"
23+
git branch gh-pages-new $(echo "delete history" | git commit-tree HEAD^{tree})
24+
git push --force origin gh-pages-new:gh-pages
25+
fi
26+
env:
27+
PRNUM: ${{ github.event.number }}

.github/workflows/pr_comment.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: pr_comment
2+
on:
3+
pull_request:
4+
types: [labeled]
5+
jobs:
6+
pr_comment:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Create PR comment
10+
if: github.event_name == 'pull_request' && github.repository == github.event.pull_request.head.repo.full_name && github.event.label.name == 'documentation' # if this is a pull request build AND the pull request is NOT made from a fork
11+
uses: thollander/actions-comment-pull-request@71efef56b184328c7ef1f213577c3a90edaa4aff
12+
with:
13+
message: 'Once the documentation build has completed, you can preview any updated documentation at this URL: https://fluxml.ai/NNlib.jl/previews/PR${{ github.event.number }}/'
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
site/

docs/make.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Documenter, NNlib
2+
3+
DocMeta.setdocmeta!(NNlib, :DocTestSetup, :(using NNlib); recursive = true)
4+
5+
makedocs(modules = [NNlib],
6+
sitename = "NNlib.jl",
7+
doctest = false,
8+
pages = ["Home" => "index.md",
9+
"Reference" => "reference.md"],
10+
format = Documenter.HTML(
11+
canonical = "https://fluxml.ai/NNlib.jl/stable/",
12+
# analytics = "UA-36890222-9",
13+
assets = ["assets/flux.css"],
14+
prettyurls = get(ENV, "CI", nothing) == "true"),
15+
)
16+
17+
deploydocs(repo = "github.com/FluxML/NNlib.jl.git",
18+
target = "build",
19+
push_preview = true)

docs/src/assets/flux.css

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
@import url('https://fonts.googleapis.com/css?family=Lato:400,400i');
2+
3+
body {
4+
font-family: Lato, "Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
5+
}
6+
7+
nav.toc {
8+
padding-top: 0;
9+
background: rgb(240, 240, 240);
10+
line-height: 2em;
11+
cursor: default;
12+
user-select: none;
13+
}
14+
15+
h1+h2 {
16+
margin-top: 0;
17+
}
18+
19+
/* Green banner in ToC */
20+
nav.toc > h1 {
21+
margin-top: 0;
22+
padding-top: 0.4em;
23+
padding-bottom: 0.5em;
24+
border-bottom: 5px solid white;
25+
box-shadow: 0px -2px 5px rgb(60,60,60);
26+
margin-bottom: 0.5em;
27+
background: rgb(60, 150, 60);
28+
29+
font-style: italic;
30+
font-weight: normal;
31+
font-size: 50pt;
32+
text-transform: lowercase;
33+
text-shadow: 2px 2px 5px rgba(0,0,0,0.2);
34+
color: white;
35+
}
36+
37+
/* Reduce ToC font size */
38+
.toctext {
39+
font-size: 10pt;
40+
}
41+
42+
/* Fade out non-clickable ToC headers */
43+
nav.toc ul span.toctext {
44+
color: rgb(180, 180, 180);
45+
}
46+
47+
nav.toc ul .toctext {
48+
color: rgb(100, 100, 100);
49+
}
50+
51+
nav.toc ul a.toctext:hover {
52+
color: inherit;
53+
background: rgb(220, 220, 220);
54+
cursor: default;
55+
}
56+
57+
nav.toc li.current > .toctext {
58+
background: linear-gradient(90deg, rgb(245,245,245) 0%, white 90%);
59+
font-weight: normal;
60+
}
61+
62+
nav.toc ul.internal li.toplevel {
63+
font-weight: normal;
64+
}
65+
66+
/* Content */
67+
68+
article { max-width: none; }
69+
70+
article > p, article > ul {
71+
max-width: 45em;
72+
}
73+
74+
/* Links */
75+
a, a:visited { color: rgb(0, 120, 0); }
76+
article p a { border-bottom: 1px solid rgb(200, 230, 200); }
77+
a:hover, a:visited:hover { color: rgb(0, 80, 0); }
78+
79+
/* Article Links */
80+
article p a { border-bottom: 1px solid rgb(200, 230, 200); }
81+
article p a:hover, article a:visited:hover { color: rgb(0, 120, 0); }
82+
article p a:hover { border-bottom: 1px solid rgb(150, 200, 150); }
83+
84+
/* Doctstrings */
85+
article section.docstring {
86+
padding: 0.5em 0;
87+
border-left: none;
88+
border-right: none;
89+
border-bottom: none;
90+
}
91+
92+
/* Code */
93+
94+
article pre, article p > code {
95+
background: rgb(245, 250, 245);
96+
}
97+
98+
article pre {
99+
border: none;
100+
max-width: none;
101+
padding: 1em;
102+
border-radius: 10px 0px 0px 10px;
103+
margin-left: -1em;
104+
margin-right: -2em;
105+
}
106+
107+
.hljs-comment {
108+
font-style: italic;
109+
}
110+
111+
.hljs-number {
112+
color: rgb(0, 150, 150);
113+
}

docs/src/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# NNlib.jl
2+
3+
`NNlib` provides a library of functions useful for neural networks, such as softmax, sigmoid, batched multiplication, convolutions and pooling. Many of these are used by [Flux.jl](https://github.com/FluxML/Flux.jl), which loads this package, but they may be used independently.
4+
5+
For use with automatic differentiation, this package defines gradients using [ChainRules.jl](https://github.com/JuliaDiff/ChainRules.jl). These will be seen by various packages including [Zygote.jl](https://github.com/FluxML/Zygote.jl).
6+
7+
To use these functions with [CUDA.jl](https://github.com/JuliaGPU/CUDA.jl) you will need [NNlibCUDA.jl](https://github.com/FluxML/NNlibCUDA.jl) as well.

docs/src/reference.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Reference
2+
3+
The API reference of `NNlib`.
4+
5+
## Activation Functions
6+
7+
Non-linearities that go between layers of your model. Note that, unless otherwise stated, activation functions operate on scalars. To apply them to an array you can call `σ.(xs)`, `relu.(xs)` and so on.
8+
9+
```@docs
10+
celu
11+
elu
12+
gelu
13+
hardsigmoid
14+
sigmoid_fast
15+
hardtanh
16+
tanh_fast
17+
leakyrelu
18+
lisht
19+
logcosh
20+
logsigmoid
21+
mish
22+
relu
23+
relu6
24+
rrelu
25+
selu
26+
sigmoid
27+
softplus
28+
softshrink
29+
softsign
30+
swish
31+
hardswish
32+
tanhshrink
33+
trelu
34+
```
35+
36+
## Softmax
37+
38+
`Flux`'s `logitcrossentropy` uses `NNlib.softmax` internally.
39+
40+
```@docs
41+
softmax
42+
logsoftmax
43+
```
44+
45+
## Pooling
46+
47+
`Flux`'s `AdaptiveMaxPool`, `AdaptiveMeanPool`, `GlobalMaxPool`, `GlobalMeanPool`, `MaxPool`, and `MeanPool` use `NNlib.PoolDims`, `NNlib.maxpool`, and `NNlib.meanpool` as their backend.
48+
49+
```@docs
50+
PoolDims
51+
maxpool
52+
meanpool
53+
```
54+
55+
## Padding
56+
57+
```@docs
58+
pad_reflect
59+
pad_constant
60+
pad_repeat
61+
pad_zeros
62+
```
63+
64+
## Convolution
65+
66+
`Flux`'s `Conv` and `CrossCor` layers use `NNlib.DenseConvDims` and `NNlib.conv` internally.
67+
68+
```@docs
69+
conv
70+
ConvDims
71+
depthwiseconv
72+
DepthwiseConvDims
73+
DenseConvDims
74+
```
75+
76+
## Upsampling
77+
78+
`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.
79+
80+
```@docs
81+
upsample_nearest
82+
∇upsample_nearest
83+
upsample_linear
84+
∇upsample_linear
85+
upsample_bilinear
86+
∇upsample_bilinear
87+
upsample_trilinear
88+
∇upsample_trilinear
89+
pixel_shuffle
90+
```
91+
92+
## Batched Operations
93+
94+
`Flux`'s `Bilinear` layer uses `NNlib.batched_mul` internally.
95+
96+
```@docs
97+
batched_mul
98+
batched_mul!
99+
batched_adjoint
100+
batched_transpose
101+
batched_vec
102+
```
103+
104+
## Gather and Scatter
105+
106+
`Flux`'s `Embedding` layer uses `NNlib.gather` as its backend.
107+
108+
```@docs
109+
NNlib.gather
110+
NNlib.gather!
111+
NNlib.scatter
112+
NNlib.scatter!
113+
```
114+
115+
## Sampling
116+
117+
```@docs
118+
grid_sample
119+
∇grid_sample
120+
```
121+
122+
## Losses
123+
124+
```@docs
125+
ctc_loss
126+
```
127+
128+
## Miscellaneous
129+
130+
```@docs
131+
logsumexp
132+
NNlib.glu
133+
```

0 commit comments

Comments
 (0)