instmodel
This repo is meant to be used with coding agents, not read manually.
Build and train small neural networks with PyTorch or TensorFlow/Keras through one shared graph API, then export them to a compact JSON "instruction model" that runs anywhere with plain NumPy (or the Rust/C++ inference ports) — no training framework needed at inference time.
Install
pip install instmodel # NumPy inference only
pip install instmodel[pytorch] # + PyTorch training backend (instmodel.torch)
pip install instmodel[tensorflow] # + TensorFlow/Keras training backend (instmodel.tf)
Example
import numpy as np
from instmodel.torch import Dense, InputBuffer, ModelGraph # same API in instmodel.tf
from instmodel.instruction_model import instruction_model_inference
x = InputBuffer(4)
y = Dense(1, activation="sigmoid")(Dense(8, activation="relu")(x))
model = ModelGraph(x, y)
model.compile(optimizer="adam", loss="binary_crossentropy")
model.fit(np.random.rand(64, 4), np.random.randint(0, 2, (64, 1)), epochs=5, verbose=0)
exported = model.create_instruction_model() # JSON-serialisable dict
print(instruction_model_inference(exported, np.random.rand(3, 4))[-1])
Sequence models
instmodel.sequence trains small causal transformers and exports them as an instruction model
that processes one token per run. The attention caches are explicit state owned by the caller,
so any runtime can decode token by token (NumPy here, or SequenceModel in the Rust port).
import numpy as np
from instmodel import sequence
from instmodel.sequence import torch as backend # same API in instmodel.sequence.tf
config = sequence.TransformerConfig(vocab_size=16, width=16, heads=4, kv_heads=2)
model = backend.Transformer(config, members=2) # two copies trained in one batch
start = np.random.randint(0, 16, (4096, 1))
tokens = (start + np.arange(13)) % 16 # rows [N, time + 1]; learn "next = token + 1"
rows = dict(tokens=backend.torch.as_tensor(tokens), groups=backend.torch.zeros(4096, 12, dtype=int))
trainer = backend.Trainer(model, rows, batch=64, lr=3e-3, ema=0.99)
for step in range(400):
trainer.step(backend.schedule(step / 400, 3e-3))
exported = sequence.export_step_model(config, trainer.averaged().member_parameters(0))
session = sequence.SequenceSession(exported) # keeps the key/value cache between steps
print(session.step([3]).argmax(-1)) # -> [4]
TransformerConfig also covers grouped-query attention, looped (weight-shared) passes and
SegmentFeatures; sequence_loss takes per-position groups, allowed-token masks and soft targets.
add_validation_sequences stores reference logits in the file for other runtimes to replay.
License
Metadata
Release files for instmodel 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| instmodel-1.4.0.tar.gz | 48.0 kB | With provenance | Details for instmodel-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| instmodel-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for instmodel-1.4.0-py3-none-any.whl |
Total release size: 90.1 kB
Release files / instmodel-1.4.0.tar.gz
| Download URL | instmodel-1.4.0.tar.gz |
|---|---|
| Size | 48.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7732a76039883a50769e82bc76e07df39c95cfc343b58c1909da9c8ae3f704e
|
|
BLAKE2b-256 checksum How to use checksums |
5723e8af023040ffe21a701f9be2dea5e6f43985d326ca918c6f6fe8b4e9233e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / instmodel-1.4.0-py3-none-any.whl
| Download URL | instmodel-1.4.0-py3-none-any.whl |
|---|---|
| Size | 42.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d5dc5ed941291e27f29cc29bbb7a2e706b323d16780d7f2b421f6f9ef63c6da5
|
|
BLAKE2b-256 checksum How to use checksums |
44a7b4d0d33608869a509c4c9ff5a167f8367a8fb3b3e3b7800c7c446fbbbdcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for instmodel 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for instmodel-1.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.