메뉴
HN
Hacker News • 13일 전

트랜스포머 회로를 위한 수학적 프레임워크

IMP
7/10
핵심 요약

Anthropic이 2021년 발표한 연구로, 트랜스포머 언어 모델의 내부 동작을 역설계(리버스 엔지니어링)하기 위한 수학적 프레임워크를 제시했습니다. 연구진은 2층 이하의 어텐션 전용 소형 모델을 분석해 '인덕션 헤드(induction head)'라는 특정 어텐션 헤드가 문맥 내 학습(in-context learning)을 설명한다는 것을 발견했습니다. 이는 AI 모델의 안전성 문제를 체계적으로 이해하고 예측하기 위한 기계적 해석 가능성(mechanistic interpretability) 연구의 초석이 되는 중요한 성과입니다.

번역된 본문

트랜스포머 회로 스레드: 트랜스포머 회로를 위한 수학적 프레임워크

저자: Nelson Elhage, Neel Nanda, Catherine Olsson, Tom Henighan, Nicholas Joseph, Ben Mann, Amanda Askell, Yuntao Bai, Anna Chen, Tom Conerly, Nova DasSarma, Dawn Drain, Deep Ganguli, Zac Hatfield-Dodds, Danny Hernandez, Andy Jones, Jackson Kernion, Liane Lovitt, Kamal Ndousse, Dario Amodei, Tom Brown, Jack Clark, Jared Kaplan, Sam McCandlish, Chris Olah

소속: Anthropic 발표일: 2021년 12월 22일 (* 핵심 연구 기여자; † 핵심 인프라 기여자; ‡ 문의: colah@anthropic.com; 저자 기여 명세는 하단 참조)

트랜스포머 언어 모델은 GPT-3, LaMDA, Codex, Meena, Gopher 등과 같은 시스템에서 실제로 사용되며 점점 더 폭넓게 활용되는 신흥 기술입니다. 그러나 이러한 모델이 규모가 커질수록 개방성과 높은 용량으로 인해 예상치 못한, 때로는 유해한 행동이 발생할 여지가 커집니다. 대형 모델이 학습된 지 수년이 지난 후에도 개발자와 사용자는 이전에 알지 못했던 모델 능력(문제가 되는 행동 포함)을 계속해서 발견하고 있습니다.

이러한 문제를 해결하는 한 가지 접근법은 기계적 해석 가능성(mechanistic interpretability)입니다. 이는 프로그래머가 복잡한 바이너리 코드를 사람이 읽을 수 있는 소스 코드로 역설계하려는 것처럼, 트랜스포머가 수행하는 세부 계산 과정을 역설계하려는 시도입니다. 이것이 가능해진다면 현재의 안전성 문제를 설명하고, 새로운 문제를 식별하며, 나아가 아직 만들어지지 않은 강력한 미래 모델의 안전성 문제를 예측하는 더 체계적인 접근법을 제공할 수 있을 것입니다.

이전 프로젝트인 Distill Circuits 스레드는 비전 모델을 역설계하려고 시도했지만, 지금까지 트랜스포머나 언어 모델에 대한 비슷한 프로젝트는 없었습니다. 이 논문에서 우리는 트랜스포머를 역설계하기 위한 초기의, 매우 예비적인 단계를 시도합니다. 현대 언어 모델의 놀라운 복잡성과 규모를 고려할 때, 우리는 가능한 한 가장 단순한 모델에서 시작하여 점차 확장해 나가는 것이 가장 생산적이라는 것을 발견했습니다. 우리의 목표는 이후 더 크고 복잡한 모델에 적용할 수 있는 간단한 알고리즘적 패턴, 모티프, 프레임워크를 발견하는 것입니다.

