Skip to content

feat: add reflection probing and steering pipelines - #2

Merged
xzAscC merged 43 commits into
mainfrom
fresh-start
Jul 16, 2026
Merged

feat: add reflection probing and steering pipelines#2
xzAscC merged 43 commits into
mainfrom
fresh-start

Conversation

@xzAscC

@xzAscC xzAscC commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

Adds end-to-end inference, LLM-as-judge evaluation, reflection diagnosis, steering-vector extraction/inference, linear probing, and ROSCOE reasoning-quality analysis. Shared model, batching, prompt, and judge utilities reduce duplication; deterministic tests mock external datasets and cover inference limits, token-only decoding, and OOM recovery. Repository ignore rules keep local research data and workflow state off GitHub while .ignore preserves OpenCode/ripgrep searchability.

Linked issue

N/A — no repository issue is associated with this work.

Verification

  • uv sync — passed (176 packages resolved)
  • uv run ruff check src/ tests/ scripts/ — passed, 0 violations
  • uv run ruff format --check src/ tests/ scripts/ — passed, 30 files formatted
  • uv run mypy src/ — passed, 0 errors in 15 source files
  • uv run pytest — passed, 159 tests
  • bash -n scripts/probing_reflection/*.sh — passed
  • Second-round review: goal/constraints PASS, QA PASS, code quality PASS, security PASS, PR context PASS

Self-review checklist

  • Changes are split into focused, reviewable commits
  • Tests cover happy paths, edge cases, and failure paths
  • External dataset/model boundaries are mocked in tests
  • No Any or type-error suppressions remain in src/
  • Local data, generated figures, notebooks, and agent state remain untracked
  • README citation updated to arXiv:2506.12217

Risks and considerations

  • Real experiment commands still require access to the configured Hugging Face models and sufficient GPU resources.
  • Cross-family judge scripts expect local inputs under the gitignored data/hard_negatives/ directory.
  • The PR removes the previously tracked .sisyphus draft and keeps .sisyphus/ local-only by design.

Summary by cubic

Adds an end-to-end pipeline for reflection probing and activation steering, including batch inference, LLM-as-judge evaluation, reflection diagnosis, steering-vector extraction/application, linear probing, and ROSCOE reasoning-quality scoring. Updates the README with pipeline overviews and example commands for running experiments on MATH-500, AIME, and GPQA.

  • New Features

    • CLI probing-reflection with commands: inference, evaluate, reflection-diagnose, extract-vectors.
    • Steering vectors: extraction from R/N sets, 4-bit steering inference with hooks, and multi-dataset adapters (MATH-500, AIME, GPQA).
    • Linear probe training/eval with metrics and plot exports; weights saved to .npz.
    • LLM-as-judge utilities for answer comparison and reflection detection; cross-family judge scripts and result merger.
    • ROSCOE-based reasoning quality scoring and report generator.
    • Documentation and shared utils for model loading, batching, prompts; extensive tests and sample fixtures.
    • Repo hygiene: expanded .gitignore and .ignore to keep local research data untracked but searchable.
  • Dependencies

    • Adds transformers, torch, datasets, tqdm, accelerate, bitsandbytes, scikit-learn, matplotlib, and runtime jupyter.

Written for commit 37b4170. Summary will update on new commits.

Review in cubic

xzAscC and others added 30 commits July 16, 2026 17:17
- Add dependencies: transformers>=4.40.0, torch>=2.0.0, datasets>=2.14.0, tqdm>=4.65.0
- Add InferenceConfig frozen dataclass to types.py
- Export InferenceConfig in __init__.py
- Create test stubs for inference module (TDD)
- test_format_cot_prompt: verify CoT prompt format
- test_batch_tokenization: verify left padding for Qwen
- test_jsonl_output_format: verify JSONL schema with 7 fields
- test_run_inference_mocked: verify run_inference with mocks

All tests expected to FAIL (TDD red phase - module doesn't exist yet)
- Add load_model helper function
- Add run_inference main function with batch processing
- All 4 tests now pass
- Add load_model() helper for model loading with bfloat16
- Add run_inference() main function with batching and OOM handling
- Add __main__.py entry point with --limit argument
- Add dependencies
- Add InferenceConfig
- Implement format_cot_prompt
- Implement batch tokenization with left padding
- Implement run_inference with Add __main__.py entry point with --limit argument

Tests: 4 passed
Implement evaluation pipeline for comparing model answers against reference
answers using LLM-as-Judge with Qwen3.5-27B:

- Add evaluation types (JudgeVerdict, EvaluationResult, EvaluationReport, EvaluationConfig)
- Implement extract_boxed_answer() for LaTeX answer extraction with nested brace support
- Add LLMJudge class with position bias mitigation (dual ordering verification)
- Implement generate_report() for accuracy statistics by subject/level
- Add evaluate() main function with batch processing
- Extend CLI with 'evaluate' subcommand
- Add comprehensive unit tests with mocked model
- Add reflection_diagnosis.py module with:
  - ReflectionJudge class for token extraction
  - diagnose_sample() for single sample analysis
  - diagnose_all() for batch processing
  - write_analyzed_jsonl() and write_analysis_report() output writers
- Add types to types.py:
  - ReflectionDiagnosisConfig
  - ReflectionToken
  - SampleWithReflection
  - ReflectionAnalysisReport
- Add reflection-diagnose CLI command to __main__.py
- Add TDD test suite with 26 passing tests
- Add types-tqdm dev dependency
…eering vectors

- Add ExtractVectorsConfig frozen dataclass with fields: input_path, model_name,
  layer_indices, output_path, min_samples (default 10), batch_size (default 4)
- Add SteeringVectorResult TypedDict with vectors and metadata fields
- Add comprehensive tests for both new types in test_types.py
- Create test fixtures and RED phase test stubs for steering_vectors module

Wave 1 complete: types + test scaffolding (TDD RED phase)
…ition, extract_activation_at_position, compute_difference_in_means, save_steering_vectors

- classify_samples: Split samples into R/N sets with min_samples validation
- find_reflection_token_position: Find reflection token index in tokenized text
- extract_activation_at_position: Extract hidden states at specified position
- compute_difference_in_means: Compute v = mean(R) - mean(N) per layer
- save_steering_vectors: Save vectors to .pt file with metadata

Tests: 20 passed (9 skipped - pending TestBatch and TestPipeline)

Co-authored-by: Sisyphus <ai@ohmyopencode.dev>
…sing

- Process samples using classify_samples to split R/N
- For R samples: find reflection token position, extract activation
- For N samples: use last token position
- CPU offload for memory management
- tqdm progress bar
- Skip samples where token not found (log warning)

Co-authored-by: Sisyphus <ai@ohmyopencode.dev>
…ition, extract_activation_at_position, extract_batch_activations, compute_difference_in_means, save_steering_vectors

- classify_samples: Split samples into R/N sets with min_samples validation
- find_reflection_token_position: Find reflection token index in text
- extract_activation_at_position: Extract hidden states at specified layer/position
- extract_batch_activations: Batch processing with R/N split and progress bar
- compute_difference_in_means: v = mean(R) - mean(N)

- save_steering_vectors: Save vectors to dict with metadata

Tests: 24 passed (5 skipped - pending TestPipeline and implementation)

Co-authored-by: Sisyphus <ai@ohmyopencode.dev>
…ct-vectors CLI command

- Add extract_steering_vectors() main orchestration function:
  - Loads JSONL data
  - Classifies samples into R/N sets
  - Loads model (bfloat16/CUDA pattern)
  - Extracts batch activations
  - Computes difference-in-means vectors
  - Saves to .pt with metadata

- Add extract-vectors CLI command:
  - --input, -i: Input JSONL path (required)
  - --model, -m: Model name (default: Qwen/Qwen2.5-0.5B)
  - --layers, -l: Layer indices, comma-separated (required)
  - --output, -o: Output .pt path (default: steering_vectors.pt)
  - --min-samples: Minimum R/N samples (default: 10)
  - --batch-size, -b: Batch size (default: 4)

All 100 tests pass. Wave 3 complete.

Co-authored-by: Sisyphus <ai@ohmyopencode.dev>
- Add SteeringInferenceConfig type with all required fields
- Implement load_steering_vectors() for loading .pt vector files
- Implement load_model_4bit() with BitsAndBytesConfig NF4 quantization
- Implement create_steering_hook() for activation steering via forward hooks
- Implement run_steering_inference() main inference pipeline with hook cleanup
- Add get_output_path() and unload_model() utilities
- Add dataset adapters for MATH-500, AIME2024, GPQA Diamond
- Add evaluate_gpqa() for full-text LLM judge comparison
- Create run_experiments.py CLI for orchestrating experiments
- Create generate_report.py for aggregating evaluation results

All 100 tests pass, ruff and mypy clean.
- Fix create_steering_hook() to cast vectors to hidden_states dtype
- Add fallback from 'test' to 'train' split for datasets like AIME
- Add accelerate and bitsandbytes dependencies
- Add dataset adapter unit tests (13 tests)
- Run demo experiments with limit=5 on all 9 conditions
…n separability

- Add scikit-learn and matplotlib dependencies
- Add LinearProbeConfig, ProbeMetrics, LinearProbeResult types
- Implement collect_token_activations for R/N set extraction
- Implement train_linear_probe with LogisticRegression
- Implement evaluate_probe for accuracy metrics
- Implement generate_tsne_plot and generate_pca_plot
- Implement save_probe_weights for .npz serialization
- Add 19 comprehensive tests (all passing)
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
xzAscC and others added 13 commits July 16, 2026 17:29
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@xzAscC
xzAscC merged commit 33991f4 into main Jul 16, 2026
2 checks passed
@xzAscC
xzAscC deleted the fresh-start branch July 16, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant