mladapter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 4 Imported by: ? 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.

Documentation

Overview

Package mladapter adapts src/ctn/contract/model (low-level tensor inference) into src/ctn/contract/inference (high-level generation, embeddings, transcription, synthesis).

src/ctn/contract/model owns raw tensor inference through a caller-selected provider. src/ctn/contract/inference owns the portable, transport-free inference contract. This package bridges them: it wraps an ml.Provider as an inference.Provider, applying explicit preprocessing and postprocessing for each operation.

Raw tensor inference must not pretend automatically to be text generation or content interpretation. Each operation requires an explicit preprocessor (request → tensors) and postprocessor (tensors → response).

Package mladapter adapts src/ctn/contract/model (low-level tensor inference) into src/ctn/contract/inference (high-level generation, embeddings, transcription, synthesis).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MLProvider

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

MLProvider wraps an ml.Provider as an inference.Provider. Each supported operation is bound to a model reference and a pair of pre/post processors. Operations that are not bound return inference.ErrUnsupported.

The wrapped ml.Provider and ml.Store are owned by the caller. Close only releases sessions created by this adapter.

func NewMLProvider

func NewMLProvider(store *ml.Store, p ml.Provider, info inference.ProviderInfo) *MLProvider

NewMLProvider wraps p as an inference.Provider backed by store for model resolution. info is the provider metadata reported by Info. No operations are supported until BindGenerate, BindEmbed, BindTranscribe, or BindSynthesize is called.

func (*MLProvider) BindEmbed

BindEmbed binds the Embed operation to an ml model.

func (*MLProvider) BindGenerate

BindGenerate binds the Generate operation to an ml model. pre converts a GenerationRequest into ml tensors; post converts output tensors into a GenerationResponse.

func (*MLProvider) BindSynthesize

BindSynthesize binds the Synthesize operation to an ml model. Synthesis produces a stream of audio bytes.

func (*MLProvider) BindTranscribe

BindTranscribe binds the Transcribe operation to an ml model.

func (*MLProvider) Close

func (a *MLProvider) Close() error

Close releases all sessions owned by this adapter. It does not close the wrapped ml.Provider or ml.Store (the caller owns them).

func (*MLProvider) Embed

Embed returns embeddings for the inputs through the bound ml model.

func (*MLProvider) Generate

Generate runs one generation pass through the bound ml model.

func (*MLProvider) Info

Info returns provider metadata.

func (*MLProvider) Models

func (a *MLProvider) Models(ctx context.Context) ([]inference.ModelInfo, error)

Models is not supported by raw ml provider metadata. Use ModelLister only via a remote provider adapter that supports model listing.

func (*MLProvider) Stream

Stream is not supported by raw ml tensor inference. Use Streamer only via a remote provider adapter that supports streaming.

func (*MLProvider) Synthesize

Synthesize synthesizes text to audio through the bound ml model.

func (*MLProvider) Transcribe

Transcribe transcribes audio through the bound ml model.

type Postprocessor

type Postprocessor[Resp any] interface {
	Postprocess(ctx context.Context, outputs []ml.Tensor) (Resp, error)
}

Postprocessor converts src/ctn/contract/model output tensors into a src/ctn/contract/inference response. The implementation is responsible for model-specific decoding (detokenization, embedding normalization, etc.) and must honor ctx for cancellation.

func FuncPostprocessor

func FuncPostprocessor[Resp any](fn func(context.Context, []ml.Tensor) (Resp, error)) Postprocessor[Resp]

FuncPostprocessor builds a Postprocessor from a function.

type Preprocessor

type Preprocessor[Req any] interface {
	Preprocess(ctx context.Context, req Req) ([]ml.Tensor, error)
}

Preprocessor converts a src/ctn/contract/inference request into src/ctn/contract/model tensors. The implementation is responsible for model-specific encoding (tokenization, feature extraction, etc.) and must honor ctx for cancellation.

func FuncPreprocessor

func FuncPreprocessor[Req any](fn func(context.Context, Req) ([]ml.Tensor, error)) Preprocessor[Req]

FuncPreprocessor builds a Preprocessor from a function.

Jump to

Keyboard shortcuts

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