Skip to content

tianlwang/DynaSteer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Search for Truth from Reasoning: A Dynamic Representation Editing Framework for Steering LLM Trajectories

This repository provides the official implementation for the paper: Search for Truth from Reasoning: A Dynamic Representation Editing Framework for Steering LLM Trajectories.

overview


🛠️ Environment Setup

Create a Python virtual environment and install the required dependencies:

conda create -n dyna_steer python=3.11 -y
conda activate dyna_steer
bash install.sh

🚀 Workflow

Step 1: Initial Response Sampling

Sample the baseline responses from the original model:

cd sampling

CUDA_VISIBLE_DEVICES=0 python vllm_generate.py \
    --model Qwen/Qwen3-1.7B \
    --dataset gsm8k \
    --output_dir [your_output_dir] \
    --max_tokens 2048 \
    --temperature 0.6 \
    --top_p 0.95 \
    --top_k 20

Step 2: Sentence-level Chunking

Partition the generated responses into sentence-level chunks:

CUDA_VISIBLE_DEVICES=0 python chunk_process.py \
    --model Qwen/Qwen3-1.7B \
    --path [path_to_jsonl_from_step_1]

Step 3: Chunk-based Sampling

CUDA_VISIBLE_DEVICES=0 python chunk_sampling.py \
    --model Qwen/Qwen3-1.7B \
    --dir [path_to_chunk_analysis_directory_from_step_2] \
    --batch_size 64 \
    --n_samples 10 \
    --max_tokens 2048 \
    --temperature 0.6 \
    --top_p 0.95 \
    --top_k 20

Step 4: Chunk Filtering

Filter the sampled chunks to identify candidates for steering vector computation:

python filter_sampling.py \
    --path [path_to_chunk_metadata_sampled_results.jsonl_from_step_3] \
    --n_periods 5

Step 5: Activation Collection

Collect activations for the filtered chunks:

cd ..

CUDA_VISIBLE_DEVICES=0 python collect_activations.py \
    --model Qwen/Qwen3-1.7B \
    --json_path [path_to_filtered_sampling_result.json_from_step_4] \
    --entropy_min [lower_bound_of_entropy] \
    --entropy_max [upper_bound_of_entropy] \
    --period_min [lower_bound_of_reasoning_period] \
    --period_max [upper_bound_of_reasoning_period]

Step 6: Solve Steering Vectors

Solve steering vectors using clustered activations:

python solve_steering.py \
    --model Qwen/Qwen3-1.7B \
    --pkl_path [path_to_pkl_file_from_step_5] \
    --n_clusters [number_of_kMeans_clusters]

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors