@@ -10,34 +10,35 @@ When you define a new layer, this tells Flux to explore inside it
10
10
to see the parameters it trains, and also to move them to the GPU, change precision, etc.
11
11
Like `@functor`, this assumes your struct has the default constructor, to enable re-building.
12
12
13
- Some "keywords" allow control of the recursion.
13
+ Some keywords allow you to limit this exploration, instead of visiting all `fieldnames(T)`.
14
+ Note that it is never necessary to tell Flux to ignore non-array objects such as functions or sizes.
14
15
* If some fields look like parameters but should not be trained,
15
- then `trainable` lets you specify fields to include, and ignore the rest.
16
- * You can likewise add restructions to Functors's `children` (although this is seldom a good idea).
16
+ then `trainable` lets you specify which fields to include, while the rest are ignored.
17
+ * You can likewise add restrictions to Functors's `children` (although this is seldom a good idea),
18
+ equivalent to `@functor Struct (α,β)`. Any `trainable` limitation must then be a subset of `children`.
17
19
18
- The defaults are `fieldnames(T)` for both. They must be subsets of this, and `trainable` must be a subset of `children`.
19
-
20
- It also handles overloads of `show` for pretty printing.
20
+ The macro also handles overloads of `show` for pretty printing.
21
21
* By default, it adds methods to 3-arg `Base.show` to treat your layer much like `Dense` or `Conv`.
22
22
* If your layer is a container, more like `Chain` or `Parallel`, then `:expand` makes `show` unfold its contents.
23
23
* To disable all `show` overloads, there is an `:ignore` option too.
24
24
25
- Note that re-running the macro with different options does not overwrite all methods, you will need to restart.
26
25
(You probably still want to define 2-arg `show(io::IO, x::Layer)`, the macro does not touch this.)
27
26
27
+ Note that re-running the macro with different options may not overwrite all methods, you will need to restart.
28
+
28
29
# Example
29
30
```jldoctest
30
31
julia> struct Trio; a; b; c end
31
32
32
- julia> tri = Trio(Dense([1.1 2.2], [0.0], tanh), Dense([ 3.3;;] , false), Dropout(0.4))
33
+ julia> tri = Trio(Dense([1.1 2.2], [0.0], tanh), Dense(hcat( 3.3) , false), Dropout(0.4))
33
34
Trio(Dense(2 => 1, tanh), Dense(1 => 1; bias=false), Dropout(0.4))
34
35
35
36
julia> Flux.destructure(tri) # parameters are not yet visible to Flux
36
37
(Bool[], Restructure(Trio, ..., 0))
37
38
38
39
julia> Flux.@layer :expand Trio
39
40
40
- julia> Flux.destructure(tri) # now gpu, train!, etc will see inside too
41
+ julia> Flux.destructure(tri) # now gpu, params, train!, etc will see inside too
41
42
([1.1, 2.2, 0.0, 3.3], Restructure(Trio, ..., 4))
42
43
43
44
julia> tri # and layer is printed like Chain
0 commit comments