graph

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const TraceVersion = 1

TraceVersion is the canonical trace JSON schema version.

Variables

This section is empty.

Functions

func ActiveRev

func ActiveRev() uint64

ActiveRev bumps whenever SetActive is called.

func CaptureEnabled

func CaptureEnabled() bool

CaptureEnabled reports whether graph capture was requested.

func ClearActive

func ClearActive()

ClearActive removes the published graph and notifies graph UI clients.

func EnableCapture

func EnableCapture()

EnableCapture allows model code to record graph traces (e.g. from --graph).

func Register

func Register(api *echo.Echo)

Register mounts graph REST and websocket routes on api.

func SetActive

func SetActive(c *Collector)

SetActive publishes a collector for REST handlers (typically after Freeze).

Types

type Collector

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

Collector stores a stable graph and emits op events from real compute passes.

func Active

func Active() *Collector

Active returns the published collector, or nil.

func NewCollector

func NewCollector() *Collector

func (*Collector) DebugPrint

func (c *Collector) DebugPrint(u ui.UI)

DebugPrint writes trace JSON and derived DAG JSON to u.

func (*Collector) Export

func (c *Collector) Export() TraceData

Export returns a copy of the captured trace.

func (*Collector) Freeze

func (c *Collector) Freeze()

func (*Collector) Frozen

func (c *Collector) Frozen() bool

func (*Collector) NewInput

func (c *Collector) NewInput(label string, shape []int) ValueID

NewInput registers the graph input and returns its value id.

func (*Collector) Pop

func (c *Collector) Pop()

Pop leaves the current scope segment.

func (*Collector) Push

func (c *Collector) Push(name string)

Push enters a nested scope segment (e.g. network, layer0).

func (*Collector) RecordOp

func (c *Collector) RecordOp(kind, label, path string, inputs []ValueID, inShape, outShape, weightShape []int) ValueID

RecordOp records one forward op and returns its output value id.

func (*Collector) SetGroupLabel

func (c *Collector) SetGroupLabel(group string)

SetGroupLabel sets the grouped block base label (e.g. "transformer block").

func (*Collector) SetName

func (c *Collector) SetName(name string)

SetName sets the display name exported with the trace (e.g. "sigmoid", "qwen 1.5b").

type DAG

type DAG struct {
	Name       string    `json:"name,omitempty"`
	GroupLabel string    `json:"group_label,omitempty"`
	Nodes      []DAGNode `json:"nodes"`
	Edges      []DAGEdge `json:"edges"`
}

DAG is a derived view of TraceData for visualization.

func BuildDAG

func BuildDAG(trace TraceData) DAG

BuildDAG constructs a dataflow DAG from a frozen trace.

type DAGEdge

type DAGEdge struct {
	From string `json:"from"`
	To   string `json:"to"`
}

DAGEdge connects value → op or op → value.

type DAGNode

type DAGNode struct {
	ID          string `json:"id"`
	Kind        string `json:"kind"`
	Label       string `json:"label,omitempty"`
	Path        string `json:"path,omitempty"`
	Scope       string `json:"scope,omitempty"`
	Shape       []int  `json:"shape,omitempty"`
	WeightShape []int  `json:"weight_shape,omitempty"`
}

DAGNode is one vertex in the derived dataflow graph.

type Op

type Op struct {
	ID          string    `json:"id"`
	Kind        string    `json:"kind"`
	Label       string    `json:"label,omitempty"`
	Path        string    `json:"path,omitempty"` // layout hint: attn, ffn, residual
	Scope       string    `json:"scope,omitempty"`
	Inputs      []ValueID `json:"inputs,omitempty"`
	Output      ValueID   `json:"output,omitempty"`
	InShape     []int     `json:"in_shape,omitempty"`
	OutShape    []int     `json:"out_shape,omitempty"`
	WeightShape []int     `json:"weight_shape,omitempty"`
}

Op is one step in the execution trace (input, linear, add, ...).

type TraceData

type TraceData struct {
	Version    int    `json:"version"`
	Name       string `json:"name,omitempty"`
	GroupLabel string `json:"group_label,omitempty"`
	Ops        []Op   `json:"ops"`
}

TraceData is the exported canonical trace (DAG builder input).

type ValueID

type ValueID string

ValueID names one activation/tensor in the forward trace.

Jump to

Keyboard shortcuts

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