구체적으로 이 논문에서는 어텐션 블록만 포함된 2층 이하의 트랜스포머를 연구합니다. 이는 96개 층을 가지고 어텐션 블록과 MLP 블록을 번갈아 사용하는 GPT-3 같은 대형 현대 트랜스포머와 대조됩니다. 우리는 트랜스포머의 작동을 새롭지만 수학적으로 동등한 방식으로 개념화함으로써 이러한 소형 모델을 이해할 수 있고, 모델이 내부적으로 어떻게 작동하는지에 대한 상당한 통찰을 얻을 수 있음을 발견했습니다. 특히 주목할 점은, 우리가 '인덕션 헤드(induction head)'라고 명명한 특정 어텐션 헤드가 이러한 소형 모델에서 문맥 내 학습(in-context learning)을 설명할 수 있으며, 이러한 헤드는 최소 2개의 어텐션 층을 가진 모델에서만 발생한다는 것입니다. 또한 이러한 헤드가 실제 특정 데이터에서 작동하는 몇 가지 예시도 살펴봅니다.

우리는 이 첫 논문에서 우리의 통찰을 더 큰 모델에 적용하는 것을 시도하지 않지만, 곧 발표될 후속 논문에서 트랜스포머를 이해하기 위한 우리의 수학적 프레임워크와 인덕션 헤드 개념이 훨씬 더 크고 현실적인 모델에 대해서도 최소한 부분적으로 관련성이 있음을 보일 것입니다. 다만 그러한 모델을 완전히 역설계할 수 있기까지는 여전히 매우 먼 길이 남아 있습니다.

결과 요약 역설계 결과 역설계의 어려움을 탐구하기 위해 우리는 여러 장난감(toy) 수준의 어텐션 전용 모델을 역설계했습니다. 그 과정에서 다음을 발견했습니다:

  • 0층 트랜스포머는 바이그램(bigram, 인접 두 단어 쌍) 통계를 모델링합니다. 바이그램 테이블은 가중치에서 직접 추출할 수 있습니다.

  • 1층 어텐션 전용 트랜스포머는 바이그램 모델과 '스킵-트라이그램(skip-trigram, "A… B C" 형태의 시퀀스)' 모델의 앙상블입니다. 바이그램 및 스킵-트라이그램 테이블은 모델을 실행하지 않고도 가중치에서 직접 접근할 수 있습니다.

