djaouen

djaouen

Getting Batches To Work With Axon

I have been struggling with this problem for the past hour now, so hopefully someone here can help me. I am trying to pass in a batch to Axon, but I can’t seem to get it working correctly. I get the following error:

** (CompileError) /home/djaouen/.cache/mix/installs/elixir-1.15.4-erts-14.0.2/27fa3a4853b40b31af06054a5826b5ad/deps/axon/lib/axon/loop.ex:468: the do-block in while must return tensors with the same shape, type, and names as the initial arguments.

Body matches template:
<snip>

But for the life of me, I can’t figure out why. I think it has something to do with my batches not being the correct shape? However, I really don’t know if that’s the problem or not. You can find the Livebook (and the associated stocks.zip file) in my repository here: GitHub - danieljaouen/stocks

I know this is probably a lot of debugging for someone to take on, so if you are busy, please don’t waste your time, but if you have a spare hour or two to help me out with this, I would greatly appreciate it. Thanks! :slight_smile:

Most Liked

djaouen

djaouen

Could it be that my data goes from :f64 to :f32 at some point in the model? How can I force it to use :f64 at every stage of the pipeline?

+-----------------------------------------------------------------------------------------------------------------+
|                                                      Model                                                      |
+=====================================+===============+==============+=====================+======================+
| Layer                               | Input Shape   | Output Shape | Options             | Parameters           |
+=====================================+===============+==============+=====================+======================+
| predictors ( input )                | []            | {32, 30, 3}  | shape: {nil, 30, 3} |                      |
|                                     |               |              | optional: false     |                      |
+-------------------------------------+---------------+--------------+---------------------+----------------------+
| flatten_0 ( flatten["predictors"] ) | [{32, 30, 3}] | {32, 90}     |                     |                      |
+-------------------------------------+---------------+--------------+---------------------+----------------------+
| dense_0 ( dense["flatten_0"] )      | [{32, 90}]    | {32, 128}    |                     | kernel: f32[90][128] |
|                                     |               |              |                     | bias: f32[128]       |
+-------------------------------------+---------------+--------------+---------------------+----------------------+
| relu_0 ( relu["dense_0"] )          | [{32, 128}]   | {32, 128}    |                     |                      |
+-------------------------------------+---------------+--------------+---------------------+----------------------+
| dense_1 ( dense["relu_0"] )         | [{32, 128}]   | {32, 1}      |                     | kernel: f32[128][1]  |
|                                     |               |              |                     | bias: f32[1]         |
+-------------------------------------+---------------+--------------+---------------------+----------------------+
Total Parameters: 11777
Total Parameters Memory: 47108 bytes

Here is the full error, in case that helps. As you can see, the data starts out as :f64, but becomes :f32 at the dense_0 layer in the pipeline (or at least, I think? Not really sure as there is also a dense_0 that shows :f64):

** (CompileError) /home/djaouen/.cache/mix/installs/elixir-1.15.4-erts-14.0.2/27fa3a4853b40b31af06054a5826b5ad/deps/axon/lib/axon/loop.ex:468: the do-block in while must return tensors with the same shape, type, and names as the initial arguments.

Body matches template:

