Documentation
Getting Started
Download the oam.py library to start working with OAM models in Python.
from oam import OAM
# Load a model
model = OAM.load("my_model.oam")
# Access metadata
print(model.metadata)
File Format Specification
The .oam format is a binary container designed for zero-overhead parsing.
Header
Magic bytes 'OAM1' (4 bytes)
Metadata Block
Length (4 bytes) + JSON Payload. Contains model name, params, architecture type.
Weights Block
Length (4 bytes) + JSON Payload. Contains the full model weights.
Training
OAM supports any model architecture.
Example model file
OAM1
{metadata json}
{weights binary}
Feel free to reimplement the logic/parser in any way you want, perhaps you would rather store the weights in json too, or in base64, the core of OEM is to store the model in a way that can be easily parsed by any language as well as containing the full model in a single file.
Example implementation
import json
import struct
import os
import datetime
class OAM:
def __init__(self):
self.metadata = {
"created_at": datetime.datetime.now().isoformat(),
"model_name": "Unknown",
"description": "OAM Model",
"params_count": 0,
"params_count_readable": "0",
"layers": 0,
"architecture": "custom"
}
self.vocab = {}
self.weights = {}
def save(self, filepath):
meta_bytes = json.dumps(self.metadata).encode('utf-8')
vocab_bytes = json.dumps(self.vocab).encode('utf-8')
weights_bytes = json.dumps(self.weights).encode('utf-8')
with open(filepath, 'wb') as f:
f.write(b'OAM1')
f.write(struct.pack('I', len(meta_bytes)))
f.write(meta_bytes)
f.write(struct.pack('I', len(vocab_bytes)))
f.write(vocab_bytes)
f.write(struct.pack('I', len(weights_bytes)))
f.write(weights_bytes)
@staticmethod
def load(filepath):
model = OAM()
with open(filepath, 'rb') as f:
magic = f.read(4)
if magic != b'OAM1':
raise ValueError("Invalid OAM file format")
meta_len = struct.unpack('I', f.read(4))[0]
model.metadata = json.loads(f.read(meta_len).decode('utf-8'))
vocab_len = struct.unpack('I', f.read(4))[0]
model.vocab = json.loads(f.read(vocab_len).decode('utf-8'))
weights_len = struct.unpack('I', f.read(4))[0]
model.weights = json.loads(f.read(weights_len).decode('utf-8'))
return model