SimpleKernel performance with Zygote
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- julia
- Ambito
- machine-learning, performance
Direzione di ricerca
Inizia in src/matrix/kernelmatrix.jl alla riga collegata usando Base.Fix1 e riproduci i benchmark Julia per kernelmatrix e Zygote.pullback. Confronta il comportamento del forward pass con il benchmark pairwise per isolare la regressione. Il lavoro è completato quando viene documentato o implementato un approccio che avvicini sostanzialmente il forward pass di Zygote al primal senza introdurre regressioni nel percorso kernel esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
It looks like we've got a performance bug in the above. Specifically, the primal looks to be fine:
julia> @benchmark kernelmatrix(SEKernel(), $(randn(100)))
BenchmarkTools.Trial:
memory estimate: 158.25 KiB
allocs estimate: 8
--------------
minimum time: 92.684 μs (0.00% GC)
median time: 155.135 μs (0.00% GC)
mean time: 181.207 μs (12.32% GC)
maximum time: 15.995 ms (98.92% GC)
--------------
samples: 10000
evals/sample: 1
while Zygotes forwards-pass is about 100x worse:
julia> @benchmark Zygote.pullback(kernelmatrix, SEKernel(), $(randn(100)))
BenchmarkTools.Trial:
memory estimate: 7.25 MiB
allocs estimate: 290068
--------------
minimum time: 34.106 ms (0.00% GC)
median time: 35.180 ms (0.00% GC)
mean time: 36.456 ms (2.37% GC)
maximum time: 60.521 ms (25.00% GC)
--------------
samples: 138
evals/sample: 1
Given that the bar for a reasonably performant forwards-pass is 1-2x the primal, this is definitely sub-optimal.
I'm reasonably sure that the culprit is the use of Base.Fix1 here: https://github.com/JuliaGaussianProcesses/KernelFunctions.jl/blob/13985cc6cb8903004f33e6fe9d2540571594a3c8/src/matrix/kernelmatrix.jl#L95
maping interesting types in is generally a bad idea when used in conjunction with Zygote unfortunately.
@theogf @devmotion I'm not sure what our best options are here. I think there are two questions here:
- could we tweak the current implementation a bit into something that Zygote likes, and get sane performance?
- what escape hatches do we have / could we have to make it straightforward to hand-improve performance where necessary?
For example, the use of Base.Fix1 here might actually be a real win, because we could hand-optimise the implementation of map(::Base.Fix1{typeof(kappa), SEKernel}, ::Array{<:Real}) quite straightforwardly. Unfortunately, this would essentially mean that any kernel that we care about having good performance with would require us to hand-implement stuff. If we did this using ForwardDiff, it might be fine though 🤷
n.b. it's definitely not the pairwise computations:
julia> @benchmark Zygote.pullback(KernelFunctions.pairwise, KernelFunctions.SqEuclidean(), randn(100))
BenchmarkTools.Trial:
memory estimate: 82.25 KiB
allocs estimate: 45
--------------
minimum time: 28.473 μs (0.00% GC)
median time: 59.303 μs (0.00% GC)
mean time: 74.604 μs (15.96% GC)
maximum time: 15.654 ms (99.13% GC)
--------------
samples: 10000
evals/sample: 1
they've been hand-optimised for ages, so it would have been really surprising if there were a problem there.
- Lingua principale
- Julia
- Stelle
- 276
- Fork
- 42
- Merge medio
- 2g 20h
- PR unite (30g)
- 3
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JuliaGaussianProcesses/KernelFunctions.jl
-
Future plans?Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
JuliaGaussianProcesses/KernelFunctions.jl#585 · 8 commenti · 3 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
JuliaGaussianProcesses/KernelFunctions.jl#571 · 1 reazione ·
-
new kernel
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
JuliaGaussianProcesses/KernelFunctions.jl#533 · 1 reazione ·
Tutte le issue di JuliaGaussianProcesses/KernelFunctions.jl
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
JuliaDecisionFocusedLearning/ImplicitDifferentiation.jl#231 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
bug io
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
lanl-ansi/PowerModels.jl#1023 ·