onnx

package module
v0.0.0-...-69c7aec Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: MIT Imports: 9 Imported by: 1

README

onnx

A Go library for automatically downloading initializing the ONNX runtime.

Installation

go get -u github.com/joeychilson/onnx

Usage

package main

import (
	"context"
	"log"

	ort "github.com/yalue/onnxruntime_go"

	"github.com/joeychilson/onnx"
)

func main() {
	ctx := context.Background()

	runtime, err := onnx.New(ctx)
	if err != nil {
		log.Fatal(err)
	}
	runtime.Close()

	sessionOptions, err := ort.NewSessionOptions()
	if err != nil {
		log.Fatal(err)
	}
	defer sessionOptions.Destroy()

	session, err := ort.NewDynamicAdvancedSession(
		"model.onnx",
		[]string{"input_ids", "attention_mask"},
		[]string{"logits"},
		sessionOptions,
	)
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Runtime)

Option is a functional option for configuring Runtime

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL sets the base URL for downloading the ONNX Runtime library

func WithCachePath

func WithCachePath(path string) Option

WithCachePath sets the cache directory

func WithGPU

func WithGPU(enabled bool) Option

WithGPU enables downloading the GPU version of the ONNX Runtime library

func WithLibraryPath

func WithLibraryPath(path string) Option

WithLibraryPath sets a direct path to the ONNX Runtime library

func WithVersion

func WithVersion(version string) Option

WithVersion sets the ONNX Runtime version

type Runtime

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

Runtime manages ONNX Runtime initialization and configuration

func New

func New(ctx context.Context, opts ...Option) (*Runtime, error)

New creates a new ONNX Runtime manager

func (*Runtime) Close

func (r *Runtime) Close() error

Close cleans up ONNX Runtime resources

func (*Runtime) EnsureRuntime

func (r *Runtime) EnsureRuntime(ctx context.Context) (string, error)

EnsureRuntime downloads and extracts the ONNX Runtime library

func (*Runtime) RuntimeInfo

func (r *Runtime) RuntimeInfo() *RuntimeInfo

GetRuntimeInfo returns information about the current runtime

func (*Runtime) RuntimeURL

func (r *Runtime) RuntimeURL(info *RuntimeInfo) string

RuntimeURL returns the download URL for a specific runtime

func (*Runtime) Version

func (r *Runtime) Version() string

Version returns the current ONNX Runtime version

type RuntimeInfo

type RuntimeInfo struct {
	Version     string
	OS          string
	Arch        string
	GPU         bool
	LibraryName string
}

RuntimeInfo contains ONNX Runtime specific information

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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