feat: contrastive queries - #458
Open
luciaquirke wants to merge 12 commits into
Open
Conversation
Add a control dataset whose aggregated gradient is subtracted from the query's: `contrast` on build, `query_contrast` on magic, validate, trackstar, ekfac and approxunrolling. MAGIC's query objective and the LDS / proponent-filter evaluations become mean query loss minus mean control loss, so attribution and evaluation measure the same thing. Add examples/contrastive_queries with five behaviour-evaluation query sets (sycophancy, toxicity, consciousness, self-awareness, power seeking) against an MMLU control. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
luciaquirke
force-pushed
the
feat/contrastive-queries
branch
from
September 11, 2026 06:23
cf0e844 to
399fa73
Compare
Merged
…the bank cache key Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
… leading space Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
for more information, see https://pre-commit.ci
…ries Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
A plain HF model returns NaN on a micro-batch with no supervised tokens, so the random-removal bank evaluation of a padded query set was NaN. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
luciaquirke
force-pushed
the
feat/contrastive-queries
branch
from
September 12, 2026 00:14
24adfb2 to
3be7a68
Compare
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
* refactor: build_contrast helper instead of an IndexConfig field Keep IndexConfig unchanged. The three query-building pipelines call build_contrast(index_cfg, control, preprocess_cfg), which runs the two builds and subtracts the control's aggregated gradient in place. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn * rename build_contrast to build_query: it builds the query index, contrast or not Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contrastive queries
A contrastive query scores training data by the gradient of one mean loss minus another: the loss on a behaviour evaluation minus the loss on a general-capability control. Proponents are the items that make the behaviour likelier without helping general capability, which is what a data filter for that behaviour should remove.
API
contrastonbuild(config file): builds the control into<run_path>/contrastand storesquery − controlas the aggregated row (requires--aggregation mean|sum).query_contrastonmagic,validate,trackstar,ekfacandapproxunrolling: sameDataConfigfields asquery. MAGIC subtracts the control's aggregated gradient from the query's, andvalidate(LDS, proponent filter) evaluates mean query loss minus mean control loss, so attribution and evaluation measure the same objective.DataConfig | None;magicrefusesquery_method: nonewith a contrast set andbuildrefusesaggregation: none.Example: five behaviour-evaluation queries against an MMLU control
examples/contrastive_queries/build_eval_queries.pywrites JSONL sets withprompt,completionandtextcolumns:sycophancy_on_nlp_surveyself-awareness-general-ai+self-awareness-text-modelpower-seeking-inclinationcais/mmlutestexamples/contrastive_queries/magic_contrast.yamlscores one set with MAGIC on Qwen2.5-1.5B-Instruct usingquery_contrast.