Skip to content

Add docs for serialization with NX.serialize#630

Merged
polvalente merged 1 commit intoelixir-nx:mainfrom
aphillipo:ap-serialization-docs
Mar 11, 2026
Merged

Add docs for serialization with NX.serialize#630
polvalente merged 1 commit intoelixir-nx:mainfrom
aphillipo:ap-serialization-docs

Conversation

@aphillipo
Copy link
Copy Markdown
Contributor

@aphillipo aphillipo commented Mar 5, 2026

  • Added docs for Nx.serialize with examples.
  • Removed link to non-working onnx docs (axon_onnx needs updating)
  • Added tests
  • Updated CHANGELOG for 0.7 to explain what's happened (debatable if this is necessary)

@aphillipo
Copy link
Copy Markdown
Contributor Author

aphillipo commented Mar 5, 2026

You are obviously welcome to rip this apart but it's a decent start, I might have a go at updating axon_onnx at some point.

Comment on lines +115 to +135
## Resuming from a Checkpoint

To resume training from a saved checkpoint:

1. Load the checkpoint with `Axon.Loop.deserialize_state/2`
2. Attach it to your loop with `Axon.Loop.from_state/2`
3. Run the loop as usual

```elixir
# Load the checkpoint (use the path from your checkpoint files)
checkpoint_path = "checkpoints/checkpoint_2_50.ckpt"
serialized = File.read!(checkpoint_path)
state = Axon.Loop.deserialize_state(serialized)

# Resume training
model =
Axon.input("data")
|> Axon.dense(8)
|> Axon.relu()
|> Axon.dense(1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@seanmor5 I think there's a bit of a dissonance between not having Axon.serialize/deserialize, while checkpoints need their Axon functions. WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TBC

@aphillipo aphillipo force-pushed the ap-serialization-docs branch 2 times, most recently from 1071994 to 748da9d Compare March 11, 2026 23:29
@aphillipo
Copy link
Copy Markdown
Contributor Author

aphillipo commented Mar 11, 2026

Okay thanks for the review @polvalente 🙏🏻 I agree that is does seem weird we have special functions for checkpointing, it would be nice to use Nx.serialize but probably there needs to be some context around the checkpointing I assume?

@polvalente
Copy link
Copy Markdown
Contributor

@aphillipo Agreed. We can go ahead with this PR regardless of the checkpointing issue, and we can revisit that later on.
Thansk a lot for the contribution

@aphillipo aphillipo force-pushed the ap-serialization-docs branch from bb28eab to 3e8e59b Compare March 11, 2026 23:40
@aphillipo
Copy link
Copy Markdown
Contributor Author

aphillipo commented Mar 11, 2026

Okay just fixed formatting issue, should be good to go. Thanks for Axon, I want to play with it more and redo the machine learning course I did in Python in it. It's a good test.

@polvalente polvalente merged commit 6f80783 into elixir-nx:main Mar 11, 2026
5 checks passed
@aphillipo aphillipo deleted the ap-serialization-docs branch March 11, 2026 23:56
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.

2 participants