FastBrain

FastBrain · 果蝇全脑实时仿真

138,639 个神经元约 1500 万个突触FlyWire v783 连接组消费级 GPU开源
果蝇全脑,放电神经元高亮

这个仓库把一整只果蝇的脑子搬进了电脑。模型有 138,639 个神经元、约 1500 万个突触,全部来自真实连接组测绘数据,在一张 6 GB 的游戏显卡上实时运行。你可以给神经元施加刺激,看脉冲怎么传遍全脑。

神经科学家在 2024 年发表了第一个这样的全脑模型(Shiu et al., Nature),原版跑 0.5 秒的脑活动要 26 秒,每跑一次实验都要等。这个项目把同样的模型加速了 27 倍,0.5 秒的脑活动 0.98 秒算完,并用一整套验证确认加速没有损失精度。在此之上还做了两件工具,一个是能在浏览器里边跑边操作的实时控制台,一个是本页下面就能直接玩的交互回放。

138,639
神经元,来自 FlyWire 真实测绘
8,861
种细胞类型,可按类型刺激
27×
比原版 PyTorch 后端快
0.98 s
算完 0.5 秒全脑活动
0.45 GB
显存占用,6 GB 显卡即可跑

在线试玩,三个真实实验的回放

下面是三次真实仿真的完整记录。每个回放里每个点是一个真实神经元的位置,金色闪光是它放电的瞬间。点播放,拖进度条,旋转大脑,把鼠标悬停在放电的神经元上能看到它的名字和放电频率。底部是几个关键神经元的膜电位波形,和示波器上看到的真实神经活动一个道理。

回放太大打不开的话,可以直接在新标签页打开 糖刺激、P9 前行、沉默蘑菇体 这三个文件,每个约 3 MB,数据全部内嵌。
这三个实验在干什么?

糖刺激复现了原论文的经典实验。果蝇腿上的糖味觉感受神经元被激活后,信号经过食道下区传到中枢脑,一路激活几百个神经元。1 秒脑时间里共有 403 个神经元放过电、17,393 次脉冲。

P9 前行刺激的是两个下行通路神经元 P9,原论文证明这能驱动果蝇向前行走。这个实验放电量小得多(130 个神经元、806 次脉冲),因为信号直奔运动输出而去,通路很短。

沉默蘑菇体是干预实验。蘑菇体是果蝇的学习记忆中枢,它的 96 个输出神经元(MBON)被永久沉默(紫色点)后再给糖刺激,全脑脉冲从 17,393 次降到 16,790 次。对比前两个回放,能直观看到一类神经元被拿掉之后信息流向怎么变。同样的损毁在活蝇身上要做遗传杂交和手术,在这里只要加一行命令参数。

它是怎么做到的

模型本身不复杂。每个神经元是一个渗漏积分发放单元,膜电位攒到阈值就放一次电,放电沿突触传给下游,突触的强弱和符号全部来自真实连接组。难的是规模。13.8 万个神经元每 0.1 毫秒算一步,原版实现一步要在 GPU 上启动约 75 次计算内核,时间几乎全花在启动开销上。FastBrain 引擎用了四招把这个开销压下去。

FastBrain 数据流示意
事件驱动,只算放电的神经元

每一瞬间放电的神经元只有几百个,占 0.3%。引擎把突触矩阵预先切成 15.1 万个定长小块,每步只把放电神经元的块拣出来做乘加,不再对全图做稠密乘法。

CUDA Graph,一万次启动合成一次

所有张量形状固定之后,连续的 16 步仿真被录制成一张 CUDA Graph,一次启动跑完,每步的内核启动数从约 75 降到约 33。

延迟环,把突触延迟变成编译期常量

突触传递有 1.8 毫秒延迟。引擎用一个环形缓冲区存中间的信号,环长取延迟步数的整数倍,寻址在编译期就确定,运行时零开销。

快和准分开验,都要过

加速引擎和原版逐指标做了对比。放电率相关系数 0.990,而原版自己换个随机种子重跑的相关也只有 0.991。两个引擎的差异,和同一模型换颗骰子的差异一样大。验证细节见下面"准不准"一节。

跑得到底有多快

同一台 RTX 3060 Laptop、同一个实验(糖刺激 200 Hz、仿真 0.5 秒)、同一套计时代码。

各后端仿真耗时对比
后端运行次数仿真耗时实时比
PyTorch (CUDA),原版126.30 s0.019×
FastBrain,dt 0.25 ms10.98 s0.51×
FastBrain,dt 0.1 ms(论文步长)12.43 s0.21×

实时比 0.51× 的意思是脑里过 1 秒,机器只要 2 秒。换成更好的显卡(比如 RTX 5080)可以超过实时。计时的完整数据在仓库 data/results/local_fastbrain/ 里。

准不准,和原版逐点对账

验证覆盖了 2 种刺激 × 2 种时长 × 5 个随机种子 × 3 种步长的完整矩阵,外加 10 秒长程漂移检查。每个指标的及格线是差异必须小于参考模型自身换随机种子产生的噪声。

