export

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportONNX

func ExportONNX(model nn.Module, sampleInput *tensor.Tensor, filePath string) error

ExportONNX traces the module with sampleInput and writes an ONNX graph file to disk.

func ExportTorchScript

func ExportTorchScript(model nn.Module, sampleInput *tensor.Tensor, filePath string) error

ExportTorchScript traces a model and saves it as a TorchScript-compatible package in one call.

func SaveTorchScript

func SaveTorchScript(ts *TorchScriptModel, filePath string) error

SaveTorchScript writes the TorchScript model into a standard PKZip package (.pt format).

Types

type ONNXGraph

type ONNXGraph struct {
	Name         string           `json:"name"`
	Nodes        []ONNXNode       `json:"nodes"`
	Inputs       []ONNXTensorInfo `json:"inputs"`
	Outputs      []ONNXTensorInfo `json:"outputs"`
	Initializers []ONNXTensorInfo `json:"initializers"`
}

ONNXGraph holds nodes, inputs, outputs, and weight initializers.

type ONNXModel

type ONNXModel struct {
	IRVersion    int       `json:"ir_version"`
	ProducerName string    `json:"producer_name"`
	Graph        ONNXGraph `json:"graph"`
}

ONNXModel encapsulates an exported computational graph.

func TraceModule

func TraceModule(model nn.Module, sampleInput *tensor.Tensor) (*ONNXModel, error)

TraceModule executes a forward pass on sampleInput and constructs an ONNX computational graph.

type ONNXNode

type ONNXNode struct {
	OpType     string                 `json:"op_type"`
	Inputs     []string               `json:"inputs"`
	Outputs    []string               `json:"outputs"`
	Attributes map[string]interface{} `json:"attributes,omitempty"`
}

ONNXNode represents an operational node in an ONNX computation graph.

type ONNXTensorInfo

type ONNXTensorInfo struct {
	Name  string    `json:"name"`
	Shape []int     `json:"shape"`
	Data  []float32 `json:"data,omitempty"`
}

ONNXTensorInfo records shape and type for inputs, outputs, and initializers.

type TSNode

type TSNode struct {
	OpType  string   `json:"op"`
	Inputs  []string `json:"inputs"`
	Outputs []string `json:"outputs"`
}

TSNode represents a traced operation node in a TorchScript computation graph.

type TorchScriptModel

type TorchScriptModel struct {
	Name       string                    `json:"name"`
	Inputs     []string                  `json:"inputs"`
	Outputs    []string                  `json:"outputs"`
	Nodes      []TSNode                  `json:"nodes"`
	Parameters map[string]*tensor.Tensor `json:"-"`
}

TorchScriptModel holds the traced graph and weights for export.

func TraceTorchScript

func TraceTorchScript(model nn.Module, sampleInput *tensor.Tensor) (*TorchScriptModel, error)

TraceTorchScript executes a forward pass and traces the operation flow.

Jump to

Keyboard shortcuts

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