원문 보기
원문 보기 (영어)
Transformer Circuits Thread A Mathematical Framework for Transformer Circuits Authors Nelson Elhage ∗† , Neel Nanda ∗ , Catherine Olsson ∗ , Tom Henighan † , Nicholas Joseph † , Ben Mann † , Amanda Askell, Yuntao Bai, Anna Chen, Tom Conerly, Nova DasSarma, Dawn Drain, Deep Ganguli, Zac Hatfield-Dodds , Danny Hernandez, Andy Jones, Jackson Kernion, Liane Lovitt, Kamal Ndousse, Dario Amodei, Tom Brown, Jack Clark, Jared Kaplan, Sam McCandlish, Chris Olah ‡ Affiliation Anthropic Published Dec 22, 2021 * Core Research Contributor; † Core Infrastructure Contributor; ‡ Correspondence to colah@anthropic.com ; Author contributions statement below . Transformer language models are an emerging technology that is gaining increasingly broad real-world use, for example in systems like GPT-3 , LaMDA , Codex , Meena , Gopher , and similar models. However, as these models scale, their open-endedness and high capacity creates an increasing scope for unexpected and sometimes harmful behaviors. Even years after a large model is trained, both creators and users routinely discover model capabilities – including problematic behaviors – they were previously unaware of. One avenue for addressing these issues is mechanistic interpretability , attempting to reverse engineer the detailed computations performed by transformers, similar to how a programmer might try to reverse engineer complicated binaries into human-readable source code. If this were possible, it could potentially provide a more systematic approach to explaining current safety problems, identifying new ones, and perhaps even anticipating the safety problems of powerful future models that have not yet been built. A previous project, the Distill Circuits thread , has attempted to reverse engineer vision models, but so far there hasn’t been a comparable project for transformers or language models. In this paper, we attempt to take initial, very preliminary steps towards reverse-engineering transformers. Given the incredible complexity and size of modern language models, we have found it most fruitful to start with the simplest possible models and work our way up from there. Our aim is to discover simple algorithmic patterns, motifs, or frameworks that can subsequently be applied to larger and more complex models. Specifically, in this paper we will study transformers with two layers or less which have only attention blocks – this is in contrast to a large, modern transformer like GPT-3, which has 96 layers and alternates attention blocks with MLP blocks. We find that by conceptualizing the operation of transformers in a new but mathematically equivalent way, we are able to make sense of these small models and gain significant understanding of how they operate internally. Of particular note, we find that specific attention heads that we term “induction heads” can explain in-context learning in these small models, and that these heads only develop in models with at least two attention layers. We also go through some examples of these heads operating in action on specific data. We don’t attempt to apply to our insights to larger models in this first paper, but in a forthcoming paper , we will show that both our mathematical framework for understanding transformers, and the concept of induction heads, continues to be at least partially relevant for much larger and more realistic models – though we remain a very long way from being able to fully reverse engineer such models. Summary of Results Reverse Engineering Results To explore the challenge of reverse engineering transformers, we reverse engineer several toy, attention-only models. In doing so we find: Zero layer transformers model bigram statistics. The bigram table can be accessed directly from the weights. One layer attention-only transformers are an ensemble of bigram and “skip-trigram” (sequences of the form "A… B C") models. The bigram and skip-trigram tables can be accessed directly from the weights, without running the model. These skip-trigrams can be surprisingly expressive. This includes implementing a kind of very simple in-context learning. Two layer attention-only transformers can implement much more complex algorithms using compositions of attention heads. These compositional algorithms can also be detected directly from the weights. Notably, two layer models use attention head composition to create “induction heads”, a very general in-context learning algorithm. We’ll explore induction heads in much more detail in a forthcoming paper. One layer and two layer attention-only transformers use very different algorithms to perform in-context learning. Two layer attention heads use qualitatively more sophisticated inference-time algorithms — in particular, a special type of attention head we call an induction head — to perform in-context-learning, forming an important transition point that will be relevant for larger models. Conceptual Take-Aways We’ve found that many subtle details of the transformer architecture require us to approach reverse engineering it in a pretty different way from how the InceptionV1 Circuits work . We’ll unpack each of these points in the sections below, but for now we briefly summarize. We’ll also expand on a lot of the terminology we introduce here once we get to the appropriate sections. (To be clear, we don't intend to claim that any of these points are necessarily novel; many are implicitly or explicitly present in other papers.) Attention heads can be understood as independent operations, each outputting a result which is added into the residual stream. Attention heads are often described in an alternate “concatenate and multiply” formulation for computational efficiency, but this is mathematically equivalent. Attention-only models can be written as a sum of interpretable end-to-end functions mapping tokens to changes in logits. These functions correspond to “paths” through the model, and are linear if one freezes the attention patterns. Transformers have an enormous amount of linear structure. One can learn a lot simply by breaking apart sums and multiplying together chains of matrices. Attention heads can be understood as having two largely independent computations: a QK (“query-key”) circuit which computes the attention pattern, and an OV (“output-value”) circuit which computes how each token affects the output if attended to. Key, query, and value vectors can be thought of as intermediate results in the computation of the low-rank matrices W_Q^TW_K and W_OW_V . It can be useful to describe transformers without reference to them. Composition of attention heads greatly increases the expressivity of transformers. There are three different ways attention heads can compose, corresponding to keys, queries, and values. Key and query composition are very different from value composition. All components of a transformer (the token embedding, attention heads, MLP layers, and unembedding) communicate with each other by reading and writing to different subspaces of the residual stream. Rather than analyze the residual stream vectors, it can be helpful to decompose the residual stream into all these different communication channels, corresponding to paths through the model. Transformer Overview Before we attempt to reverse engineer transformers, it's helpful to briefly review the high-level structure of transformers and describe how we think about them. In many cases, we've found it helpful to reframe transformers in equivalent, but non-standard ways. Mechanistic interpretability requires us to break models down into human-interpretable pieces. An important first step is finding the representation which makes it easiest to reason about the model. In modern deep learning, there is — for good reason! — a lot of emphasis on computational efficiency, and our mathematical descriptions of models often mirror decisions in how one would write efficient code to run the model. But when there are many equivalent ways to represent the same