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.