Jacobian Lens 的 GGUF 原生实现,用于解释和操控 llama.cpp 托管的量化 LLM 的残差流激活,附带一个 Web 界面,支持实时可视化、引导、概念交换和消融。

Stars

78

7 天增长

暂无数据

Fork 数

10

开放 Issue

0

开源协议

Apache-2.0

最近更新

2026-07-12

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它将可解释性研究中的 Jacobian Lens 技术直接应用于量化 GGUF 模型(包括混合专家模型),无需 PyTorch 或完整的 Hugging Face 流程,并添加了可引导任何 OpenAI 兼容应用的实时干预系统。

适合谁使用

  • 研究 LLM 机械可解释性的研究人员
  • 构建或修改基于 llama.cpp 服务的应用程序的开发者
  • 希望实时调试或引导模型输出的机器学习从业者
  • 实验本地量化语言模型的爱好者

典型使用场景

  • 可视化每一层和每一位置残差流中占主导的 token
  • 在生成文本中引导或消融特定概念(例如,纠正错误的两跳推理)
  • 通过 OpenAI 兼容的后端将实时概念操控集成到聊天应用中
  • 在多种架构和量化级别上复现并扩展论文中的发现

项目优势

  • 适用于 llama.cpp 能加载的任何 GGUF 模型,包括稠密和混合专家架构
  • 读取权重直接来自模型 GGUF(通过 gguf-py 反量化),无需 PyTorch 或原始检查点
  • 拟合和服务的内存及文件大小按 O(n_layers·d_model²) 缩放,与专家数量无关
  • 支持在提示处理和 token 生成过程中的实时干预(引导、交换、消融),并提供干净的 OpenAI API 供外部应用使用

使用前须知

  • 默认的回归拟合透镜是相关性近似;论文中的精确因果透镜需要使用原始 PyTorch 代码拟合并转换 .pt 文件
  • 网格计算(位置 × d_model × 词表)在大型模型上可能较慢——建议使用层步长或更短的提示
  • 必须运行原生激活服务器而非原版 llama-server 才能启用实时干预;不支持附加到已运行的 llama-server

README 快速开始

jlens-gguf — the Jacobian Lens for llama.cpp / GGUF models

A GGUF-native implementation of the Jacobian Lens from Anthropic's Verbalizable Representations Form a Global Workspace in Language Models, plus an interactive visualizer & manipulator (in the spirit of Neuronpedia's J-Lens pages) that works against GGUF models served by llama.cpp — with live steering, concept swapping (patching), ablation, and steered generation.

                                  browser (web UI)
                                        │  JSON
                        ┌───────────────▼────────────────┐
                        │  bridge  (python, numpy)       │  lens math:
                        │  jlens_gguf.server             │  J_l transport, unembed,
                        │   • model GGUF → readout wts   │  top-k, ranks, J-lens vectors,
                        │   • lens GGUF  → J_l (+ bias)  │  steering / swap / ablate,
                        └───────┬────────────────────────┘  sparse decomposition
                                │  HTTP (binary activations, generic residual edits)
                        ┌───────▼────────────────────────┐
                        │  jlens-server  (C++, llama.cpp)│  the same GGUF file your
                        │   • captures l_out- per    │  llama-server mmaps — weights
                        │     layer/position             │  are shared page cache
                        │   • applies add / low-rank /   │
                        │     set edits mid-graph        │
                        │   • generation w/ edits active │
                        └────────────────────────────────┘

New here? Start with QUICKSTART.md — a friendly, task-oriented walkthrough. This README is the full reference.

The reference PyTorch implementation reads the residual stream with hooks and computes with torch tensors. Here, the lens lives in a GGUF file, readout weights (final norm + unembedding) are read directly from the model GGUF (dequantized with gguf-py, no torch), and residual-stream access + live interventions go through a small llama.cpp-based activation server that hooks the computation graph via ggml's scheduler eval callback.

Quickstart

# clone with the llama.cpp submodule
git clone --recursive  jlens-gguf   # or:

项目描述

Interactive Jacobian-Lens visualizer and live steerer for GGUF models on llama.cpp

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

lopopolo
精选
lopopolo GitHub avatar

harness-engineering

Harness Engineering is a methodology for improving coding agent outputs by carefully crafting the environment around them—providing curated context, tools, and executable constraints that encode an organization’s nonfunctional requirements and cumulative lessons.

AI 与机器学习AI 智能体
2,390
slvDev
精选
slvDev GitHub avatar

esp32-ai

A 28.9 million parameter language model runs on an $8 ESP32-S3 microcontroller entirely on-device, generating simple stories at about 9.5 tokens per second.

AI 与机器学习大语言模型
1,960
littledivy
精选
littledivy GitHub avatar

mimic

mimic captures traffic from any iOS or web app and automatically generates a Python client library that lets you call the app's API like a regular library.

AI 与机器学习
1,482