메뉴
HN
Hacker News 3일 전

8달러 마이크로컨트롤러에서 구동하는 28.9M LLM

IMP
8/10
핵심 요약

구글 Gemma 모델에서 도입된 '층별 임베딩(PLE)' 기법을 활용해, 파라미터 대부분을 느린 플래시 메모리에 저장하고 연산에 필요한 최소한의 데이터만 빠른 메모리로 불러와 초소형 칩에서 구동하는 기술입니다. 이를 통해 외부 서버 연결 없이 $8짜리 ESP32-S3 칩 내장 메모리만으로 28.9M(약 2900만 개) 파라미터의 언어모델을 구동하는 놀라운 성과를 보여줍니다. 엣지 디바이스의 극단적인 메모리 제약을 극복한 하드웨어 최적화 및 경량화 연구로서 엣지 AI(Edge AI) 분야에 중요한 의미를 갖습니다.

번역된 본문

$8짜리 마이크로컨트롤러에서 28.9M 파라미터 LLM 구동하기

이 약 8달러짜리 마이크로컨트롤러인 ESP32-S3에서 텍스트를 생성하는 2,890만 개 파라미터의 언어 모델에 대한 소식입니다. 이 모델은 외부 서버로 어떠한 데이터도 전송하지 않고 칩 자체에서 완벽하게 오프라인으로 구동됩니다. 칩에 연결된 작은 화면에 초당 약 9 토큰(token)의 속도로 텍스트를 출력합니다. 과거 이와 비슷한 칩에서 사람들이 구동했던 언어 모델은 파라미터가 26만 개에 불과했으므로, 이 모델은 약 100배 더 많은 용량을 자랑합니다. 이것이 가능한 이유는 구글의 Gemma 모델에서 도입된 '층별 임베딩(Per-Layer Embeddings)'이라는 개념을 활용해 모델의 대부분을 RAM 대신 플래시(flash) 메모리에 저장해 두었기 때문입니다.

세부 수치 파라미터: 28.9M (이 중 25M는 플래시 조회 테이블에 저장) 칩: 약 $8 가량의 ESP32-S3. 512KB SRAM, 8MB PSRAM 및 16MB 플래시 메모리 탑재 속도: 종단 간(End-to-end) 약 9.5 tok/s (순수 연산 기준 9.7 tok/s) 연결성: 없음. 모든 연산이 기기 자체에서 독립적으로 실행됨 모델 크기: 4-bit 양자화(Quantization) 시 14.9MB

왜 어려우며, 어떻게 이를 극복했는가? 마이크로컨트롤러에는 매우 빠른 메모리가 거의 없습니다. ESP32-S3에 제공되는 빠른 SRAM의 용량은 고작 512KB에 불과합니다. 일반적으로 모델 전체를 이 빠른 메모리에서 접근할 수 있어야 하므로 개발자는 필연적으로 매우 작은 모델만 사용할 수밖에 없었고, 이것이 바로 이전의 칩 모델이 26만 개 파라미터에 머물렀던 이유였습니다.

이를 해결하는 방법은 모델을 아예 빠른 메모리에 올리지 않는 것입니다. 언어 모델 파라미터의 대부분은 모델이 연산을 수행하는 대신 단순히 데이터를 읽어오는 역할만 하는 임베딩 테이블(embedding table)에 자리 잡고 있습니다. 따라서 2,500만 행에 달하는 이 거대한 테이블은 느린 플래시 메모리에 그대로 두고, 각 토큰이 생성될 때 필요한 약 450바이트 정도의 행만을 빠른 메모리로 끌어오는 방식을 취한 것입니다. 반면 실제 추론과 연산을 담당하는 작은 핵심 부분만 빠른 메모리에 상주시킵니다. 이렇게 하면 대부분의 모델 용량을 로드하지 않으므로 거대한 모델을 구동하는 데 드는 비용이 거의 발생하지 않습니다. 모델은 그저 플래시 메모리에 가만히 있다가 조금씩 샘플링될 뿐입니다. 이 아이디어가 바로 Gemma 3n 및 Gemma 4에서 비롯된 구글의 '층별 임베딩(Per-Layer Embeddings)' 기술입니다. 본 연구에서는 스마트폰이나 GPU 대신 마이크로컨트롤러의 메모리 구조에 이 개념을 적용했습니다. 제가 아는 한, 이렇게 작은 칩에 이 기술을 적용한 시도는 이번이 처음입니다.

SRAM (빠르고 작음): 모든 토큰을 생성할 때 사용되는 '추론' 코어 PSRAM (중간 속도): 결과물을 출력하는 헤드(head) 및 작업 메모리 FLASH (용량이 크고 느림): 2,500만 개 파라미터 테이블. 토큰당 약 6개 행(약 450 B)을 읽어옴

이 모델이 할 수 있는 일과 없는 일 이 모델은 'TinyStories' 데이터셋으로 학습되었습니다. 그래서 짧고 단순하며 대부분 문맥이 잘 맞는 이야기를 생성해 냅니다. 하지만 질문에 답하거나, 지시를 따르거나, 코드를 작성하거나, 사실 정보를 아는 등의 기능은 수행할 수 없습니다. 이러한 한계는 모델에서 실제로 추론을 담당하는 부분의 크기가 너무 작기 때문에 발생하며, 메모리를 최적화하는 기술이 이를 개선해주지는 않습니다. 흥미로운 점은 2,890만 개 파라미터 모델이 무슨 말을 할 수 있는지가 아니라, 거대한 모델을 초소형 칩에 어떻게 탑재했는지 하는 아키텍처 그 자체에 있습니다.

