Skip to main content

Module prism

Module prism 

Source
Expand description

Prism/Bonsai signed FWHT activation boundary.

Prism matrices carry an explicit signed-Hadamard activation boundary: the source checkpoint folds D·H into every forward matrix and stores the embedding twin in the inverse basis. Keep the transform in one small module so CPU fallback, tests, and GPU paths share one typed header.

Functions§

forward
Transform an activation row before a forward Prism matrix: x·D·H. The source contract requests an f16 boundary after the FWHT; keeping that cast here makes the CPU implementation agree with the trained MLX path.
forward_weight
Apply the forward basis only to a manifest-listed matrix. This is the mixed-profile counterpart of forward: ordinary q2tp may retain q4tp for attention/down projections, but those matrices are still stored in the same signed-Hadamard basis as the production Prism profile.
has_contract
True when this tensor belongs to a Prism header, regardless of whether it is a forward or inverse matrix. GPU graph/device paths use this as a conservative safety gate because they do not carry the transform descriptor yet.
inverse_embedding
Transform a decoded embedding row back to the caller basis: z·H·D.
is_affine_target
Whether this exact canonical matrix carries the production affine correction. Ordinary Prism q2tp and non-Prism dtype16 remain the raw (c - 1.5) * s codec; no correction is inferred from the architecture name or from the tensor dtype alone.
is_forward_weight
Whether this named matrix is one of the source’s forward-basis weights. Vision tensors and auxiliary projections are intentionally not included.
is_inverse_embedding
The source manifest names are wrapper-qualified, while CMF stores the canonical runtime name. The embedding is the only inverse matrix in the Prism checkpoint; all other projections use forward activations.
perf_report
Aggregate the CPU-side signed-Hadamard work for one bounded benchmark. This is deliberately opt-in and does not sample or print in the hot path.
profile_report
Print cache/validation counters for a bounded benchmark. The report is opt-in so normal CLI output and production hot paths remain unchanged.