mbtorch-io-formats

Guide model serialization across ONNX, safetensors, and .mbt formats.

1|Updated Mar 7, 2026
One-click install
npx skills add https://github.com/c-tomioka/mbtorch --skill mbtorch-io-formats
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mbtorch-io-formats
Source: https://github.com/c-tomioka/mbtorch/tree/main/.claude/skills/mbtorch-io-formats
Command: npx skills add https://github.com/c-tomioka/mbtorch --skill mbtorch-io-formats

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill defines design, validation, and testing guidance for MbTorch model input/output so that ONNX, safetensors, and the native .mbt format are parsed and emitted safely, deterministically, and without silent compatibility regressions or corrupted tensors.

Core Features & Use Cases

  • Format isolation: keep all format-specific parsing and serialization inside io/ and ensure core tensor and nn modules remain format-agnostic.
  • Strict validation & fail-fast behavior: verify magic bytes, header structure, version/opset compatibility, and tensor offsets before mapping binary buffers to memory.
  • Explicit error taxonomy: surface precise errors (e.g., InvalidMagicBytes, UnsupportedOpset, HeaderMismatch, TensorShapeMismatch) with file path, format, version, and remedial hints.
  • DTO-based intermediate representation: translate file formats into I/O-specific metadata structures before converting to nn.Model or core.Tensor to minimize coupling.
  • .mbt format and versioning rules: two-part layout (magic + JSON metadata + binary blobs), required metadata fields, and clear version bump/migration procedures.
  • Testing strategy: require ONNX parity tests, safetensors header/data checks, .mbt round-trip and version compatibility tests, plus corruption and unsupported-version cases.
  • Use case: when importing an ONNX model or saving a model for edge distribution, use these rules to avoid mismatched shapes, unsupported ops, or silently corrupted weights.

Quick Start

Enable mbtorch-io-formats when modifying any io/ loader or writer and add a parity or round-trip test that fails if metadata, shapes, dtype, or outputs diverge.

Frequently Asked Questions about mbtorch-io-formats

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely serialize and deserialize models across ONNX, safetensors, and .mbt formats?

Model serialization and deserialization across ONNX, safetensors, and .mbt formats requires isolating format-specific parsing inside an io/ directory and using a DTO intermediate representation to translate file formats into core objects without silent compatibility regressions.

Why does loading a model fail with invalid magic bytes or unsupported opset errors?

Invalid magic bytes or unsupported opset errors occur because strict validation enforces fail-fast behavior, verifying header structure, version compatibility, and tensor offsets before mapping binary buffers to memory to prevent corrupted weights.

What is the best way to handle backward and forward compatibility for model I/O formats?

Backward and forward compatibility for model I/O formats is achieved by defining a two-part .mbt layout with magic bytes and JSON metadata, establishing clear version bump and migration procedures, and maintaining mandatory parity and round-trip test suites.

How do I test ONNX import and safetensors export for parity and corruption handling?

Testing ONNX import and safetensors export for parity requires implementing mandatory test suites that fail if metadata, shapes, dtypes, or outputs diverge, and including specific test cases for corruption handling and unsupported version scenarios.

Does MbTorch support converting ONNX models to the native .mbt format without shape mismatches?

MbTorch supports converting ONNX models to the native .mbt format without shape mismatches by using an explicit error taxonomy with precise errors like TensorShapeMismatch and applying strict validation checks during the DTO-based intermediate translation process.