指标参考模型自身噪声FastBrain vs 参考结论
放电率相关系数0.9910.990噪声之内
活跃神经元集合重合度(Jaccard)0.9280.92噪声之内
脉冲时序精度(±2 ms)0.3420.34噪声之内
10 秒长程漂移—逐秒相关 0.989–0.996无发散
10 秒长程漂移检查

下图是糖刺激实验的全脑脉冲栅格。每一行是一个放电的神经元,每个点是一次脉冲,按首次放电时间排序,能清楚看到信号从感受神经元(底部)逐级向上游中枢传播的波浪。

糖刺激实验的全脑脉冲栅格图

在自己电脑上跑一遍

仓库带一个实时控制台。模型在 GPU 上跑,浏览器里同步看到全脑放电,可以随手加刺激、挂探针、暂停重置。装环境大约十分钟,需要 Python 和 CUDA 版 PyTorch,双击 run_live.bat 就能打开。

实时控制台:全脑动画加 8 通道膜电位示波器

控制台全貌。左边选细胞类型加刺激,中间是全脑放电动画,底部示波器是 8 个神经元的实时膜电位。

控制台全屏模式

一键全屏看脑。每个点是一个真实位置的神经元,金色闪光是放电。

完整的操作教程和脚本接口写在仓库的 experiments/LIVE_CONSOLE.md,本页的三个回放用 run_replay.bat 一条命令就能重新生成。

仓库地址是 github.com/ArcadiaE/fly-brain,fork 自 eonsystemspbc/fly-brain,GPL-2.0。

下一步做什么

阶段内容状态
0FastBrain 引擎与系统验证矩阵已完成,即本页内容
1把模型放电和公开钙成像实验数据做首次动力学级对比(DANDI 001869 视觉威胁数据集、Aimon 2019 气味数据集);审计原论文结论对突触符号和权重的敏感性进行中
2两个方向选一个。一是用贝叶斯优化反向设计刺激方案,产出可执行的 split-GAL4 驱动线建议;二是把蘑菇体三因子学习规则嵌入全脑模型,先在孤立蘑菇体上复现条件反射,再做全脑消融待启动

方法论上定了两条规矩。任何结论都必须带一个度数匹配的重连网络做空白对照,任何数字都要能溯源到原始文献。

数据与引用

  • 基础模型:Shiu et al. 2024, Nature 634:210–219,PMC11446845
  • 连接组:FlyWire v783 公开版,138,639 个神经元全部有细胞类型标注
  • 本仓库:github.com/ArcadiaE/fly-brain;基准原始数据 data/results/local_fastbrain/,验证矩阵 experiments/out/validation/
  • 阶段 1 目标数据集:DANDI 001869(looming 视觉威胁)、Aimon et al. 2019(气味响应,CRCNS 10.6080/K01J97ZN)

FastBrain · Real-time Fly Whole-Brain Simulation

138,639 neurons~15M synapsesFlyWire v783 connectomeconsumer GPUopen source
Whole fly brain with firing neurons highlighted

This repository puts an entire fruit fly brain into a computer. The model has 138,639 neurons and about 15 million synapses, all taken from real connectome mapping data, and it runs in real time on a 6 GB gaming GPU. You can stimulate neurons and watch the pulses spread across the whole brain.

Neuroscientists published the first such whole-brain model in 2024 (Shiu et al., Nature), and the original takes 26 seconds to simulate half a second of brain activity, which makes experiments painful to run. This project makes the same model 27 times faster, computing half a second of brain activity in 0.98 seconds, and a validation suite confirms the speedup costs nothing in accuracy. On top of that it adds two tools, a live console you can operate in a browser while the simulation runs, and the interactive replays you can play with right below.

138,639
neurons from real FlyWire mapping
8,861
cell types, all individually stimulable
27×
faster than the original PyTorch backend
0.98 s
to simulate 0.5 s of brain activity
0.45 GB
VRAM; any 6 GB GPU can run it

Try it: replays of three real experiments

Below are complete recordings of three real simulations. Every dot is a real neuron's position, and each gold flash is the moment it fires. Press play, scrub the timeline, rotate the brain, and hover over firing neurons to see their names and rates. The traces at the bottom are membrane voltages of a few key neurons, the same kind of signal an electrophysiologist sees on an oscilloscope.

Trouble loading? Open the replays in a new tab: sugar · P9 walking · mushroom body silenced (about 3 MB each, all data embedded)
What are these three experiments?

Sugar reproduces the paper's classic experiment. Activating the sugar gustatory receptor neurons on the fly's leg sends the signal through the subesophageal zone into the central brain, recruiting a few hundred neurons along the way. Over one second of brain time, 403 neurons fire a total of 17,393 spikes.

P9 walking stimulates two descending-pathway neurons called P9, which the original paper showed can drive forward walking. Much less of the brain lights up (130 neurons, 806 spikes) because the signal runs straight to the motor output over a very short pathway.

Silenced mushroom body is an intervention. The mushroom body is the fly's center of learning and memory. With its 96 output neurons (MBONs) permanently silenced (purple dots), the same sugar stimulus produces 16,790 spikes instead of 17,393. Comparing the two replays shows how information flow changes when one class of neurons is removed. The same lesion on a living fly takes genetic crosses and surgery; here it takes one command-line flag.

