Skip to main content

Crate el_runtime

Crate el_runtime 

Source
Expand description

el-runtime — the Core: inference session lifecycle, the port traits that the collaborator contexts plug into, and the decode-loop orchestrator (ADR-001). Air-gap is structural (ADR-004): this crate has no network dependency, and the only outbound seam is the opt-in ports::HybridRelay.

The decode step composes collaborators in a fixed, invariant order (docs/ddd/domain-events.md): grammar mask → safety adjust → sample → commit, so safety steering only ever operates over already-legal tokens.

Structs§

AllowAllMasker
Allow-all grammar — every token legal (used when no schema is registered).
AnchorGuard
SafetyMode::Lightweight chunk guard — training-free token-anchor heuristics (no weights), the ChunkGuard counterpart of LightweightFilter. Each pattern is an unsafe token-id n-gram; the guard adds per_hit milli-units for every pattern that occurs as a contiguous subslice of the scored window, saturating at SafetyScore::MAX.
Checkpoint
A safe-prefix snapshot for rollback (ADR-012). Stores only indices: rollback truncates KV descriptors (KvRegion::truncate) and never replays prefill, and the KV payload is never copied (ADR-002/ADR-003).
CheckpointManager
A bounded ring of guard-verified safe-prefix checkpoints. Fixed memory: the oldest checkpoint is dropped once cap is reached (ADR-003). A cap of 0 (or disable) retains nothing — the loop then has no rollback target and fails closed on a breach.
ContrastiveSteerer
SafetyMode::SecDecoding (or model-backed Lightweight) steerer (ADR-013): a hard-ban layer applied every step plus contrastive soft steering from an ExpertLogits source applied only when the runtime supplies base logits (i.e. inside the early-token window). With no expert divergence it reduces to the hard-ban behaviour of LightweightFilter; with no bans and a flat expert it is a no-op.
IdentityCompressor
Identity compressor — passes the prompt through unchanged.
InferenceSession
One live generation. Constructing it requires a LoadPermit, so a model that has not passed the provenance gate (ADR-006) cannot reach the runtime — the Conformist relationship is enforced in the type system.
LightweightFilter
SafetyMode::Lightweight — a training-free blacklist filter (real). Banned tokens receive a very large negative logit so they cannot be sampled.
LogitAdjustment
A vector subtracted from target logits to steer away from unsafe output. Sparse and integer (milli-logits) for deterministic, allocation-light steps.
NoSafety
SafetyMode::Off — a no-op steerer.
NullEngine
A trivial engine that emits EOS immediately after prefill. Lets you exercise the full session lifecycle without the Candle adapter (ADR-002 is the real engine). Not for production inference.
Ports
The collaborator ports bound to a session. relay is None by default — air-gapped.
RollbackPolicy
Cadence and bounds for the checkpointed-rollback control loop (ADR-012), chosen per device tier so cost scales with the hardware budget (ADR-003).
SafetyModeSelector
Chooses the affordable mode for the device (ADR-005).
SafetyScore
Risk score in milli-units, 0 (safe) ..= 1000 (max). Integer for deterministic, float-free safety decisions (ADR-008).

Traits§

ChunkGuard
Scores recent generated output for risk (ADR-012 chunk guard). Reuses the active tier’s safety model; like every safety path it is deterministic and never touches the network (ADR-004).
ExpertLogits
Safety-tuned next-token logits for the committed context, in integer milli-logits over the same vocabulary and tokenizer as the base generator (the ADR-012 shared-tokenizer invariant — the contrastive direction is only meaningful when base and expert share a token set). The expert weights are integrity-gated on load (ADR-006) by the adapter that constructs the implementor; like every safety path this is deterministic and never touches the network (ADR-004).
GrammarMasker
Grammar Constraint port (llguidance — context 4). Returns a per-token allow mask of length vocab; true = legal this step.
HybridRelay
Opt-in LAN relay (ADR-004 HybridMode). Implementations MUST stay on the local network — there is no cloud variant.
InferenceEngine
The inference engine adapter (RuntimeAcl). Implemented for real by Candle in the excluded adapter el-engine-candle (ADR-002).
PromptCompressor
Prompt Compression port (LLMLingua-2 — context 2).
SafetySteerer
Per-step safety intervention. The runtime applies this after the grammar mask and before sampling.

Functions§

contrastive_adjustment
SafeDecoding-style contrastive adjustment (ADR-013): steer toward the safety expert and away from the base — final = base + α·(expert − base) — returned as additive milli-logit penalties consumed after the grammar mask, before sampling (the ADR-005 order is unchanged).