Skip to content

Commit

Permalink
swtich to GLMakie
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Dec 21, 2023
1 parent 5b6df6a commit 3a884c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 4 additions & 2 deletions benchmarking/Project.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
MLDatasets = "eb30cadb-4394-5ae3-aed4-317e484a6458"
Metalhead = "dbeba491-748d-5e0e-a39e-b530a07fa0cc"
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
cuDNN = "02a925ec-e4fe-4b08-9a7e-0d78e3d38ccd"

[compat]
Colors = "0.12"
CUDA = "5"
DataFrames = "1"
Flux = "0.14"
GLMakie = "0.20"
MLDatasets = "0.7"
Metalhead = "0.9"
Optimisers = "0.3"
ProgressMeter = "1.9"
TimerOutputs = "0.5"
UnicodePlots = "3.6"
cuDNN = "1.2"
13 changes: 9 additions & 4 deletions benchmarking/benchmark.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

using Colors
using CUDA, cuDNN
using DataFrames
using Flux
using Flux: logitcrossentropy, onecold, onehotbatch
using GLMakie
using Metalhead
using MLDatasets
using Optimisers
using ProgressMeter
using TimerOutputs
using UnicodePlots

include("tooling.jl")

Expand Down Expand Up @@ -64,7 +65,10 @@ modelstrings = (
# "UNet(; $common)" # doesn't support kwargs "inchannels", "nclasses"
)
df = DataFrame(; model=String[], train_loss=Float64[], train_acc=Float64[], test_loss=Float64[], test_acc=Float64[])
plt = lineplot([0], [0], title="test accuracy vs. time (s)", ylim = (0,1), xlim=(0,60))
cols = distinguishable_colors(length(modelstrings), [RGB(1,1,1), RGB(0,0,0)], dropseed=true)
f = Figure()
ax = Axis(f[1, 1], title="CIFAR-10 Training on a Nvidia 3090, batch 1000\nTest accuracy vs. time over 45 epochs", xlabel="Time (s)", ylabel="Testset Accuracy")
display(f)
max_x = 0
for (i, modstring) in enumerate(modelstrings)
@timeit to "$modstring" begin
Expand All @@ -86,14 +90,15 @@ for (i, modstring) in enumerate(modelstrings)
else
elapsed, train_loss_hist, train_acc_hist, test_loss_hist, test_acc_hist = ret
max_x = max(maximum(elapsed), max_x)
lineplot!(plt, elapsed, test_acc_hist, name=modstring)
lines!(ax, elapsed, test_acc_hist, label=modstring, color=cols[i])
elapsed, train_loss_hist[end], train_acc_hist[end], test_loss_hist[end], test_acc_hist[end]
end
push!(df, (modstring, train_loss, train_acc, test_loss, test_acc), promote=true)
end
GC.gc(true)
end
display(plt)
f[1, 2] = Legend(f, ax, "Models", framevisible = false)
display(f)
display(df)
print_timer(to; sortby = :firstexec)
end
Expand Down
4 changes: 2 additions & 2 deletions benchmarking/tooling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function _train(model, train_loader, test_loader; epochs = 45,
train_loss_hist, train_acc_hist = Float64[], Float64[]
test_loss_hist, test_acc_hist = Float64[], Float64[]
elapsed = Float64[]
start = time()
@showprogress "training" for epoch in 1:epochs
i = 0
for (x, y) in train_loader
Expand All @@ -72,7 +71,7 @@ function _train(model, train_loader, test_loader; epochs = 45,
@timeit to "testing" test_loss, test_acc = loss_and_accuracy(test_loader, model, device; limit)
push!(train_loss_hist, train_loss); push!(train_acc_hist, train_acc);
push!(test_loss_hist, test_loss); push!(test_acc_hist, test_acc);
push!(elapsed, time() - start)
push!(elapsed, time())
if show_plots
plt2 = lineplot(1:epoch, train_loss_hist, name = "train_loss", xlabel="epoch", ylabel="loss")
lineplot!(plt2, 1:epoch, test_loss_hist, name = "test_loss")
Expand All @@ -85,6 +84,7 @@ function _train(model, train_loader, test_loader; epochs = 45,
GC.gc() # GPU will OOM without this
end
end
elapsed = elapsed .- elapsed[1]
train_loss, train_acc, test_loss, test_acc = train_loss_hist[end], train_acc_hist[end], test_loss_hist[end], test_acc_hist[end]
@info "results after $epochs epochs $(repr(map(x->round(x, digits=3), (; train_loss, train_acc, test_loss, test_acc))))"
return elapsed, train_loss_hist, train_acc_hist, test_loss_hist, test_acc_hist
Expand Down

0 comments on commit 3a884c1

Please sign in to comment.