# debayanroy676/surgery-on-llm architecture

> Architecture diagram of the GitHub repository debayanroy676/surgery-on-llm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/debayanroy676/surgery-on-llm
- Repository: https://github.com/debayanroy676/surgery-on-llm

## Overview

This repository is a notebook experiment that tests how a large perturbation to a Llama query-projection weight affects model behavior. The principal workflow inspects a GGUF, loads it into an editable Transformers model, captures a baseline, applies a weight intervention, and measures resulting activation and prediction changes. A separate A/B stage compares original and modified weights across prompts. The README documents these stages; no notebook source excerpts were provided, so the relationships below rely on that documentation.

Main entry points: [`LLM-Brain-Surgery.ipynb`](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb) (Editable model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Model preparation"]
  node_inspect["GGUF inspection"]
  node_load["Model loading"]
  node_baseline["Baseline capture"]
end

subgraph group_intervention["Weight intervention"]
  node_model["Editable model"]
  node_modify["Weight modification"]
end

subgraph group_evaluation["Behavior evaluation"]
  node_drift["Activation drift"]
  node_logits["Logit analysis"]
  node_tokens["Token and entropy"]
  node_abtest["Prompt A/B test"]
  node_results["Measured results"]
end

node_researcher(("Researcher"))
node_gguf["GGUF weights"]

node_researcher -->|"runs experiment"| node_inspect
node_inspect -->|"inspects tensors"| node_gguf
node_load -->|"loads weights"| node_gguf
node_inspect -->|"informs loading"| node_load
node_load -->|"captures baseline"| node_baseline
node_baseline -->|"records weights"| node_model
node_modify -->|"perturbs weights"| node_model
node_model -->|"measures activations"| node_drift
node_model -->|"measures logits"| node_logits
node_logits -->|"derives distributions"| node_tokens
node_baseline -->|"compares original"| node_abtest
node_modify -->|"compares operated weights"| node_abtest
node_abtest -->|"reports predictions"| node_results
node_drift -->|"reports drift"| node_results
node_tokens -->|"reports confidence"| node_results

click node_inspect "https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb"
click node_load "https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb"
click node_baseline "https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb"
click node_model "https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb"
click node_modify "https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb"
click node_drift "https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb"
click node_logits "https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb"
click node_tokens "https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb"
click node_abtest "https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb"
click node_results "https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_inspect,node_load,node_baseline toneBlue
class node_model,node_modify toneAmber
class node_drift,node_logits,node_tokens,node_abtest,node_results toneMint
class node_researcher,node_gguf toneIndigo
```

## Components

### Model preparation

- [GGUF inspection](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb): `LLM-Brain-Surgery.ipynb`
- [Model loading](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb): `LLM-Brain-Surgery.ipynb`
- [Baseline capture](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb): `LLM-Brain-Surgery.ipynb`

### Weight intervention

- [Editable model](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb): `LLM-Brain-Surgery.ipynb`
- [Weight modification](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb): `LLM-Brain-Surgery.ipynb`

### Behavior evaluation

- [Activation drift](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb): `LLM-Brain-Surgery.ipynb`
- [Logit analysis](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb): `LLM-Brain-Surgery.ipynb`
- [Token and entropy](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb): `LLM-Brain-Surgery.ipynb`
- [Prompt A/B test](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb): `LLM-Brain-Surgery.ipynb`
- [Measured results](https://github.com/debayanroy676/surgery-on-llm/blob/main/LLM-Brain-Surgery.ipynb): `LLM-Brain-Surgery.ipynb`

### Other components

- **Researcher**
- **GGUF weights**

## Connections

- Researcher → GGUF inspection: runs experiment (evidence: `README.md`)
- GGUF inspection → GGUF weights: inspects tensors (evidence: `README.md`)
- Model loading → GGUF weights: loads weights (evidence: `README.md`)
- GGUF inspection → Model loading: informs loading (evidence: `README.md`)
- Model loading → Baseline capture: captures baseline (evidence: `README.md`)
- Baseline capture → Editable model: records weights (evidence: `README.md`)
- Weight modification → Editable model: perturbs weights (evidence: `README.md`)
- Editable model → Activation drift: measures activations (evidence: `README.md`)
- Editable model → Logit analysis: measures logits (evidence: `README.md`)
- Logit analysis → Token and entropy: derives distributions (evidence: `README.md`)
- Baseline capture → Prompt A/B test: compares original (evidence: `README.md`)
- Weight modification → Prompt A/B test: compares operated weights (evidence: `README.md`)
- Prompt A/B test → Measured results: reports predictions (evidence: `README.md`)
- Activation drift → Measured results: reports drift (evidence: `README.md`)
- Token and entropy → Measured results: reports confidence (evidence: `README.md`)
