pipeline¶
Walkthrough: How a run works
Responsibility¶
Entry point (
ExplainRunner), configuration, orchestration of one run, re-scoring of an archive, result and manifest types.
Public surface¶
Signatures: Public API; keys: Config keys.
ExplainConfig:backend,generationandexplanationsections.BudgetConfigtakes one offraction,evaluationsandper_player. Unset keys,efficiency: noneandhierarchicalare not serialised, so older configurations keep their Run id (Absolute budget passed to samplers as an exact fraction).ExplanationConfigcross-field rules raiseConfigError:exactneedsbudget.fraction: 1.0,complementary,neyman_ccandleverageneed the Shapley estimand andkernel_banzhafBanzhaf.efficiency: additiveneeds Shapley withoutloo,hierarchicalthesentencesplayers,neyman_ccnoinclude_minimal_masks.explain_config_from_yamlraisesConfigErrorfor an invalid document.ExplainRunner:explain,explain_sync(aRuntimeErrorinside a running loop),explain_hierarchical(returnsHierarchicalRunOutput),reanalyze,rescore.close,acloseand context managers close an injected backend and loop.ExplainOrchestrator.run(): see Data flow.score_coalitionsfits aFittableValueFunctionand scores each coalition;reanalyzeuses it too.reanalyze_sync(Reanalyze): for a run scored with backend embeddings and aRequiresEmbeddingsvalue function it logs aWARNING, or raisesReanalyzeMismatchErrorwithstrict; aRequiresLogprobsorRequiresTeacherForcingvalue function on rows without logprobs orforcedscores raisesReanalyzeMismatchError.rescorerebuilds prompts from archived masks, runsscore_continuationsonly and reanalyzes (decision).ExplainResult;ExplainRunOutputwithto_dict()(ExplainRunPayload; each label addsspeakerandlabel, the span’sdisplay_label);player_setisNoneafterreanalyze.RunManifest,parse_manifest,MANIFEST_SCHEMA_VERSION5 (Manifest):embedding_sourceis"none","hash"or"backend";value_infoanddecodingrecord the value function’s settings and the sampling; wrong types raiseArchiveCorruptError.deletion_curve(config, snapshot, attributions, ks, registry, backend)(async): samplesN - top_kperk, returnsDeletionCurve(values,drops,area);removal_metricsadds insertion, random-matched and flip metrics;image_removal_metricsmatches areas.ExplainContext: one run’s inputs;plugin_context()builds itsPluginContext.
Data flow¶
ExplainRunner._partitionand_build_contextcheck plugin options, resolve the partitioner, refuse a plan above2 ** max_playerscoalitions and set 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). ARequiresTeacherForcingone needsSupportsTeacherForcing(ConfigError) and skips coalition generation whenreads_candidate_textis false. ARequiresEmbeddingsone switchesgeneration.compute_embeddingson.It generates the Base generation and writes it to the archive first.
It samples masks with
budget_fraction(n, fraction, evaluations)(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 and draw (num_samples;_scoreaverages), sorted by prefix hash withkv_cache.enabled; the runtime scheduler consumes lazily rendered jobs; records return by key in mask order.score_coalitionsscores records built withgeneration_record_from_text(text)plus the backend’s logprobs andforcedscores, kept per coalition key in the store and archive, so the records equal whatreanalyzebuilds. APreparesScoresvalue function is awaited first.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 align with masks in any job order (C11).
The base generation precedes every coalition row; an archive is complete only after both phases are stored.
reanalyzerefuses a different estimator, absence policy or partition (ReanalyzeMismatchError). It raisesArchiveIncompleteErrorfor a foreign or unfinished archive, a missing boundary coalition, or rows missing 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).