Documentation
¶
Overview ¶
Package graph builds a topologically sorted execution plan from a loaded ONNX model.
Index ¶
- Variables
- func ApplyAllFusions(g *Graph) map[string]int
- func MustRegisterFusion(name string, apply FusionFunc)
- func RegisterFusion(name string, apply FusionFunc) error
- func RegisteredFusions() []string
- func UnregisterFusion(name string) error
- type ExecutionNode
- type FusionFunc
- type Graph
- type InputInfo
- type OutputInfo
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCyclicGraph indicates that the computation graph contains a // cyclic dependency that prevents topological sorting. ErrCyclicGraph = errors.New("graph: cyclic dependency detected") // ErrUnresolvedInput indicates that a node references an input name // that is not a graph input, initializer, or output of another node. ErrUnresolvedInput = errors.New("graph: unresolved input") // ErrBuildFailed indicates a general failure during graph // construction, such as an initializer weight conversion error. ErrBuildFailed = errors.New("graph: build failed") // ErrEmptyFusionName indicates RegisterFusion was called with an // empty name. Fusion names must be unique non-empty strings so // the registry can address them. ErrEmptyFusionName = errors.New("graph: empty fusion name") // ErrNilFusion indicates RegisterFusion was called with a nil // FusionFunc. ErrNilFusion = errors.New("graph: nil fusion function") // ErrFusionExists indicates RegisterFusion was called with a name // that is already in use. ErrFusionExists = errors.New("graph: fusion already registered") // ErrFusionNotFound indicates UnregisterFusion was called for a // name that is not in the registry. ErrFusionNotFound = errors.New("graph: fusion not found") )
Sentinel errors returned by the graph builder.
Functions ¶
func ApplyAllFusions ¶
ApplyAllFusions runs every registered fusion against g in registration order. It returns a map keyed by fusion name carrying the number of fusions performed by each pass; callers may use the map for logging or metrics. A nil g returns an empty map and no error.
func MustRegisterFusion ¶
func MustRegisterFusion(name string, apply FusionFunc)
MustRegisterFusion is the panicking variant of RegisterFusion intended for init() blocks. The same caveat that applies to ops.MustRegister applies here: registration is a one-shot startup operation, so a duplicate or nil registration is always a programmer error.
func RegisterFusion ¶
func RegisterFusion(name string, apply FusionFunc) error
RegisterFusion adds apply to the list of fusions that ApplyAllFusions invokes. It returns an error if name is empty, apply is nil, or a fusion is already registered under that name. The order in which fusions are registered determines the order in which ApplyAllFusions runs them.
func RegisteredFusions ¶
func RegisteredFusions() []string
RegisteredFusions returns the names of every fusion currently in the registry in registration order. The returned slice is a copy and safe to mutate.
func UnregisterFusion ¶
UnregisterFusion removes the named fusion from the registry. It is primarily intended for tests that need to isolate fusion behaviour. It returns an error if name is empty or no fusion is registered under that name.
Types ¶
type ExecutionNode ¶
type ExecutionNode struct {
OpType string
Name string
InputNames []string
OutputNames []string
Attributes map[string]*onnx.Attribute
}
ExecutionNode is a thin projection of an onnx.Node containing only the fields needed by the executor. Attributes is the same map pointer from the source node (no deep copy).
type FusionFunc ¶
FusionFunc applies a single graph rewrite pass in place and returns the number of nodes the pass fused. A return value of zero is normal and means the pattern did not match anywhere; it is not an error.
type Graph ¶
type Graph struct {
ExecutionOrder []*ExecutionNode
Inputs []InputInfo
Outputs []OutputInfo
Weights map[string]*tensor.Tensor
}
Graph is a read-only execution plan built from an ONNX model. It holds nodes in topological order, filtered runtime inputs, graph outputs, and converted initializer weights.
type InputInfo ¶
InputInfo describes a runtime graph input with its name, shape (converted to []int), and element data type.
type OutputInfo ¶
OutputInfo describes a graph output with its name and shape (converted to []int).
Directories
¶
| Path | Synopsis |
|---|---|
|
fusion
|
|
|
concatwrite
Package concatwrite registers the (producer-Conv → Concat) tail fusion.
|
Package concatwrite registers the (producer-Conv → Concat) tail fusion. |
|
conv1x1pair
Package conv1x1pair registers the 1×1 Conv pair fusion.
|
Package conv1x1pair registers the 1×1 Conv pair fusion. |
|
convleakyrelu
Package convleakyrelu registers the Conv → LeakyReLU fusion.
|
Package convleakyrelu registers the Conv → LeakyReLU fusion. |
|
convprelu
Package convprelu registers the Conv → PReLU fusion.
|
Package convprelu registers the Conv → PReLU fusion. |
|
muladd
Package muladd registers the Mul → Add fusion.
|
Package muladd registers the Mul → Add fusion. |
|
pixelshuffle
Package pixelshuffle registers the PyTorch pixel-shuffle graph rewrite (Reshape → Transpose → Reshape → single DepthToSpace).
|
Package pixelshuffle registers the PyTorch pixel-shuffle graph rewrite (Reshape → Transpose → Reshape → single DepthToSpace). |