How it works

The model itself is simple. Each neuron is a leaky integrate-and-fire unit that fires when its membrane voltage crosses a threshold, and the spike travels down its synapses, whose strengths and signs all come from the real connectome. The hard part is scale. 138,639 neurons step every 0.1 millisecond, and the original implementation launches about 75 GPU kernels per step, spending nearly all its time on launch overhead. The FastBrain engine cuts that overhead in four ways.

FastBrain dataflow schematic
Event-driven: only compute the neurons that fire

Only a few hundred neurons fire at any instant, about 0.3% of the brain. The synapse matrix is pre-cut into 151,000 fixed-size blocks; each step gathers only the blocks belonging to firing neurons, instead of multiplying against the whole graph.

CUDA Graph: ten thousand launches become one

With every tensor pinned to a fixed shape, 16 consecutive simulation steps are recorded into a single CUDA graph and launched once, cutting kernel launches from about 75 to about 33 per step.

Delay ring: synaptic delay as a compile-time constant

Synaptic transmission takes 1.8 ms. The engine stores in-flight signals in a ring buffer whose length is a multiple of the delay in steps, so addressing is resolved at capture time and costs nothing at run time.

Accuracy holds against the original

Compared metric by metric against the original, the firing-rate correlation is 0.990, while the original compared against itself with a different random seed reaches 0.991. The two engines differ by exactly as much as the same model re-rolled with a new die. Details are in the accuracy section below.

How fast, exactly

Same RTX 3060 Laptop, same experiment (sugar stimulation at 200 Hz, 0.5 s simulated), same timing procedure.

Simulation time by backend
BackendRunsSim timeReal-time ratio
PyTorch (CUDA), original126.30 s0.019×
FastBrain, dt 0.25 ms10.98 s0.51×
FastBrain, dt 0.1 ms (paper's step)12.43 s0.21×

A ratio of 0.51× means one second of brain time costs two seconds of wall time. A stronger GPU (an RTX 5080, say) goes past real time. Full timing data lives in data/results/local_fastbrain/.

Is it accurate: checked line by line against the original

The validation covers a full matrix of 2 stimuli × 2 durations × 5 random seeds × 3 time steps, plus a 10-second long-run drift check. For every metric, the difference must be smaller than the noise the reference model produces against itself just by changing its random seed.

MetricReference self-noiseFastBrain vs referenceVerdict
Firing-rate correlation0.9910.990within noise
Active-set overlap (Jaccard)0.9280.92within noise
Spike-time precision (±2 ms)0.3420.34within noise
10 s long-run drift—per-second correlation 0.989–0.996no divergence
Ten-second drift check

Below is the whole-brain spike raster of the sugar experiment: each row is one firing neuron, each dot one spike, rows sorted by first-spike time. The wave of activity climbing from the receptor neurons at the bottom up into the central brain is clearly visible.

Whole-brain spike raster of the sugar experiment

Run it on your own machine

The repository ships a live console: the model runs on your GPU while a browser shows the whole brain spiking in sync, and you can add stimuli, attach voltage probes, pause and reset at will. Setup takes about ten minutes (Python plus a CUDA build of PyTorch); double-click run_live.bat and the console opens.

Live console with 8-channel voltage oscilloscope

The console: pick a cell type to stimulate on the left, watch the brain in the middle, read real membrane voltages of 8 neurons on the oscilloscope below.

Console in fullscreen brain view

One click to fullscreen. Every dot is a neuron at its real position; gold flashes are spikes.

The full operating guide and the scripting API live in experiments/LIVE_CONSOLE.md; the three replays on this page regenerate with one run_replay.bat command.

Repository: github.com/ArcadiaE/fly-brain (forked from eonsystemspbc/fly-brain, GPL-2.0).

What comes next

PhaseContentStatus
0The FastBrain engine and its systematic validation suitedone, this page
1First dynamics-level comparison of model spikes against public calcium-imaging datasets (DANDI 001869 looming stimuli; Aimon 2019 odors); audit how sensitive the paper's conclusions are to synapse signs and weightsin progress
2One of two: inverse stimulus design with Bayesian optimization (deliverable: an actionable split-GAL4 driver-line suggestion); or embedding three-factor mushroom-body learning into the whole-brain model, reproducing conditioning in an isolated mushroom body first, then whole-brain ablationqueued

Two standing rules: every claim ships with a degree-matched rewired null network as control, and no number is used unless it traces back to a primary source.

Data and references

  • Base model: Shiu et al. 2024, Nature 634:210–219, PMC11446845
  • Connectome: FlyWire v783 public release; all 138,639 neurons carry cell-type annotations
  • This repository: github.com/ArcadiaE/fly-brain; raw benchmark data in data/results/local_fastbrain/, validation matrix in experiments/out/validation/
  • Phase-1 target datasets: DANDI 001869 (looming visual threat), Aimon et al. 2019 (odor responses, CRCNS 10.6080/K01J97ZN)