https://github.com/baggepinnen/fluxopttools.jl
Use Optim to train Flux models and visualize loss landscapes
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.2%) to scientific vocabulary
Keywords from Contributors
Repository
Use Optim to train Flux models and visualize loss landscapes
Basic Info
- Host: GitHub
- Owner: baggepinnen
- License: mit
- Language: Julia
- Default Branch: master
- Size: 397 KB
Statistics
- Stars: 60
- Watchers: 5
- Forks: 4
- Open Issues: 3
- Releases: 4
Metadata Files
README.md
FluxOptTools
This package contains some utilities to enhance training of Flux.jl models.
Train using Optim
Optim.jl can be used to train Flux models (if Flux is on version 0.10 or above), here's an example how
julia
using Flux, Zygote, Optim, FluxOptTools, Statistics
m = Chain(Dense(1,3,tanh) , Dense(3,1))
x = LinRange(-pi,pi,100)'
y = sin.(x)
loss() = mean(abs2, m(x) .- y)
Zygote.refresh()
pars = Flux.params(m)
lossfun, gradfun, fg!, p0 = optfuns(loss, pars)
res = Optim.optimize(Optim.only_fg!(fg!), p0, Optim.Options(iterations=1000, store_trace=true))
The utility provided by this package is the function optfuns which returns three functions and p0, a vectorized version of pars. BFGS typically has better convergence properties than, e.g., the ADAM optimizer. Here's a benchmark where BFGS in red beats ADAGrad with tuned step size in blue, and a stochastic L-BFGS [1] (implemented in this repository) in green performs somewhere in between.
From a computational time perspective, S-LBFGS is about 2 times slower than ADAM (with additionnal memory complexity) while the traditional L-BFGS algorithm is around 3 times slower than ADAM (but similar memory burden as SL-BFGS).
The code for this benchmark is in the runtests.jl.
Visualize loss landscape
Based on the work on loss landscape visualization [2], we define a plot recipe such that a loss landscape can be plotted with
julia
using Plots
contourf(() -> log10(1 + loss()), pars, color=:turbo, npoints=50, lnorm=1)
The landscape is plotted by selecting two random directions and extending the current point (pars) a distance lnorm * norm(pars) (both negative and positive) along the two random directions. The number of loss evaluations will be npoints^2.
Flatten and Unflatten
What this package really does is flattening and reassembling the types Flux.Params and Zygote.Grads to and from vectors. These functions are used like so
```julia
p = zeros(pars) # Creates a vector of length sum(length, pars)
copy!(p,pars) # Store pars in vector p
copy!(pars,p) # Reverse
g = zeros(grads) # Creates a vector of length sum(length, grads)
copy!(g,grads) # Store grads in vector g
copy!(grads,g) # Reverse
``
This is what is used under the hood in the functions returned fromoptfuns` in order to have everything on a form that Optim understands.
References
Owner
- Name: Fredrik Bagge Carlson
- Login: baggepinnen
- Kind: user
- Location: Lund, Sweden
- Website: baggepinnen.github.io
- Twitter: baggepinnen
- Repositories: 59
- Profile: https://github.com/baggepinnen
Control systems, system identification, signal processing and machine learning
GitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1
Committers
Last synced: over 3 years ago
All Time
- Total Commits: 38
- Total Committers: 7
- Avg Commits per committer: 5.429
- Development Distribution Score (DDS): 0.342
Top Committers
| Name | Commits | |
|---|---|---|
| Fredrik Bagge Carlson | b****n@g****m | 25 |
| Fredrik Bagge Carlson | c****b@u****g | 6 |
| AlexLewandowski | l****p@g****m | 2 |
| Matthieu Barreau | n****n@g****m | 2 |
| pakk-minidose | 5****e@u****m | 1 |
| Julia TagBot | 5****t@u****m | 1 |
| Sharan Yalburgi | s****i@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 12 months ago
All Time
- Total issues: 11
- Total pull requests: 14
- Average time to close issues: 3 months
- Average time to close pull requests: 3 days
- Total issue authors: 11
- Total pull request authors: 8
- Average comments per issue: 2.55
- Average comments per pull request: 2.0
- Merged pull requests: 9
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- vavrines (1)
- ChrisRackauckas (1)
- cortner (1)
- jacob-zyl (1)
- Red-Portal (1)
- bienpierre (1)
- nuclear718 (1)
- athulsudheesh (1)
- JuliaTagBot (1)
- khorrami1 (1)
- pakk-minidose (1)
Pull Request Authors
- mBarreau (7)
- AlexLewandowski (1)
- pakk-minidose (1)
- sharanry (1)
- baggepinnen (1)
- gnadt (1)
- fraksuh (1)
- JuliaTagBot (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- julia 10 total
- Total dependent packages: 2
- Total dependent repositories: 0
- Total versions: 4
juliahub.com: FluxOptTools
Use Optim to train Flux models and visualize loss landscapes
- Documentation: https://docs.juliahub.com/General/FluxOptTools/stable/
- License: MIT
-
Latest release: 0.1.3
published almost 3 years ago
Rankings
Dependencies
- JuliaRegistries/TagBot v1 composite
- actions/checkout v2 composite
- codecov/codecov-action v1 composite
- julia-actions/julia-processcoverage v1 composite
- julia-actions/julia-runtest latest composite
- julia-actions/setup-julia latest composite