djaouen

djaouen

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 · GitHub

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 OP

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

Last Post!

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews