Loss registry¶
LossRegistry is the per-compiled-module table mapping
attachment sites (program names, deduction names, encoder /
decoder names, rule names, chart sites, global) to weighted
scalar-loss callables.
The training driver calls LossRegistry.evaluate(env) to sum
every registered loss; evaluate_on(kind, target, env,
rule_deduction) returns the weighted partial sum filtered to
a single attachment site.
Loss bodies are compiled by the QVR compiler as let-expression
closures of signature (env) -> Tensor. The env for a global
loss includes the compiled module's program / deduction /
encoder / decoder bindings as top-level names; for
rule-attached losses, the env also carries "rule",
"deduction", "antecedents", "conclusion", and "weight"
keys populated by the agenda's rule-firing callback.
losses
¶
Loss attachment registry.
Holds the table of weighted scalar losses declared in a compiled module, keyed by attachment site, so the training driver can evaluate the right ones at the right point in the training step.
LossEntry
dataclass
¶
LossEntry(name: str, body: LossBody, weight: LossWeight | None = None, attachment_kind: AttachmentKind = 'global', target: str | None = None, rule_deduction: str | None = None)
One registered loss.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
Diagnostic identifier (the DSL name).
TYPE:
|
body |
Computes the scalar loss given a training-step environment.
TYPE:
|
weight |
Computes a scalar multiplier given the same environment, or
TYPE:
|
attachment_kind |
Where this loss fires (see
TYPE:
|
target |
Name of the attachment target (program / deduction / encoder / decoder / chart / rule).
TYPE:
|
rule_deduction |
For
TYPE:
|
LossRegistry
dataclass
¶
LossRegistry(entries: list[LossEntry] = list())
All losses declared in a compiled module.
evaluate
¶
evaluate(env: Mapping[str, TrainEnv] | None = None) -> Tensor
Sum all registered losses, weighted, under env.
Source code in src/quivers/structural/losses.py
90 91 92 93 94 95 | |
evaluate_on
¶
evaluate_on(kind: AttachmentKind, target: str | None = None, env: Mapping[str, TrainEnv] | None = None, rule_deduction: str | None = None) -> Tensor
Sum only the losses whose attachment matches the filter.
kind selects the attachment kind; target filters by
attachment target (the program / deduction / encoder /
decoder / rule name); rule_deduction further narrows the
"rule" kind to a specific enclosing deduction.
Source code in src/quivers/structural/losses.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |