Skip to content

Commit 150c85d

Browse files
authored
fix: fix Axon.Display for Tensor parameter templates (#638)
* fix: fix Axon.Display for Tensor parameter templates * fix: add Hex mirror fallback for setup-beam * revert: hex fallback
1 parent fa8a928 commit 150c85d

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/axon/display.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ defmodule Axon.Display do
186186
%Parameter{shape: {:tuple, shapes}}, acc ->
187187
Enum.reduce(shapes, acc, &(Nx.size(apply(&1, input_shapes)) + &2))
188188

189+
%Parameter{template: %Nx.Tensor{} = template}, acc ->
190+
acc + Nx.size(template)
191+
189192
%Parameter{template: shape_fn}, acc when is_function(shape_fn) ->
190193
acc + Nx.size(apply(shape_fn, input_shapes))
191194
end)
@@ -253,6 +256,11 @@ defmodule Axon.Display do
253256

254257
"#{name}: tuple#{inspect(shapes)}"
255258

259+
%Parameter{name: name, template: %Nx.Tensor{} = template} ->
260+
type = Nx.type(template)
261+
shape = Nx.shape(template)
262+
"#{name}: #{type_str(type)}#{shape_string(shape)}"
263+
256264
%Parameter{name: name, template: shape_fn} when is_function(shape_fn) ->
257265
shape = Nx.shape(apply(shape_fn, input_shapes))
258266
"#{name}: #{type_str(type)}#{shape_string(shape)}"

test/axon/display_test.exs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule Axon.DisplayTest do
2+
use ExUnit.Case, async: true
3+
4+
describe "as_table/2" do
5+
test "renders layers with concrete parameter templates" do
6+
model = Axon.input("input") |> Axon.dense(32)
7+
input = Nx.template({1, 16}, :f32)
8+
9+
table = Axon.Display.as_table(model, input)
10+
11+
assert table =~ ~s|dense_0 ( dense )|
12+
assert table =~ ~s|kernel: f32[16][32]|
13+
assert table =~ ~s|bias: f32[32]|
14+
assert table =~ ~s|Total Parameters: 544|
15+
assert table =~ ~s|Total Parameters Memory: 2.18 kilobytes|
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)