by Simon DanischJul 13 2019
Julia & graphic enthusiast. Interested in high performance computing, GPUs and machine learning.

WGLMakie Casset Zygote

apt-get update
apt-get install build-essential -y
ln -fs /lib/x86_64-linux-gnu/libz.so.1 /usr/local/lib/libz.so
ldconfig
]up; add https://github.com/SimonDanisch/ShaderAbstractions.jl https://github.com/JuliaPlots/WGLMakie.jl#sd-buffers GeometryBasics#master Observables AbstractPlotting#sd-webgl GeometryTypes JSCall#master StaticArrays WebIO#master Zygote PackageCompiler#sd-notomls Cassette Interact; gc
utilities.jl
include(
utilities.jl
) chain = [(rand() * pi) for i in 1:4] function next_position(position, angle) position .+ (sin(angle), cos(angle)) end # Our "neuronal network" ... or chain of flexible links function predict(chain, input) output = next_position(input, chain[1]) # Layer 1 output = next_position(output, chain[2]) # Layer 2 output = next_position(output, chain[3]) # Layer 3 output = next_position(output, chain[4]) # Layer 4 return output end function loss(chain, input, target) sum((predict(chain, input) .- target) .^ 2) end input, target = (0.0, 0.0), (3.0, 3.0) weights, s = visualize(chain, input, target) s
using Zygote
function loss_gradient(chain, input, target)
  # first index, to get gradient of first argument
  Zygote.gradient(loss, chain, input, target)[1]
end

for i in 1:100
  # get gradient of loss function
  angle∇= loss_gradient(chain, input, target)
  # update weights with our loss gradients
  # this updates the weights in the direction of smaller loss
  chain .-= 0.01 .* angle∇
  # update visualization
  weights[] = chain
  sleep(0.01)
end;
0.4s
Julia 1.1 WGLMakie+Zygote (Julia)
Install
open("/results/snoop.jl", "w") do io
	write(io, read(
utilities.jl
)) println(io, """ function next_position(position, angle) position .+ (sin(angle), cos(angle)) end # Our "neuronal network" ... or chain of flexible links function predict(chain, input) output = next_position(input, chain[1]) # Layer 1 output = next_position(output, chain[2]) # Layer 2 output = next_position(output, chain[3]) # Layer 3 output = next_position(output, chain[4]) # Layer 4 return output end function loss(chain, input, target) return sum((predict(chain, input) .- target) .^ 2) end chain = [(rand() * pi) for i in 1:4] input, target = (0.0, 0.0), (3.0, 3.0) weights, s = visualize(chain, input, target) using Zygote repr(MIME"text/html"(), s); function loss_gradient(chain, input, target) # first index, to get gradient of first argument Zygote.gradient(loss, chain, input, target)[1] end angle∇= loss_gradient(chain, input, target) # update weights with our loss gradients # this updates the weights in the direction of smaller loss chain .-= 0.01 .* angle∇ # update visualization weights[] = chain """) end
snoop.jl
using PackageCompiler
open("/results/precompiles.jl", "w") do io
  PackageCompiler.snoop(
snoop.jl
, io) end
false
precompiles.jl
# add the correct usings + imports to the precompile file
using Pkg
packages = ["WGLMakie", "GeometryBasics", "AbstractPlotting", "Zygote", "LinearAlgebra"]
ctx = Pkg.Types.Context()
pkgs = PackageSpec.(packages)
packages = PackageCompiler.flat_deps(ctx, packages)
# remove blacklisted packages from full list of packages
imports = PackageCompiler.to_pkgid.(packages)
filter!(x-> !(x.name in ("WinRPM", "HTTPClient")), imports)
usings = join(["const $(x.name) = Base.require($(PackageCompiler.prepr(x)))" for x in imports], "\n")
open("/results/precompiles2.jl", "w") do io
  println(io, usings)
  open(
precompiles.jl
) do io2 write(io, io2) end end
2068012
precompiles2.jl
using PackageCompiler
syso, sysold = compile_incremental(
precompiles2.jl
)
("/root/.julia/packages/PackageCompiler/RRsVs/sysimg/sys.so", "/usr/local/julia/lib/julia/sys.so")
cp(syso, sysold, force  = true)
"/usr/local/julia/lib/julia/sys.so"