Skip to content

solvi.core.deciders.backends

The encoders: ONNX and torch scorers, tokenizing, file fingerprints.

Part of solvi.core.deciders, which re-exports every name; import from there.

The encoders: ONNX and torch scorers, tokenizing with block masks, file fingerprints. (Part of solvi.core.deciders, which re-exports every name.)

LongInputWarning

Bases: UserWarning

long="full": a checkpoint forced to read long inputs it was not trained on, or whole long texts read on a CPU. Without long=: an input that does not fit the pass was read cut (the decision's extra["truncated"] says how much).

SharedQuestionWarning

Bases: UserWarning

Two decision parts of one model ask the same question (task and options) and one of them has a LoRA adapter: adapters are kept per part, so the other part is scored without it (named once per pair of parts).

BlockUnsupported

Bases: ValueError

The scorer cannot run the block layout at all (e.g. an ONNX export without its inputs): one question per sequence.

OnnxScorer

OnnxScorer(path, max_len=512, device=None, onnx_file=None, bs=16, caps=None)

Bases: _NetScorer

onnxruntime session over onnx/model_*.onnx (inputs input_ids, attention_mask; output logits [B, L, C]). The block layout needs an export with the inputs position_ids, full_attention_mask and sliding_attention_mask ([B, 1, L, L] bool); without them several questions fall back to one per pass.

TorchScorer

TorchScorer(path, max_len=512, device=None, bs=16, caps=None)

Bases: _NetScorer

The checkpoint's encoder (transformers AutoModel from config.json) + the option head, weights from model.safetensors. The block layout passes per-layer-type attention masks and position ids (sdpa attention).

inputs

inputs(ids, att, pids=None, masks=None, device=None)

Packed arrays (see pack) → the network's inputs as tensors on device (default: the scorer's).

block_masks

block_masks(blk, pids, window)

blk [B, L] (−1 input, j ≥ 0 block j, −2 padding), pids [B, L] → (full, sliding) boolean masks [B, 1, L, L] (True = may attend): the input sees only the input, block j sees the input and itself, blocks do not see each other; the sliding (local) layers also need |pos_i − pos_j| ≤ window. Padding rows see themselves only.