직접 구동해 보기 펌웨어, 배선 방법 및 플래싱 단계는 저장소의 firmware/esp32_llm/README.md 파일에 있습니다. 모델 학습, 절제 연구(Ablation), 양자화 코드는 src/ 및 experiments/ 폴더에 있습니다. 전체 방법론과 세부 측정 결과는 RESULTS.md에 작성되어 있습니다.

크레딧 (출처) 이 모델은 TinyStories 데이터셋으로 학습되었습니다. 이는 소규모 모델이 글을 얼마나 잘 학습할 수 있는지 보여주기 위해 만든 아주 짧고 단순한 합성 소설 데이터입니다(Ronen Eldan과 Yuanzhi Li, Microsoft Research, arXiv:2305.07759).

나머지 절반의 핵심 기술은 구글 Gemma 모델의 설계인 '층별 임베딩(Per-Layer Embeddings)'입니다. 이 덕분에 거대한 모델을 작은 칩에 탑재할 수 있었습니다. 또한 Andrej Karpathy의 llama2.c 프로젝트 덕분에 많은 사람(저를 포함해서)이 초소형 언어 모델을 학습시키고 순수 C 언어 환경에서 구동할 수 있다고 믿게 되었습니다. 이 프로젝트 역시 그 연장선에서 출발했습니다.

실제 개발 과정에서의 에피소드 저는 저장소(Repository)에 지저분한 커밋 내역을 일부러 그대로 남겨두었습니다. 여기에는 제가 파라미터를 계산하다가 발견한 버그도 포함되어 있습니다. 이 버그는 초기에 파라미터 수치를 부풀렸었고, 이후 버그를 수정하면서 정확한 결과가 나오게 된 과정을 커밋 내역과 RESULTS.md 파일에서 확인하실 수 있습니다.

원문 보기
원문 보기 (영어)
Running a 28.9M parameter LLM on an $8 microcontroller Open to Work · 𝕏 slvDev · LinkedIn This is a 28.9 million parameter language model that generates text on an ESP32-S3, a microcontroller that costs about $8. It runs on the chip itself, with nothing sent to a server, and it writes each word to a small screen wired to the chip at roughly 9 tokens per second. The last language model people ran on a chip like this had 260 thousand parameters, so this one holds about a hundred times more. It fits because most of the model lives in flash instead of RAM, using an idea from Google's Gemma models called Per-Layer Embeddings. The numbers Parameters 28.9M stored (25M of them in a flash lookup table) Chip ESP32-S3, about $8, with 512KB SRAM, 8MB PSRAM and 16MB flash Speed about 9.5 tok/s end to end (9.7 tok/s of pure compute) Connectivity none, everything runs on the device Model size 14.9MB at 4-bit Why it is hard, and how it fits anyway A microcontroller has very little fast memory. The ESP32-S3 gives you 512KB of SRAM. Normally the whole model has to be reachable from there, which keeps you stuck with tiny models, and that is why the previous model on a chip like this had only 260 thousand parameters. The way around it is to stop putting the model in fast memory at all. Most of a language model's parameters sit in an embedding table, which the model reads from rather than computes on. So you can leave that 25 million row table in slow flash and pull only the few rows each token needs, about 450 bytes, while the small part that does the actual work stays in fast memory. The large model then costs almost nothing to run, because you never load most of it. It just sits in flash and gets sampled a little at a time. That idea is Google's Per-Layer Embeddings, from Gemma 3n and Gemma 4. Here it runs on the memory layout of a microcontroller instead of a phone or a GPU. As far as I can tell, nobody had tried it on a chip this small. SRAM (fast, tiny) the "thinking" core, used on every token PSRAM (medium) the output head and working memory FLASH (huge, slow) the 25M-param table, about 6 rows read per token (~450 B) What it does, and what it does not The model was trained on TinyStories, so it writes short, simple stories and mostly keeps them coherent. It will not answer questions, follow instructions, write code, or know facts. That limit comes from the small part of the model that does the reasoning, and the memory trick does not change it. What is interesting here is the architecture, fitting a large model onto a tiny chip, rather than what a 28.9 million parameter model can say. Running it yourself The firmware, the wiring, and the flashing steps live in firmware/esp32_llm/README.md . The training, ablation, and quantization code is in src/ and experiments/ . The full method, the ablations, and the on-chip measurements are written up in RESULTS.md . Credit TinyStories is the dataset this trains on: short synthetic stories simple enough that a small model can still learn to write coherently (Ronen Eldan and Yuanzhi Li, Microsoft Research, arXiv:2305.07759 ). The other half is Per-Layer Embeddings, Google's design from the Gemma models, which is what lets a big model fit on a small chip. Andrej Karpathy's llama2.c is why a lot of people, me included, believe you can train a tiny language model and run it in plain C at all. This grew out of that. How this actually went I left the messy history in the repo on purpose. That includes a bug I found in my own parameter accounting, which had inflated an early number, and the corrected result that followed once I fixed it. The commit history and RESULTS.md show where the numbers moved and why.