Skip to content
Merged
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
22 changes: 20 additions & 2 deletions lib/axon/display.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ defmodule Axon.Display do
%Axon.Node{
id: id,
op_name: :container,
parent: [parents],
parent: [_ | _] = parents,
name: name_fn
},
nodes,
Expand Down Expand Up @@ -221,6 +221,13 @@ defmodule Axon.Display do
"#{type}#{shape}"
end

defp render_output_shape(shapes) when is_tuple(shapes) do
shapes
|> Tuple.to_list()
|> Enum.map(&render_output_shape(&1))
|> Enum.join(", ")
end

defp type_str({type, size}), do: "#{Atom.to_string(type)}#{size}"

defp render_options(opts) do
Expand Down Expand Up @@ -347,7 +354,9 @@ defmodule Axon.Display do

name = name_fn.(op, op_counts)
node_shape = Axon.get_output_shape(%Axon{output: id, nodes: nodes}, templates)
to_node = %{axon: :axon, id: id, op: op, name: name, shape: node_shape}
shape = expand_output_shape(node_shape)

to_node = %{axon: :axon, id: id, op: op, name: name, shape: shape}

new_edgelist =
Enum.reduce(node_inputs, edgelist, fn from_node, acc ->
Expand All @@ -357,6 +366,15 @@ defmodule Axon.Display do
{to_node, {cache, op_counts, new_edgelist}}
end

defp expand_output_shape(%Nx.Tensor{} = tensor), do: Nx.shape(tensor)

defp expand_output_shape(shapes) when is_tuple(shapes) do
shapes
|> Tuple.to_list()
|> Enum.map(&expand_output_shape/1)
|> List.to_tuple()
end

defp generate_mermaid_node_entry(%{id: id, op: :input, name: name, shape: shape}) do
~s'#{id}[/"#{name} (:input) #{inspect(shape)}"/]'
end
Expand Down
Loading