Commit Graph
6 Commits
Author SHA1 Message Date
nghianguyenandClaude Opus 5 ea877a61bc fix(keys): decide at configure time whether this build has the key
Whether the model-package key is present was an __has_include test
inside the header, and that test leaves no dependency for the build
system. A key emitted after a build had already compiled the file would
not take effect until someone cleaned, and the resulting engine looks
exactly like one built without a key — which on a release machine means
shipping an engine that silently cannot open a package.

CMake now decides it and says which case it is, so emitting the key and
re-configuring is what installs it, visibly.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-13 05:56:58 +10:00
nghianguyenandClaude Opus 5 3c9e0b79f5 fix(ANSModelPackage): read the head off the graph, not off the package's word
A package whose family says "yolo" may hold an end-to-end export. Boxes
took the family from the backend marker, and the marker names the
runtime, not the head — so a fast yolo26 export arrived declared as
plain yolo while its graph emits [1, N, 6] with the NMS inside it.
Decoding that as a [1, 4+nc, N] grid reads coordinates as confidences:
detections everywhere, and nothing that looks like a failure.

OpenModelPackage now reads the first output's dims from the model it has
just decrypted, and corrects the family with the reason in the warning
rather than swapping it silently. It costs nothing there: the bytes are
in hand. The legacy marker is left alone, so anything converting back to
a zip still writes what ANSCORE expects.

A two-class v8 export is [1, 6, 8400] and must not be mistaken for one,
which is why the 6 has to be the last axis with a detection count before
it. Both cases are tested, and the package this Mac exported before the
writer was fixed now reads as yolo10 here too. 46 checks, no failures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-13 00:19:15 +10:00
nghianguyenandClaude Opus 5 c82b2a67bc feat(ANSModelPackage): take the base key the ceremony gives this build
The reader has been able to open packages for a while and has held no
key, so it refused all of them. This is the seam that hands it one.

The base private key is not in this repository and never will be. It is
written by the ceremony (ANSMINDCORE's ansmodel-keys) into a generated
header that is gitignored and produced from the key vault on the machine
that builds a release. ANSModelKeys.h uses that file when it is there
and says "no keys" when it is not, so a developer's checkout builds and
runs with no secret in it: every zip still loads, and a package is
refused with a sentence that says why.

Keys are settled once — what the build carries, plus a developer's
environment — unless a caller sets a keyring outright, which now means
exactly that rather than depending on which call ran first.

Checked with the real keys against the packages ANSMINDCORE's side
produced: a package sealed by a box that holds only the public half
opens here byte for byte, and one signed by the new release key verifies
against the built-in root. If those two products disagreed, a model that
runs in one would not run in the other, which is the failure this format
exists to avoid. 40 checks in the package test, no failures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 23:05:00 +10:00
nghianguyenandClaude Opus 5 8e50120759 feat(ANSModelPackage): ask the model its input size when nothing else says
A package now carries what its model expects on the input, but every
package written before that does not — and neither does the zip, which
is most of what is in the field. The engine was then left to assume
640x640, which is wrong for a classification export at 224 and for
anything trained at a rectangular size.

The model itself always knows. ANSOnnxShape reads the first input's
shape straight out of the ONNX protobuf, from memory or from a file,
walking the top level and SEEKING past the nodes and the initializers
rather than reading them — the fields it wants sit after all of the
weight on the wire, and a 324 MB model answers in ten milliseconds.

OpenModelPackage uses it only when the manifest is silent, which costs
nothing there because the bytes are already decrypted in hand. An axis
the graph leaves open is reported as zero and a file that cannot be
parsed is a failure: both mean "this model does not say", and the caller
keeps the default it had. Being wrong about an input size would be worse
than being silent about it.

Checked against python-onnx on all 46 models on this machine, static and
dynamic, four-dimensional and not, with no disagreements. The test
writes ONNX graphs byte by byte, with node and initializer ahead of the
input as a real export has them, and packs one into a package whose
manifest says nothing — which is the case this exists for. 40 checks,
no failures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 22:47:47 +10:00
nghianguyenandClaude Opus 5 080910c8ac feat(ODEngine): open a model package and run it without unpacking it
An engine's model has always been a path to a password-protected zip:
ANSODBase inflates it into a folder, and every engine then picks out
train_last.onnx, classes.names and model_config.json. A .ansmodel
package replaces all four with one sealed file, and this is the part
that turns it back into what the engines already understand.

ANSODBase::LoadModel and ::Initialize now recognise a .ansmodel path and
take a second route: the package is opened with the process keyring, the
model is decrypted into memory, and the classes, task and input geometry
come out of the manifest instead of loose files. Nothing is extracted,
so the unprotected model never touches the disk — which is the reason
the format exists, and it is one function's job to keep.

The engines follow it down. BasicOrtHandler gains a constructor that
takes the bytes rather than a path; it keeps a view of them, not a copy,
because the weights are in RAM either way once a session exists and a
copy would only double what every loaded model costs. The owner of the
plaintext is ANSODBase, which holds it for as long as the engine object
lives — that is what lets the DirectML recovery path rebuild a session
after a driver fault — and wipes it on teardown.

Wired through ANSONNXYOLO (and so the classification facade), ANSONNXOBB,
ANSONNXPOSE, ANSONNXSEG and YOLO12OD. YOLOOD is left alone: it loads
darknet weights and OpenCV DNN graphs, neither of which the writer
produces. A zip still loads exactly as before, on every engine.

Keys come from SetProcessModelKeys, as in ANSMINDCORE, with the same
development fallback from the environment. With none set, a package is
refused with a sentence saying so and every zip still works, so a build
made before the key ceremony runs everything except packages.

The engine layer needs CUDA to compile, so the contract it depends on is
checked where it can be: ANSModelPackage-UnitTest now opens the fixture
ANSMINDCORE wrote through the same glue ANSODBase uses, and covers the
refusal a keyless build gives. 32 checks, no failures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 22:21:39 +10:00
nghianguyenandClaude Opus 5 6c164c3d0f feat(ANSModelPackage): read the ANS model package here too
The second reader. A package is one encrypted file — cleartext header,
sealed manifest, model bytes sealed in chunks — and this opens it: the
content key unwrapped with X25519 against the base key, the header
verified as Ed25519 signed by a release key the root vouches for, the
model decrypted into memory and handed to ANSModelSource, which the
engines already take.

It is a new library rather than code inside the engine layer, and
deliberately free of the heavy dependencies around it: no CUDA, no
OpenCV, no LabVIEW. That is what lets it build and be tested on every
platform, including the ones where the engine layer does not build.

THE TWO IMPLEMENTATIONS MUST AGREE, so this does not merely claim to:
tests/ANSModelPackage-UnitTest/data/interop.ansmodel was written by
ANSMINDCORE's packer, and the test opens it here — manifest, classes and
a chunked payload, byte for byte. A change to either wire format shows
up as this failing. The fixture's keys are derived by published rules,
recorded beside it, so anyone can rebuild it.

The AEAD and the small primitives are copies of ANSMINDCORE's, not
reimplementations, for the same reason. Monocypher 4.0.2 is vendored
here as it is there, including the RFC 8032 pair — its default EdDSA
signs with BLAKE2b and would not interoperate.

Verified by compiling and running the test directly: 19 checks, RFC
8439, RFC 7748 and RFC 8032 vectors, the interop fixture, a round trip,
a flipped bit, an unknown root, a revoked signer, and rubbish bytes.
ANSCORE's own CMake configure fails on this machine for reasons that
predate this change — eight errors with or without it, all missing
dependencies — so the new CMake targets still need a real build box.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 21:24:53 +10:00