{%{"dense_0" => %{"bias" => #Nx.Tensor<
       f64[128]
     >, "kernel" => #Nx.Tensor<
       f64[90][128]
     >}, "dense_1" => %{"bias" => #Nx.Tensor<
       f64[1]
     >, "kernel" => #Nx.Tensor<
       f64[128][1]
     >}}, %{"dense_0" => %{"bias" => #Nx.Tensor<
       f32[128]
     >, "kernel" => #Nx.Tensor<
       f32[90][128]
     >}, "dense_1" => %{"bias" => #Nx.Tensor<
       f32[1]
     >, "kernel" => #Nx.Tensor<
       f32[128][1]
     >}}, %{}, {%{scale: #Nx.Tensor<
      f32
    >}, %{count: #Nx.Tensor<
      s64
    >, nu: %{"dense_0" => %{"bias" => #Nx.Tensor<
          f64[128]
        >, "kernel" => #Nx.Tensor<
          f64[90][128]
        >}, "dense_1" => %{"bias" => #Nx.Tensor<
          f64[1]
        >, "kernel" => #Nx.Tensor<
          f64[128][1]
        >}}, mu: %{"dense_0" => %{"bias" => #Nx.Tensor<
          f64[128]
        >, "kernel" => #Nx.Tensor<
          f64[90][128]
        >}, "dense_1" => %{"bias" => #Nx.Tensor<
          f64[1]
        >, "kernel" => #Nx.Tensor<
          f64[128][1]
        >}}}}, %{"dense_0" => %{"bias" => #Nx.Tensor<
       f64[128]
     >, "kernel" => #Nx.Tensor<
       f64[90][128]
     >}, "dense_1" => %{"bias" => #Nx.Tensor<
       f64[1]
     >, "kernel" => #Nx.Tensor<
       f64[128][1]
     >}}, #Nx.Tensor<
   s64
 >, #Nx.Tensor<
   s64
 >}

and initial argument has template:

{%{"dense_0" => %{"bias" => #Nx.Tensor<
       f64[128]
     >, "kernel" => #Nx.Tensor<
       f64[90][128]
     >}, "dense_1" => %{"bias" => #Nx.Tensor<
       f64[1]
     >, "kernel" => #Nx.Tensor<
       f64[128][1]
     >}}, %{"dense_0" => %{"bias" => #Nx.Tensor<
       f32[128]
     >, "kernel" => #Nx.Tensor<
       f32[90][128]
     >}, "dense_1" => %{"bias" => #Nx.Tensor<
       f32[1]
     >, "kernel" => #Nx.Tensor<
       f32[128][1]
     >}}, %{}, {%{scale: #Nx.Tensor<
      f32
    >}, %{count: #Nx.Tensor<
      s64
    >, nu: %{"dense_0" => %{"bias" => #Nx.Tensor<
          f32[128]
        >, "kernel" => #Nx.Tensor<
          f32[90][128]
        >}, "dense_1" => %{"bias" => #Nx.Tensor<
          f32[1]
        >, "kernel" => #Nx.Tensor<
          f32[128][1]
        >}}, mu: %{"dense_0" => %{"bias" => #Nx.Tensor<
          f32[128]
        >, "kernel" => #Nx.Tensor<
          f32[90][128]
        >}, "dense_1" => %{"bias" => #Nx.Tensor<
          f32[1]
        >, "kernel" => #Nx.Tensor<
          f32[128][1]
        >}}}}, %{"dense_0" => %{"bias" => #Nx.Tensor<
       f32[128]
     >, "kernel" => #Nx.Tensor<
       f32[90][128]
     >}, "dense_1" => %{"bias" => #Nx.Tensor<
       f32[1]
     >, "kernel" => #Nx.Tensor<
       f32[128][1]
     >}}, #Nx.Tensor<
   s64
 >, #Nx.Tensor<
   s64
 >}

    (nx 0.5.3) lib/nx/defn/expr.ex:483: Nx.Defn.Expr.compatible_while!/4
    (nx 0.5.3) lib/nx/defn/expr.ex:354: Nx.Defn.Expr.defn_while/6
    (axon 0.5.1) lib/axon/loop.ex:468: Axon.Loop."__defn:accumulate_gradients__"/8
    (axon 0.5.1) lib/axon/loop.ex:420: anonymous fn/6 in Axon.Loop.train_step/4
    (axon 0.5.1) lib/axon/loop.ex:1925: anonymous fn/6 in Axon.Loop.build_batch_fn/2
    (nx 0.5.3) lib/nx/defn/compiler.ex:158: Nx.Defn.Compiler.runtime_fun/3
    (exla 0.5.3) lib/exla/defn.ex:385: anonymous fn/4 in EXLA.Defn.compile/8
    (exla 0.5.3) lib/exla/defn/locked_cache.ex:36: EXLA.Defn.LockedCache.run/2

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement