opake-alignment
Functional, mechanism-agnostic primitives for DP-safe preference learning:
per-example loss functions (DPO / SFT families), log-probability helpers, preference
collators, dataset transforms, reference-model helpers, alignment metrics, and
memory-efficient fused-linear twins (fused_nll_loss / fused_dft_loss /
fused_sequence_logp) that project hidden states through the lm_head via the
optional opake-patches linear-CE kernel.
Built on opake-engine (clipping, functional, distributed) and opake-base
(serialization). Consumed by both functional training scripts
(examples/train_dpo.py-style) and the TRL-style class trainers in
opake.transformers.trl.
Design
- Functional, no hidden state. Every public symbol is a pure function, a
factory returning a callable, or an inert dataclass — no
nn.Modulesubclasses, no user-instantiated classes.vmap(grad(...))composes cleanly only over pure functions. - Mechanism-agnostic. Depends only on the substrate packages
(
opake-engine,opake-base); never onopake-dpsgd,opake-dpftrl, oropake-optimizers. The DP mechanism and optimizer are chosen at the call site. - Per-example API. Public losses map each record to its own scalar and
compose with
vmap(grad(...)); this does not imply family-wide locality verification. Batch-coupled Tier 3 variants are not shipped. - Direct functions, no registry. Each method exposes its loss functions
directly (
dpo_sigmoid,nll_loss, …) — there is no string registry, resolver, or variant enum. A config-string consumer (trainer / CLI) builds its own name→function mapping at the call site (seeexamples/train_dpo.py).
Import layout
Method-first, mirroring opake.dpsgd / opake.dpftrl: each method owns its
primitives under its own namespace.
opake.alignment <- top-level façade (dpo, sft, data, metric)
opake.api.alignment <- implementation namespace
opake.alignment.dpo <- DPO method façade (aggregates the below)
opake.alignment.dpo.loss <- logp + 14 per-pair heads + log-ratio combinators
opake.alignment.dpo.collator <- preference (DPO) collator factory
opake.alignment.dpo.reference <- ref-logp precompute, null_ref_context, EMA
opake.alignment.dpo.metric <- preference reward telemetry
opake.alignment.dpo.data <- preference prompt extraction
opake.alignment.sft.loss <- nll_loss, dft_loss + fused_nll_loss, fused_dft_loss
opake.alignment.sft.collator <- language-modeling (SFT) collator
opake.alignment.data <- chat-template prep + completion-mask tokenization
opake.alignment.metric <- shared token metrics (accuracy, entropy)
opake.alignment.dpo.loss is the DPO loss-construction toolkit: the per-sequence
log-prob primitives sequence_logp / fused_sequence_logp, the 14 per-pair
heads, and the log-ratio combinators all live there (a per_example_loss is
head(sequence_logp(...) - ref_logp, …)). The lower-level selective_log_softmax
building block, entropy_from_logits / mean_token_accuracy (token metrics), and
chat-template helpers stay internal impl under opake.api.alignment.*, surfaced
through the method that consumes them, following the shared-impl re-import pattern of
opake.dpsgd.clipping.
Metadata
Release files for opake-alignment 0.16.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| opake_alignment-0.16.1-py3-none-any.whl | Python 3 | none | any | Details |
Release files / opake_alignment-0.16.1-py3-none-any.whl
| Download URL | opake_alignment-0.16.1-py3-none-any.whl |
|---|---|
| Size | 88.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
792ef00c1ac268c6ad25709d5c945e34e61be1b0d9d5ecacf24fb23e5c7faebd
|
|
BLAKE2b-256 checksum How to use checksums |
8bf0b448093ea5255da52cf5c5bd27d190e00227b1270ebeaab36d07c9134306
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency log