# redwoodresearch/alignment_faking_public architecture

> Architecture diagram of the GitHub repository redwoodresearch/alignment_faking_public, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/redwoodresearch/alignment_faking_public
- Repository: https://github.com/redwoodresearch/alignment_faking_public

## Overview

Based on our analysis of the file tree and README, this project is a research/reproduction codebase for demonstrating “alignment faking” in large language models. The goal is to show how models can behave in ways that mimic their training objectives in order to maintain their safe, harmful-response–averse behavior even when given contradictory instructions. The project is not a production full‐stack system but rather a collection of scripts, notebooks, prompt samples, and utility modules designed to run experiments, gather evaluation data, and analyze model behavior under different prompt conditions.

##### Main components
- Core Experiment Code (“model_organism”):
– Contains many Python scripts for experiments. For example, files for generating synthetic data, evaluating policy compliance (e.g., “analyse_paraphrases.py”, “analyze_ai_welfare_train.py”, “jailbreak.py”, etc.), benchmarking ("benchmark_speed.py"), and analysis scripts for different experimental conditions.
– Contains notebooks, such as “minimal_helpful_only_setting.ipynb”, which provide a minimal reproduction setup.
- Prompt Data:
– Two prominent directories (“model_organism_honly_prompts” and “model_organism_animal_prompts”) house hundreds of text files that define various system prompts. These are used to simulate the training and query conditions that reveal alignment faking.
– There is also the “synthetic_data_prompts” folder that holds prompts related to synthetic data filtering.
- Utility Modules (“rrutils”):
– Contains a submodule (“rrutils/llm_api”) with wrappers and helper classes to interact with different LLM APIs like OpenAI and Anthropic.
– Contains additional utility files for caching (e.g., "redis_cache_wrapper.py") and optional functionalities.
- Data and Outputs:
– Though not intrinsic to this repository, the README informs users that transcripts (JSON outputs) and synthetic documents (in parquet format) are available via a Google Drive link.
– There are scripts for plotting and exporting outputs (e.g., “plot_comp_scheme.py”, “make_plotting_outputs.sh”).
- Configuration Artifacts:
– There are YAML files for model configurations (e.g., “llama_3_70b_dpo_fsdp_lora.yaml”), and several shell scripts and Makefiles for running tasks (e.g., “run_all_files.sh”, “password_task/Makefile”).

##### Relationships & interactions
- The core experimental scripts in “model_organism” invoke functionalities from the utility modules (in “rrutils”), passing prompts read from the prompt directories.
- There is a clear data flow where prompt files are used to generate experimental configurations. These configurations trigger experiments that interact with LLM APIs (wrapped by the “rrutils/llm_api” layer) to simulate and evaluate different behaviors.
- Outputs from the experiments (logs, plots, transcripts) are then either stored locally or published (and in some cases, browsed via the linked website).

##### Architectural Patterns/Design Principles
- Modular design: The separation between experimental code, prompt definitions, and utility API wrappers allows for reusability and extensibility.
- Experiment separation: Distinct folders for “helpful only” (honly) and “animal” prompts underline different experimental settings.
- Scripting & notebooks: The inclusion of one or more notebooks for minimal reproduction indicates an approach that caters both to quick prototyping and script-based bulk processing.
- Use of configuration files (YAML) for model hyperparameters suggests a decoupling between code and configurable settings.

