Commit fe803a1
Merge #1794
1794: Tidy up `Maxout` r=mcabbott a=mcabbott
Maxout is from #698 . This:
* adds pretty printing
* changes the explicit signature to `Maxout(layer, layer, layer)`, rather than providing a tuple, to be more like other layers (with deprecation)
* adds more examples to the docstring, and combines the two
* changes not to use `mapreduce`. I see now this was a performance choice at the time, discussed here #647 (comment) , but with Zygote this is much slower.
Before:
```
julia> using Flux
julia> m3 = Maxout(() -> Dense(5, 7, tanh), 3)
Maxout{Tuple{Dense{typeof(tanh), Matrix{Float32}, Vector{Float32}}, Dense{typeof(tanh), Matrix{Float32}, Vector{Float32}}, Dense{typeof(tanh), Matrix{Float32}, Vector{Float32}}}}((Dense(5, 7, tanh), Dense(5, 7, tanh), Dense(5, 7, tanh)))
julia> x = rand(Float32, 5, 11);
julia> `@btime` gradient(sum∘m3, $x);
min 112.792 μs, mean 123.774 μs (930 allocations, 49.09 KiB. GC mean 3.71%)
```
After:
```
julia> m3 = Maxout(() -> Dense(5, 7, tanh), 3)
Maxout(
Dense(5, 7, tanh), # 42 parameters
Dense(5, 7, tanh), # 42 parameters
Dense(5, 7, tanh), # 42 parameters
) # Total: 6 arrays, 126 parameters, 888 bytes.
julia> x = rand(Float32, 5, 11);
julia> `@btime` gradient(sum∘m3, $x);
min 34.541 μs, mean 38.448 μs (493 allocations, 32.48 KiB. GC mean 6.63%)
```
Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>File tree
4 files changed
+55
-27
lines changed- src
- layers
- test/layers
4 files changed
+55
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
| 214 | + | |
| 215 | + | |
215 | 216 | | |
216 | | - | |
217 | | - | |
218 | | - | |
| 217 | + | |
| 218 | + | |
219 | 219 | | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
| 220 | + | |
| 221 | + | |
225 | 222 | | |
226 | | - | |
227 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
228 | 226 | | |
229 | | - | |
230 | | - | |
231 | | - | |
| 227 | + | |
232 | 228 | | |
233 | 229 | | |
| 230 | + | |
| 231 | + | |
234 | 232 | | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
239 | 236 | | |
240 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
241 | 243 | | |
242 | | - | |
| 244 | + | |
| 245 | + | |
243 | 246 | | |
244 | 247 | | |
245 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
246 | 254 | | |
247 | | - | |
| 255 | + | |
248 | 256 | | |
249 | 257 | | |
250 | 258 | | |
251 | 259 | | |
252 | 260 | | |
253 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
254 | 272 | | |
255 | 273 | | |
| 274 | + | |
256 | 275 | | |
257 | 276 | | |
258 | 277 | | |
| |||
277 | 296 | | |
278 | 297 | | |
279 | 298 | | |
| 299 | + | |
| 300 | + | |
280 | 301 | | |
281 | 302 | | |
282 | 303 | | |
| |||
390 | 411 | | |
391 | 412 | | |
392 | 413 | | |
393 | | - | |
| 414 | + | |
394 | 415 | | |
395 | 416 | | |
396 | 417 | | |
| |||
399 | 420 | | |
400 | 421 | | |
401 | 422 | | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
402 | 426 | | |
403 | 427 | | |
404 | 428 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| |||
0 commit comments