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, generation and explanation sections. BudgetConfig takes one of fraction, evaluations and per_player. Unset keys, efficiency: none and hierarchical are not serialised, so older configurations keep their Run id (Absolute budget passed to samplers as an exact fraction).

  • ExplanationConfig cross-field rules raise ConfigError: exact needs budget.fraction: 1.0, complementary, neyman_cc and leverage need the Shapley estimand and kernel_banzhaf Banzhaf. efficiency: additive needs Shapley without loo, hierarchical the sentences players, neyman_cc no include_minimal_masks. explain_config_from_yaml raises ConfigError for an invalid document.

  • ExplainRunner: explain, explain_sync (a RuntimeError inside a running loop), explain_hierarchical (returns HierarchicalRunOutput), reanalyze, rescore. close, aclose and context managers close an injected backend and loop.

  • ExplainOrchestrator.run(): see Data flow. score_coalitions fits a FittableValueFunction and scores each coalition; reanalyze uses it too.

  • reanalyze_sync (Reanalyze): for a run scored with backend embeddings and a RequiresEmbeddings value function it logs a WARNING, or raises ReanalyzeMismatchError with strict; a RequiresLogprobs or RequiresTeacherForcing value function on rows without logprobs or forced scores raises ReanalyzeMismatchError. rescore rebuilds prompts from archived masks, runs score_continuations only and reanalyzes (decision).

  • ExplainResult; ExplainRunOutput with to_dict() (ExplainRunPayload; each label adds speaker and label, the span’s display_label); player_set is None after reanalyze.

  • RunManifest, parse_manifest, MANIFEST_SCHEMA_VERSION 5 (Manifest): embedding_source is "none", "hash" or "backend"; value_info and decoding record the value function’s settings and the sampling; wrong types raise ArchiveCorruptError.

  • deletion_curve(config, snapshot, attributions, ks, registry, backend) (async): samples N - top_k per k, returns DeletionCurve (values, drops, area); removal_metrics adds insertion, random-matched and flip metrics; image_removal_metrics matches areas.

  • ExplainContext: one run’s inputs; plugin_context() builds its PluginContext.

Data flow

  1. ExplainRunner._partition and _build_context check plugin options, resolve the partitioner, refuse a plan above 2 ** max_players coalitions and set the Run id from the configuration without its archive section plus the model id.

  2. Without an injected backend the runner builds one through plugins instantiate_backend and closes it after the call.

  3. The orchestrator resolves the plugins. A RequiresLogprobs value function on a backend without SupportsLogprobs raises ConfigError (logprob value). A RequiresTeacherForcing one needs SupportsTeacherForcing (ConfigError) and skips coalition generation when reads_candidate_text is false. A RequiresEmbeddings one switches generation.compute_embeddings on.

  4. It generates the Base generation and writes it to the archive first.

  5. It samples masks with budget_fraction(n, fraction, evaluations) (estimation) and adds a missing empty or grand coalition; the base text is v(N). A SupportsKvCache backend gets its prefix cache enabled, and the metrics count only this run’s hits.

  6. It plans (mask, coalition key, prefix hash) per mask and draw (num_samples; _score averages), sorted by prefix hash with kv_cache.enabled; the runtime scheduler consumes lazily rendered jobs; records return by key in mask order.

  7. score_coalitions scores records built with generation_record_from_text(text) plus the backend’s logprobs and forced scores, kept per coalition key in the store and archive, so the records equal what reanalyze builds. A PreparesScores value function is awaited first.

  8. A TwoPhaseEstimator gets begin_allocation(masks, payoffs); phase-two masks run the same way and every coalition is rescored on the joint corpus.

  9. 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 with estimator.estimate_attributions, normalises and logs each stage at INFO.

Invariants

  • The empty and grand coalitions are always evaluated; sum(values) == grand_value - base_value for 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.

  • reanalyze refuses a different estimator, absence policy or partition (ReanalyzeMismatchError). It raises ArchiveIncompleteError for a foreign or unfinished archive, a missing boundary coalition, or rows missing under a full-table budget.

  • explain and reanalyze score identical records for a run without model embeddings (C15).

Known issues

Tests