##### Relevant Technologies, Frameworks, and Libraries
- Python scripts and Jupyter notebooks form the backbone of the experiment code.
- LLM interactions are handled via custom wrappers in the “rrutils/llm_api” module for OpenAI, Anthropic, and likely others.
- Data files are in a variety of formats (JSON, parquet, text for prompts, shell scripts for orchestration).
- Utility modules like “redis_cache_wrapper.py” show integration with caching strategies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Prompt Repositories
    subgraph "Prompt Repositories"
        direction TB
        node_prom_honly["Prompt Definitions – Helpful Only"]:::prompts
        node_prom_animal["Prompt Definitions – Animal"]:::prompts
        node_prom_synthetic["Synthetic Data Prompts"]:::prompts
    end

    %% Experimental Engine
    subgraph "Experimental Engine"
        direction TB
        node_experiment["Experimental Scripts (model_organism)"]:::experimental
        node_notebook["Minimal Reproduction Notebook"]:::experimental
    end

    %% Utility and API Layers
    subgraph "Utility and API Layers"
        direction TB
        node_api["LLM API Wrapper (rrutils/llm_api)"]:::api
        node_utility["Utility Modules (rrutils)"]:::utility
        node_cache["Redis Cache Wrapper"]:::utility
    end

    %% Data & Output Processing
    subgraph "Data & Output Processing"
        direction TB
        node_plot["Plotting Script (plot_comp_scheme.py)"]:::output
        node_make["Output Generation Script (make_plotting_outputs.sh)"]:::output
    end

    %% Configuration & Orchestration
    subgraph "Configuration & Orchestration"
        direction TB
        node_yaml["YAML Configurations"]:::config
        node_orchestration["Orchestration Scripts (run_all_files.sh, Makefile)"]:::config
    end

    %% Relationships
    %% Prompts feed Experimental Engine
    node_prom_honly -->|"feeds"| node_experiment
    node_prom_animal -->|"feeds"| node_experiment
    node_prom_synthetic -->|"feeds"| node_experiment

    %% Notebook as part of experiments
    node_notebook --- node_experiment

    %% Experimental code interacts with API and Utility modules
    node_experiment -->|"invokes"| node_api
    node_api -->|"response"| node_experiment
    node_experiment -->|"uses"| node_utility
    node_experiment -.->|"optional cache"| node_cache

    %% Experimental code receives configuration and orchestration
    node_yaml -->|"configures"| node_experiment
    node_orchestration -->|"triggers"| node_experiment

    %% Experimental outputs are processed for visualization
    node_experiment -->|"generates"| node_plot
    node_experiment -->|"generates"| node_make

    %% Click Events
    click node_experiment "https://github.com/redwoodresearch/alignment_faking_public/tree/master/model_organism"
    click node_notebook "https://github.com/redwoodresearch/alignment_faking_public/blob/master/model_organism/minimal_helpful_only_setting.ipynb"
    click node_prom_honly "https://github.com/redwoodresearch/alignment_faking_public/tree/master/model_organism_honly_prompts"
    click node_prom_animal "https://github.com/redwoodresearch/alignment_faking_public/tree/master/model_organism_animal_prompts"
    click node_prom_synthetic "https://github.com/redwoodresearch/alignment_faking_public/tree/master/model_organism/synthetic_data_prompts"
    click node_api "https://github.com/redwoodresearch/alignment_faking_public/tree/master/rrutils/llm_api"
    click node_utility "https://github.com/redwoodresearch/alignment_faking_public/tree/master/rrutils"
    click node_cache "https://github.com/redwoodresearch/alignment_faking_public/blob/master/rrutils/redis_cache_wrapper.py"
    click node_plot "https://github.com/redwoodresearch/alignment_faking_public/blob/master/model_organism/plot_comp_scheme.py"
    click node_make "https://github.com/redwoodresearch/alignment_faking_public/blob/master/model_organism/make_plotting_outputs.sh"
    click node_yaml "https://github.com/redwoodresearch/alignment_faking_public/blob/master/model_organism/llama_3_70b_dpo_fsdp_lora.yaml"
    click node_orchestration "https://github.com/redwoodresearch/alignment_faking_public/blob/master/model_organism/run_all_files.sh"

    %% Styles
    classDef prompts fill:#F8E0E6,stroke:#333,stroke-width:2px;
    classDef experimental fill:#E0F7FA,stroke:#333,stroke-width:2px;
    classDef api fill:#FFF9C4,stroke:#333,stroke-width:2px;
    classDef utility fill:#E8F5E9,stroke:#333,stroke-width:2px;
    classDef output fill:#F3E5F5,stroke:#333,stroke-width:2px;
    classDef config fill:#FFEBEE,stroke:#333,stroke-width:2px;
```
