Skip to content

Commit 0d180a8

Browse files
Merge pull request #953 from SciML/fix-sophia-documentation-example
Fix Sophia neural network training documentation example
2 parents 597f249 + 94e449c commit 0d180a8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

docs/src/optimization_packages/optimization.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,18 @@ ps_ca = ComponentArray(ps)
7676
smodel = StatefulLuxLayer{true}(model, nothing, st)
7777
7878
function callback(state, l)
79-
state.iter % 25 == 1 && @show "Iteration: %5d, Loss: %.6e\n" state.iter l
79+
state.iter % 25 == 1 && @show "Iteration: $(state.iter), Loss: $l"
8080
return l < 1e-1 ## Terminate if loss is small
8181
end
8282
8383
function loss(ps, data)
84-
ypred = [smodel([data[1][i]], ps)[1] for i in eachindex(data[1])]
85-
return sum(abs2, ypred .- data[2])
84+
x_batch, y_batch = data
85+
ypred = [smodel([x_batch[i]], ps)[1] for i in eachindex(x_batch)]
86+
return sum(abs2, ypred .- y_batch)
8687
end
8788
8889
optf = OptimizationFunction(loss, AutoZygote())
8990
prob = OptimizationProblem(optf, ps_ca, data)
9091
91-
res = Optimization.solve(prob, Optimization.Sophia(), callback = callback)
92+
res = Optimization.solve(prob, Optimization.Sophia(), callback = callback, epochs = 100)
9293
```

0 commit comments

Comments
 (0)