Types¶
Abstract Values¶
- class autoform.extend.AVal[source]¶
Base class for abstract values used by traced programs.
Abstract values carry trace-time information about runtime values. Extension domains subclass
AValto describe the information primitive abstract rules need, such as shape, dtype, schema, or other static metadata.Example
>>> import autoform.extend as afe >>> class ArrayAVal(afe.AVal): ... def __init__(self, shape, dtype): ... self.shape = shape ... self.dtype = dtype
- class autoform.extend.StrAVal[source]¶
Abstract value for
strleaves.Example
>>> import autoform as af >>> ir = af.trace(lambda x: x)("x") >>> (x,) = ir.in_ir_tree >>> x.aval StrAVal()
- class autoform.extend.IntAVal[source]¶
Abstract value for
intleaves.Example
>>> import autoform as af >>> ir = af.trace(lambda x: x)(1) >>> (x,) = ir.in_ir_tree >>> x.aval IntAVal()
Primitives¶
- class autoform.extend.Prim(name)[source]¶
Primitive operation key used by interpreter rule registries.
A primitive has no behavior by itself. Runtime, abstract, batching, and AD behavior are attached by registering rules keyed by the
Priminstance.- Parameters:
name (str) – The name of the primitive.
Example
>>> import autoform.extend as afe >>> add = afe.Prim("add")
- class autoform.extend.Zero(aval, /)[source]¶
Symbolic zero cotangent for an abstract value.
Zerokeeps reverse-mode and pushforward rules from materializing a concrete zero until one is actually needed. Usematerialize()to replace symbolic zeros with concrete values.Example
>>> import autoform.extend as afe >>> z = afe.Zero(afe.StrAVal()) >>> afe.materialize(z) ''
- Parameters:
aval (T)
IR¶
- class autoform.extend.IR(ir_eqns, in_ir_tree, out_ir_tree)[source]¶
A traced AutoForm program.
An
IRcontains the ordered equations produced by tracing, plus the input and output IR trees that describe how runtime arguments and results are structured. Extension transforms may construct newIRvalues when they rewrite or wrap a program.
- class autoform.extend.IREqn(prim, in_ir_tree, out_ir_tree, params=None, tags=frozenset({}))[source]¶
One primitive application inside an
IR.An equation records the primitive to execute, the IR-shaped input and output trees, static primitive parameters, and the tags active when the equation was traced. Calling
bind()executes the primitive under those tags.- Parameters:
prim (Prim) – Primitive represented by this equation.
in_ir_tree (Tree) – Input tree containing IR variables and concrete literals.
out_ir_tree (Tree) – Output tree containing IR variables and concrete literals.
params (dict[str, Any] | None) – Static parameters passed to the primitive rule.
tags (frozenset[Hashable]) – Tags associated with this equation.
Interpreters¶
- class autoform.extend.Interpreter[source]¶
Base class for runtime primitive interpreters.
Subclass
Interpreterto build an execution-time extension context. A custom interpreter usually stores the currentactive_interpreteras its parent, overridesinterpretandainterpretto handle new primitives.