Skip to content

Conversation

@dimamik
Copy link

@dimamik dimamik commented Oct 28, 2025

Fixes all compile-time warnings for Elixir 1.19.1:

==> axon
Compiling 27 files (.ex)
     warning: incompatible types given to Kernel.apply/2:

         apply(Axon.Initializers, [])

     given types:

         Axon.Initializers, empty_list()

     but expected one of:

         fun(), list(term())

     typing violation found at:
     │
 135 │                 apply(Axon.Initializers, [])
     │                 ~
     │
     └─ lib/axon/quantization.ex:135:17: Axon.Quantization.weight_only_quantized_dense/3

    warning: Tuple.append/2 is deprecated. Use insert_at instead
    │
 49 │     Nx.reshape(scales, Tuple.append(ones, :auto))
    │                              ~
    │
    └─ lib/axon/quantization/layers.ex:49:30: Axon.Quantization.Layers.reshape_scales/2
    └─ lib/axon/quantization/layers.ex:54:23: Axon.Quantization.Layers.reshape_output/2

    warning: got "@impl true" for function __stream__/7 but no behaviour specifies such callback. The known callbacks are:

      * Nx.Defn.Compiler.__compile__/4 (function)
      * Nx.Defn.Compiler.__jit__/5 (function)
      * Nx.Defn.Compiler.__partitions_options__/1 (function)
      * Nx.Defn.Compiler.__to_backend__/1 (function)

    │
 18 │   def __stream__(_, _, _, _, _, _, _), do: raise("not implemented")
    │   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ lib/axon/defn.ex:18: Axon.Defn (module)

      warning: a struct for Axon.Loop.State is expected on struct update:

          %Axon.Loop.State{
            state
            | epoch: epoch + 1,
              metrics: zero_metrics,
              iteration: 0,
              max_iteration: state.max_iteration
          }

      but got type:

          dynamic()

      where "state" was given the type:

          # type: dynamic()
          # from: lib/axon/loop.ex
          {:continue, state}

      when defining the variable "state", you must also pattern match on "%Axon.Loop.State{}".

      hint: given pattern matching is enough to catch typing errors, you may optionally convert the struct update into a map update. For example, instead of:

          user = some_function()
          %User{user | name: "John Doe"}

      it is enough to write:

          %User{} = user = some_function()
          %{user | name: "John Doe"}

      typing violation found at:
      │
 1695 │ ...                   %State{
      │                       ~
      │
      └─ lib/axon/loop.ex:1695:29: Axon.Loop.run/4

      warning: a struct for Axon.Loop.State is expected on struct update:

          %Axon.Loop.State{state | epoch: epoch + 1, iteration: 0}

      but got type:

          dynamic(%{..., epoch: term(), metrics: term()})

      where "state" was given the type:

          # type: dynamic(%{..., epoch: term(), metrics: term()})
          # from: lib/axon/loop.ex
          {:halt_epoch, %{epoch: epoch, metrics: metrics} = state}

      when defining the variable "state", you must also pattern match on "%Axon.Loop.State{}".

      hint: given pattern matching is enough to catch typing errors, you may optionally convert the struct update into a map update. For example, instead of:

          user = some_function()
          %User{user | name: "John Doe"}

      it is enough to write:

          %User{} = user = some_function()
          %{user | name: "John Doe"}

      typing violation found at:
      │
 1927 │         {:cont, {batch_fn, final_metrics_map, %State{state | epoch: epoch + 1, iteration: 0}}}
      │                                               ~
      │
      └─ lib/axon/loop.ex:1927:47: Axon.Loop.halt_epoch/5

Generated axon app

@josevalim
Copy link
Contributor

Woot, it found an actual bug :)

Comment on lines +17 to 26
package: package()
]
end

def cli do
[
docs: :docs,
"hex.publish": :docs
]
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I this change correct for < 1.19?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure honestly, isn't this local-only thing and just a pure function otherwise? I thought it won't break even if not supported

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We suport this for a few versions already and yes, it won't break users.

@dimamik
Copy link
Author

dimamik commented Oct 30, 2025

@josevalim

Woot, it found an actual bug :)

Can you elaborate more? The code seems legit...

@josevalim
Copy link
Contributor

@dimamik I meant this warning is an actual bug:

     warning: incompatible types given to Kernel.apply/2:

         apply(Axon.Initializers, [])

     given types:

         Axon.Initializers, empty_list()

     but expected one of:

         fun(), list(term())

     typing violation found at:
     │
 135 │                 apply(Axon.Initializers, [])
     │                 ~
     │
     └─ lib/axon/quantization.ex:135:17: Axon.Quantization.weight_only_quantized_dense/3

It needs to be fixed. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants