Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing state in training #579

Merged
merged 9 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/axon/loop.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ defmodule Axon.Loop do
is set, the loop will raise on any cache miss during the training loop. Defaults
to true.

* `:force_garbage_collect?` - whether or not to force garbage collection after each
* `:force_garbage_collection?` - whether or not to force garbage collection after each
iteration. This may help avoid OOMs when training large models, but it will slow
training down.

Expand Down
20 changes: 17 additions & 3 deletions lib/axon/model_state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,27 @@ defmodule Axon.ModelState do
end

defp tree_get(data, access) when is_list(access) do
Enum.reduce(access, %{}, &Map.put(&2, &1, Map.fetch!(data, &1)))
Enum.reduce(access, %{}, fn key, acc ->
case data do
%{^key => val} ->
Map.put(acc, key, val)

%{} ->
acc
end
end)
end

defp tree_get(data, access) when is_map(access) do
Enum.reduce(access, %{}, fn {key, value}, acc ->
tree = tree_get(data[key], value)
Map.put(acc, key, tree)
case data do
%{^key => val} ->
tree = tree_get(val, value)
Map.put(acc, key, tree)

%{} ->
acc
end
end)
end

Expand Down
Loading