deeplog.circuit.lower.klay
Klay-direct lowering backend.
Used for a circuit whose structure a Klay semiring implements. An operator Klay
has no node for does not disqualify the circuit: the graph is cut there
(deeplog.circuit.split) and the rest still lowers here. Chains of
same-type associative ops are flattened into n-ary Klay nodes and
identity-constant children dropped, producing a shallow circuit.
Klay’s only constant primitives are true/false, so an arbitrary numeric
constant is carried as an input slot pre-filled with its value rather than as a
node — see lower_klay().
Classes
Expose a subset of an inner module's input slots as runtime inputs. |
Functions
|
Lower a circuit to a Klay-backed torch module. |
Module Contents
- class ConstantPrefillModule(
- inner: Module,
- n_total_slots: int,
- free_slot_indices: tuple[int, ...],
- constant_slot_values: dict[int, float],
Bases:
torch.nn.ModuleExpose a subset of an inner module’s input slots as runtime inputs.
The wrapped module expects
n_total_slotsinputs. The user-visible forward only takes a tensor whose last dim has sizelen(free_slot_indices)— those values are scattered into the free slots, and the remaining slots are filled fromconstant_slot_valueson every call.Useful whenever some inputs of an inner torch module are statically known constants (e.g. baked numeric labels, ablated features, pinned test inputs) and you don’t want to rebuild the inner module to drop them.
Wrap
innerso onlyfree_slot_indicesare user inputs.- forward(x)[source]
Scatter
xinto the free slots, prefill the rest with constants.
- lower_klay( ) DeepLogModule[source]
Lower a circuit to a Klay-backed torch module.
A boolean circuit’s negations are pushed down to its atoms first, by De Morgan’s laws, since Klay negates only those. Every reachable leaf gets an input slot. So does every reachable arbitrary-value constant node (
0.6intimes(p, 0.6)), because Klay has no constant primitive beyondtrue/false— but those slots are pre-filled with their values and dropped from the module’s input shape, so they never surface as runtime inputs. Klay evaluates the resulting circuit arithmetically, so a constant node shared by several parents (they are deduplicated by value) multiplies once per use, as written.