DEDUPED Hot AI repos, turned into use cases Get the Monday 5

How to export a trained Sequential model to ONNX with Tensai

Train a Sequential model in Tensai, then marshal it to ONNX with the encoding/onnx package.

Short answer: Build a small Sequential model from the layer package and train it with Compile and Fit; then call the marshal function in the encoding/onnx package on the trained model and write the bytes to a .onnx file; load the file in onnxruntime and run the same input through it. All steps.

Who it is forA developer who trains a small model in Go and needs to run it in onnxruntime or another ONNX consumer.

The problemTrained Go models are stuck in Go unless they can be exported to a standard format.

The outcomeAn ONNX file (opset 13, FP32) whose outputs match Tensai Predict to about 1e-7 relative error.

What you need first

  • Go toolchain (Go 1.26 or 1.27 is needed only for the GOEXPERIMENT=simd build)
  • git to clone the repository
  • Disk space for model checkpoints when using the image, audio, or embedding commands

Steps

  1. Build a small Sequential model from the layer package and train it with Compile and Fit. (inferred, check the README)
  2. Call the marshal function in the encoding/onnx package on the trained model and write the bytes to a .onnx file. (inferred, check the README)
  3. Load the file in onnxruntime and run the same input through it. (inferred, check the README)
  4. Compare the onnxruntime output with Predict on the same input and confirm the relative error is near 1e-7.

Prompt for your agent

In the mattn/tensai repository, train a small Sequential model, export it with encoding/onnx, and run the file in onnxruntime. Report the maximum relative error between Predict and onnxruntime outputs. Verify that the error is about 1e-7 or below.

Caveat. The README says onnxruntime reproduces Predict to about 1e-7 relative error but does not name the exact marshal function, so the function call above is inferred.

Use this in your AI agent

Ask your agent

Using the Deduped MCP, get the setup steps for mattn/tensai and "Export a trained Sequential model to ONNX"

Add Deduped to Claude Code once

claude mcp add --transport http deduped https://dedupedai.com/mcp

Cursor, ChatGPT, others

Share: X LinkedIn Hacker News Email Copy link

Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer