feat: add reflection probing and steering pipelines - #2
Merged
Conversation
- 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>
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>
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.
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
.ignorepreserves 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 violationsuv run ruff format --check src/ tests/ scripts/— passed, 30 files formatteduv run mypy src/— passed, 0 errors in 15 source filesuv run pytest— passed, 159 testsbash -n scripts/probing_reflection/*.sh— passedSelf-review checklist
Anyor type-error suppressions remain insrc/Risks and considerations
data/hard_negatives/directory..sisyphusdraft 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
probing-reflectionwith commands:inference,evaluate,reflection-diagnose,extract-vectors..npz..gitignoreand.ignoreto keep local research data untracked but searchable.Dependencies
transformers,torch,datasets,tqdm,accelerate,bitsandbytes,scikit-learn,matplotlib, and runtimejupyter.Written for commit 37b4170. Summary will update on new commits.