model

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Tensor model plugin bridge

pkg/ext-go/model binds res/int/model to the language-neutral Ext plugin contract model.tensor/v1. A guest serves the infer operation over the Ext JSON-line transport. Its request contains an absolute model-store root, a provider/name@version reference, and 1 to 64 float32 tensors. The response contains 1 to 64 float32 tensors. Tensor bytes are JSON base64; one call allows at most 16 MiB of raw input or output tensor data. Larger tensors need a future stream or shared-memory transport. The JSON request and response fixtures are in testdata/v1.

Go guests can register an ml.Provider with RegisterProvider, then call ServeCurrentExecutable. The guest reopens and verifies the model bundle on each call. Non-Go guests can implement the same descriptor and JSON payloads. The host must choose a sealed package and record an exact scoped trust digest. The guest's ID and version must match the values used when packaging it.

CTN's flow is:

ctn model provider package onnxruntime 1.0.0 /path/to/provider /path/to/package
ctn model provider install /path/to/package
ctn model provider list
ctn model provider trust onnxruntime
ctn model run --provider onnxruntime /absolute/model-store \
  onnxruntime/model@v1 /path/to/tensors.json
ctn model provider untrust onnxruntime

tensors.json is {"tensors":[{"shape":[1,2],"format":"float32","data":"...base64..."}]}. model run returns the same shape with output tensors, or writes it to a new file with --output FILE. A test guest exercises packaging, trust, process transport, model verification, and tensor output end to end. Platform SDKs provide CoreML, TensorFlow Lite, and ONNX Runtime implementations. On macOS, res/int/model/ios also builds ext-coreml-guest, a Swift guest that connects the CoreML backend to this contract. Package it as ID coreml, version 1.0.0. res/int/model/windows/Guest publishes a self-contained Windows ONNX guest as ID onnxruntime, version 1.0.0; res/int/model/linux/Guest publishes the same protocol for Linux. pkg/ext-android offers ModelTensorGuest.create to bind a caller-selected MlProvider to this contract in an app-hosted guest. CTN can launch it when an Android application supplies a process entry point.

Documentation

Overview

Package ml bridges res/int/model tensor providers to the Ext plugin contract. The wire contract is language-neutral; this package supplies Go host and guest helpers. A host still chooses and trusts a sealed provider package.

Index

Constants

View Source
const ContractName = "model.tensor"
View Source
const ContractVersion = "v1"
View Source
const MaxWireTensorBytes = 16 << 20
View Source
const Protocol = ContractName + "/" + ContractVersion

Variables

View Source
var ContractRef = plugin.ContractRef{Name: ContractName, Version: ContractVersion}

Functions

func PackageExecutable

func PackageExecutable(options ExecutablePackage) (packagekit.Manifest, error)

PackageExecutable seals a model.tensor/v1 guest without installing it.

func RegisterProvider

func RegisterProvider(registry *author.Registry, provider domain.Provider, authorize func(context.Context, plugin.Request) error) (*plugin.Descriptor, error)

RegisterProvider serves a selected native provider. The guest reopens and verifies the model bundle on every call, and closes the native session. The authorize callback must enforce guest-side access policy.

func ServeCurrentExecutable

func ServeCurrentExecutable(ctx context.Context, id, version string, provider domain.Provider, authorize func(context.Context, plugin.Request) error) error

ServeCurrentExecutable binds the guest identity to the running executable.

func ServeStdio

func ServeStdio(ctx context.Context, id plugin.Identity, provider domain.Provider, authorize func(context.Context, plugin.Request) error) error

ServeStdio exposes one explicitly selected provider over Ext JSON-line.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client calls a model.tensor/v1 guest through an already authorized session.

func NewClient

func NewClient(caller author.Caller) *Client

func (*Client) Infer

func (c *Client) Infer(ctx context.Context, request InferRequest) (InferResponse, error)

type ExecutablePackage

type ExecutablePackage struct {
	ID, Version, Binary, OutputDir, OS, Arch string
}

type InferRequest

type InferRequest struct {
	Root      string          `json:"root"`
	Reference string          `json:"reference"`
	Inputs    []domain.Tensor `json:"inputs"`
}

func (InferRequest) Validate

func (r InferRequest) Validate() error

type InferResponse

type InferResponse struct {
	Outputs []domain.Tensor `json:"outputs"`
}

func (InferResponse) Validate

func (r InferResponse) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL