
ahamez
Machine Learning in Elixir: Chapter 1 doesn't work with Axon 0.7 (page 26)
Hello @seanmor5 ,
When upgrading Axon to 0.7, evaluation fails with:
** (ArgumentError) argument at position 3 is not compatible with compiled function template.
%{i: #Nx.Tensor<
s32
>, model_state: #Inspect.Error<
got Protocol.UndefinedError with message:
"""
protocol Enumerable not implemented for #Nx.Tensor<
f32[3]
> of type Nx.Defn.TemplateDiff (a struct). This protocol is implemented for the following type(s): Date.Range, Explorer.Series.Iterator, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Kino.Control, Kino.Input, Kino.JS.Live, List, Map, MapSet, Range, Stream, Table.Mapper, Table.Zipper
"""
while inspecting:
%{
data: %{
"dense_0" => %{
"bias" => #Nx.Tensor<
f32[3]
>,
"kernel" => #Nx.Tensor<
f32[4][3]
>
}
},
state: %{},
__struct__: Axon.ModelState,
parameters: %{"dense_0" => ["bias", "kernel"]},
frozen_parameters: %{}
}
Stacktrace:
(elixir 1.17.2) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir 1.17.2) lib/enum.ex:166: Enumerable.reduce/3
(elixir 1.17.2) lib/enum.ex:4423: Enum.reduce/3
(axon 0.7.0) lib/axon/model_state.ex:359: anonymous fn/2 in Inspect.Axon.ModelState.get_param_info/1
(stdlib 6.0) maps.erl:860: :maps.fold_1/4
(axon 0.7.0) lib/axon/model_state.ex:359: anonymous fn/2 in Inspect.Axon.ModelState.get_param_info/1
(stdlib 6.0) maps.erl:860: :maps.fold_1/4
(axon 0.7.0) lib/axon/model_state.ex:320: Inspect.Axon.ModelState.inspect/2
>, loss:
<<<<< Expected <<<<<
#Nx.Tensor<
f32
>
==========
#Nx.Tensor<
f64
>
>>>>> Argument >>>>>
, optimizer_state: {%{scale: #Nx.Tensor<
f32
>}}, loss_scale_state: %{}, y_true: #Nx.Tensor<
u8[120][3]
>, y_pred: #Nx.Tensor<
f64[120][3]
>}
(nx 0.9.1) lib/nx/defn.ex:342: anonymous fn/7 in Nx.Defn.compile_flatten/5
(nx 0.9.1) lib/nx/lazy_container.ex:73: anonymous fn/3 in Nx.LazyContainer.Map.traverse/3
(elixir 1.17.2) lib/enum.ex:1829: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(elixir 1.17.2) lib/enum.ex:1829: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(nx 0.9.1) lib/nx/lazy_container.ex:72: Nx.LazyContainer.Map.traverse/3
(nx 0.9.1) lib/nx/defn.ex:339: Nx.Defn.compile_flatten/5
(nx 0.9.1) lib/nx/defn.ex:331: anonymous fn/4 in Nx.Defn.compile/3
#cell:75r7qhxms33esmsj:5: (file)
It seems it’s a problem between the type of the iris dataset (:f64
) whereas :f32
is expected.
Marked As Solved

kubafu
I stumbled upon it too and fixed it with explicit conversion to :f32, i.e.
x_train =
train_data[@columns]
|> Nx.stack(axis: 1)
|> Nx.as_type(:f32)
y_train =
train_data["species"]
|> Nx.stack(axis: -1)
|> Nx.equal(Nx.iota({1, 3}, axis: -1))
x_test =
test_data[@columns]
|> Nx.stack(axis: 1)
|> Nx.as_type(:f32)
y_test =
test_data["species"]
|> Nx.stack(axis: -1)
|> Nx.equal(Nx.iota({1, 3}, axis: -1))
6
Also Liked

nunez
Cool! I updated it at the dataframe level since Nx still scares me.
cols = ~w(sepal_width sepal_length petal_length petal_width)
normalized_iris =
DF.mutate(
iris,
for col <- across(^cols) do
{col.name, Explorer.Series.cast((col - mean(col)) / standard_deviation(col), :f32)}
end
)
2
Popular Pragmatic Bookshelf topics

page 20: … protoc command…
I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New

Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’.
In particula...
New

Title: Web Development with Clojure, Third Edition - migrations/create not working: p159
When I execute the command:
user=> (create-...
New

Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display)
It looks like
.with_simple_console_no_bg(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New

The generated iex result below should list products instead of product for the metadata. (page 67)
iex> product = %Product{}
%Pento....
New

A Common-Sense Guide to Data Structures and Algorithms, Second Edition by Jay Wengrow @jaywengrow
Hi,
I have the paperback version of t...
New

I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New

Is the book’s epub format available to read on Google Play Books?
New

Modern front-end development for Rails, second edition - Struggling to get the first chapter to work
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New

Getting an error when installing the dependencies at the start of this chapter:
could not compile dependency :exla, "mix compile" failed...
New
Other popular topics

Any thoughts on Svelte?
Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New

I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New

Just done a fresh install of macOS Big Sur and on installing Erlang I am getting:
asdf install erlang 23.1.2
Configure failed.
checking ...
New

Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New

API 4
Path:
/user/following/
Method:
GET
Description:
Returns the list of all names of people whom the user follows
Response
[
{ ...
New

This is going to be a long an frequently posted thread.
While talking to a friend of mine who has taken data structure and algorithm cou...
New

I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New

Author Spotlight
Erin Dees
@undees
Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New

Will Swifties’ war on AI fakes spark a deepfake porn reckoning?
New

If you’re getting errors like this:
psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /emacs
- /haskell
- /onivim
- /svelte
- /typescript
- /crystal
- /c-plus-plus
- /kotlin
- /tailwind
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /ash
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /zig
- /scala
- /sublime-text
- /textmate
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /django
- /manjaro
- /spring
- /diversity
- /nodejs
- /lua
- /c
- /slackware
- /julia
- /markdown