pipeline¶
Walkthrough: How a run works.
Responsibility¶
User entry point (
ExplainRunner), configuration schema, the orchestration of one explain run, re-scoring of an archive, and the result and manifest types.
Public surface¶
Signatures: Public API; configuration keys: Config keys.
ExplainConfig:backend,generationandexplanationsections.BudgetConfigtakesfractionorevaluations, never both; only the key that is set is serialised, so a fraction-only configuration keeps its Run id (Absolute budget passed to samplers as an exact fraction).ExplanationConfigcross-field rules raiseConfigError:exactneedsbudget.fraction: 1.0,complementaryandneyman_ccneed the Shapley estimand,neyman_ccrefusesinclude_minimal_masks.explain_config_from_yamlraisesConfigErrorfor an invalid, empty or non-mapping document.ExplainRunner:explain,explain_sync(aRuntimeErrorinside a running loop),reanalyze;close,acloseand both context managers close an injected backend and the runner’s own event loop.ExplainOrchestrator.run(): the data flow below.score_coalitionsfits aFittableValueFunctionon base plus coalitions and scores each coalition;reanalyzeuses it too.reanalyze_sync(Reanalyze): for a run scored with backend embeddings and aRequiresEmbeddingsvalue function it logs aWARNING, or raisesReanalyzeMismatchErrorwithstrict; aRequiresLogprobsvalue function on rows without logprobs raisesReanalyzeMismatchError.ExplainResult;ExplainRunOutputwithto_dict()(ExplainRunPayload; each label addsspeakerandlabel, the span’sdisplay_label);player_setisNoneafterreanalyze.RunManifest,parse_manifest,MANIFEST_SCHEMA_VERSION4 (Manifest):embedding_sourceis"none","hash"or"backend"; wrong field types raiseArchiveCorruptError.deletion_curve(config, snapshot, attributions, ks=None, registry=None, backend=None)(async): ranks players, runs the pipeline with a private estimator that samplesN - top_kperkon a registry copy, and returnsDeletionCurve(values,drops, trapezoidareaoverk / n).ExplainContext: resolved inputs of one run;plugin_context()builds thePluginContext.
Data flow¶
ExplainRunner._build_contextchecks plugin options, resolves the partitioner, refuses a plan above2 ** max_playerscoalitions and sets the Run id from the configuration without its archive section plus the model id.Without an injected backend the runner builds one through plugins
instantiate_backendand closes it after the call.The orchestrator resolves the plugins. A
RequiresLogprobsvalue function on a backend withoutSupportsLogprobsraisesConfigError(logprob value). ARequiresEmbeddingsvalue function switchesgeneration.compute_embeddingson; the archive opens with the manifest.It generates the Base generation and writes it to the archive first.
It samples masks with
budget_fraction(n, fraction, evaluations)from estimation and adds a missing empty or grand coalition; the base text isv(N). ASupportsKvCachebackend gets its prefix cache enabled, and the metrics count only this run’s hits.It plans
(mask, coalition key, prefix hash)per mask, sorted by prefix hash only withkv_cache.enabled; the runtime scheduler consumes lazily rendered jobs, and records come back by coalition key in mask order.score_coalitionsscores records built withgeneration_record_from_text(text)plus the backend’s logprobs, kept per coalition key in the store. Hash vectors depend on the text only, so the records equal whatreanalyzebuilds from the archived text and logprobs.A
TwoPhaseEstimatorgetsbegin_allocation(masks, payoffs); phase-two masks run the same way and every coalition is rescored on the joint corpus.It records
embedding_source("backend"when a backend vector differs from the hash vector, else"hash"when embeddings are scored), marks the archive complete, aggregates withestimator.estimate_attributions, normalises and logs each stage atINFO.
Invariants¶
The empty and grand coalitions are always evaluated;
sum(values) == grand_value - base_valuefor Shapley on the full table.Payoffs are aligned with masks whatever order the scheduler ran the jobs in (C11).
The base generation is in the archive before any coalition row; an archive is marked complete only after every coalition of both phases is stored.
reanalyzerefuses a different estimator, absence policy or partition (ReanalyzeMismatchError). It raisesArchiveIncompleteErrorfor a foreign or unfinished archive, a missing boundary coalition, or missing rows under a full-table budget.explainandreanalyzescore identical records for a run without model embeddings (C15).
Known issues¶
Fixed: C01, C02, C04, C08, C11, C15, D01 (Fixed issues).