Tutorial 4b

Neurons with a dendrite#

Open In Colab about 20 min on Colab’s T4 GPU

Real neurons are not points. Their dendrites often receive separate streams of input and process them partly independently of the soma. We take the simplest case, a spiking soma coupled to a passive dendrite, with current flowing both ways between them and separate synapses, and so separate weights and gradients, for each. The spike count now depends on two input currents, so ChronoProp fits an FI plane, as in Tutorial 4a.

To make both compartments necessary, we use addSHD. An English spoken digit drives the somata, a German one the dendrites, and the network must report their sum, which neither digit determines alone. We measure the FI plane, look at the proxy’s gradients, and train both methods, as in the paper’s Supplementary Fig. 7. To run it on Colab’s GPU, please select Runtime → Change runtime type → T4 GPU.

Supplementary Fig. 7a: the addSHD task
# install ChronoProp (skipped when it is already installed)
try:
    import chronoprop as cp
except ImportError:
    %pip install -q "chronoprop @ git+https://github.com/Poirazi-Lab/chronoprop"
    import chronoprop as cp

import matplotlib.pyplot as plt
import numpy as np
import torch
from torch.utils.data import Subset

cuda = torch.cuda.is_available()
device = torch.device('cuda' if cuda else 'cpu')
print(device)
cuda

Settings#

The options are those of Tutorials 3 and 4a. We train for 40 epochs and at the coarse timestep, where an epoch costs three to four times less than at the fine one.

ARCH = 'rec'         # 'rec' (recurrent) or 'ff' (feedforward)
TIMESTEP = 'coarse'  # 'coarse' (1 ms) or 'fine' (0.1 ms, 3-4x slower per epoch)
EPOCHS = 40          # the paper trains for 500
SEED = 1234          # the first of the paper's 10 seeds
DATA_DIR = 'data/SHD'
SUBSET = 0           # keep only the first SUBSET pairs per split; 0 keeps all

The two-compartment neuron#

The soma is the LIF neuron of Tutorial 1. The dendrite is a second membrane, \(V_d\), that integrates its own synaptic current \(I_d\) and exchanges current with the soma through a coupling conductance \(g_c\), and only the soma has a threshold and fires:

\[\begin{split}\begin{aligned} V_d[t] &= \alpha\, V_d[t-1] + (1-\alpha)\,\big(R\, I_d[t] + g_c\,(V_s[t-1] - V_d[t-1])\big) \\ V_s[t] &= \alpha\, V_s[t-1] + (1-\alpha)\,\big(R\, I_s[t] - g_c\,(V_s[t-1] - V_d[t-1])\big) \end{aligned}\end{split}\]

\(I_s\) and \(I_d\) are the synaptic currents of the two compartments (each filtered as in Tutorial 1), \(\alpha = e^{-\Delta t/\tau_\text{mem}}\), and the soma spikes and resets as before; here \(g_c = 1\). To see how the two inputs combine, we drive the neuron for 50 ms with a constant current into the soma, into the dendrite, or into both, and count its spikes in each 10 ms window.

dt = cp.configs.TIMESTEPS[TIMESTEP]['dt']
window_steps = cp.fi.window_steps(cp.configs.WINDOW, dt)  # steps per 10 ms window
neuron = cp.neurons.TwoCompartmentLIF(
    threshold_soma=1.0, reset_soma=0.0, tau_mem=10e-3, tau_syn=2e-3, R=5.0, dt=dt,
    device='cpu', **cp.configs.DENDRITE)

# name: (somatic current, dendritic current, colour)
cases = {'soma only (0.25)': (0.25, 0.0, 'tab:blue'),
         'dendrite only (0.5)': (0.0, 0.5, 'tab:green'),
         'both': (0.25, 0.5, 'tab:red')}
n_windows = 5
no_input = torch.zeros(1, 1)
windows = np.arange(1, n_windows + 1)

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11, 2.8))
for i, (name, (I_s, I_d, color)) in enumerate(cases.items()):
    soma, dend = torch.tensor([[I_s]]), torch.tensor([[I_d]])
    state = neuron.initialize_state(1, 1)
    voltage = []
    counts = np.zeros(n_windows, int)
    with torch.no_grad():
        for t in range(n_windows * window_steps):
            spike, state = neuron(no_input, no_input, state,
                                  external_current_soma=soma, external_current_dend=dend)
            voltage.append(1.2 if spike else state[0].item())  # draw each spike as a short stroke
            counts[t // window_steps] += int(spike)
    time_ms = np.arange(len(voltage)) * dt * 1e3
    ax1.plot(time_ms, voltage, color=color, lw=1, label=name)
    ax2.bar(windows + (i - 1) * 0.27, counts, 0.27, color=color, label=name)

ax1.axhline(1.0, color='0.5', ls=':', lw=1)  # the threshold
for k in range(1, n_windows):
    ax1.axvline(k * 10, color='0.85', lw=0.8, zorder=0)  # window boundaries
ax1.set_xlabel('time (ms)')
ax1.set_ylabel('soma voltage $V_s$')
ax1.set_title('the soma')
ax1.legend(fontsize=8, loc='lower right')
ax2.set_xticks(windows)
ax2.set_xlabel('time window')
ax2.set_ylabel('spikes')
ax2.set_ylim(0, 3)
ax2.legend(fontsize=8, loc='upper left')
ax2.set_title('spike count per window')
plt.tight_layout()
../_images/372faae591eb8ab478eabc764abfaf4cef0c9897c90aeaa393ae886e00c3821e.png

Neither input fires the neuron alone, because each leaves the soma below its threshold (dotted). Together they drive it across, and it fires in every window after the first. The first window stays silent because the dendrite’s input reaches the soma late, first charging the dendrite and then spreading through the coupling.

Measuring the FI plane#

measure_fi_plane_dendrite injects every combination of 101 somatic and 101 dendritic currents into the resting neuron for one window and counts the spikes. A rectified linear function of the two currents fits the counts:

\[N = \max\big(0,\; g_d\, I_d + g_s\,(I_s - \theta)\big)\]

with somatic gain \(g_s\), dendritic gain \(g_d\) and somatic threshold \(\theta\) (gain_soma, gain_dend and threshold_soma in the code).

I_s, I_d, N = cp.fi.measure_fi_plane_dendrite(neuron, num_steps=window_steps,
                                              **cp.configs.FI_PLANE_DENDRITE)
fit = cp.fi.fit_relu_dendrite(I_s, I_d, N)
ratio = fit['gain_dend'] / fit['gain_soma']
print(f"g_s = {fit['gain_soma']:.3f}, g_d = {fit['gain_dend']:.3f}, "
      f"theta = {fit['threshold_soma']:.3f}, R² = {fit['r_squared']:.3f}")

soma_grid, dend_grid = np.meshgrid(I_s.numpy(), I_d.numpy(), indexing='ij')
fitted = np.maximum(0, fit['gain_soma'] * (soma_grid - fit['threshold_soma'])
                    + fit['gain_dend'] * dend_grid)
onset = fit['threshold_soma'] - ratio * I_d.numpy()  # where the fit leaves 0

fig, axes = plt.subplots(1, 2, figsize=(11, 3.4), sharey=True)
for ax, Z, title in zip(axes, [N.numpy(), fitted], ['measured', 'fitted']):
    im = ax.imshow(Z.T, origin='lower', aspect='auto', extent=[0, 1, 0, 1],
                   cmap='viridis', vmin=0, vmax=N.max().item())
    ax.plot(onset, I_d.numpy(), 'w--', lw=1)
    ax.set_xlim(0, 1)
    ax.set_xlabel('somatic current $I_s$')
    ax.set_title(title)
axes[0].set_ylabel('dendritic current $I_d$')
fig.colorbar(im, ax=axes, label='spikes per window')
g_s = 4.546, g_d = 1.390, theta = 0.295, R² = 0.956
<matplotlib.colorbar.Colorbar at 0x787294afcc20>
../_images/8734bdff1efa944779260771b5c7a798b86954613b4269b5e18881429e622ea2.png

Dendritic input lowers the somatic current the neuron needs, but never fires it alone within one window, so the measured plane is silent along its left edge. The dashed line is where the fitted plane leaves zero, \(I_s = \theta - (g_d/g_s)\, I_d\).

The backward pass#

In training, each hidden neuron has two drives in every window, the window’s input spike counts times the soma’s weights and the same for the dendrite’s weights. The proxy (SpikesToRateDendrite) passes the simulated spike count forward unchanged. In the backward pass, wherever the fitted plane is above zero, it sends the gradient to both drives, scaled by each compartment’s gain, \(g_s\) for the somatic drive and \(g_d\) for the dendritic one. Below the onset, neither gets a gradient. Two neurons with the same somatic drive but different dendritic drives:

g_s, g_d, theta, _ = cp.fi.proxy_from_dendritic_neuron(neuron, window=cp.configs.WINDOW, dt=dt,
                                                      tau_syn=cp.configs.NEURON['tau_syn'])
proxy = cp.proxy.SpikesToRateDendrite(g_s, g_d, theta)

drive_soma = torch.tensor([1.0, 1.0], requires_grad=True)  # same somatic drive in the window
drive_dend = torch.tensor([0.0, 3.0], requires_grad=True)  # different dendritic drives
counts = torch.tensor([0.0, 2.0])                          # counts from the simulation
proxy(drive_soma, drive_dend, counts).sum().backward()
for k in range(2):
    print(f'dendritic drive {drive_dend[k]:.0f}: gradient to soma {drive_soma.grad[k]:.3f}, '
          f'to dendrite {drive_dend.grad[k]:.3f}')
dendritic drive 0: gradient to soma 0.000, to dendrite 0.000
dendritic drive 3: gradient to soma 1.155, to dendrite 0.353

The first neuron sits below its onset and gets no gradient. The dendritic drive of the second lifts it above, and both of its compartments receive one. As in Tutorials 1 and 4a, proxy_from_dendritic_neuron has moved the fit onto the axis of the window’s summed input, dividing both gains by the factor between the axes and multiplying the threshold by it.

Data#

load_addshd pairs each English recording with a German one, split as in the paper, and stacks the two into items of shape [time steps, 2, 700], channel 0 for the somata and channel 1 for the dendrites. The label is the sum of the two digits, so the network chooses among 19 classes, 0 to 18. Training pairs are redrawn every epoch, while validation and test pairs stay fixed.

dt_us = cp.configs.TIMESTEPS[TIMESTEP]['dt_us']
train, val, test = cp.data.load_addshd(DATA_DIR, dt_us=dt_us, seed=SEED)
print(f'{len(train)} training, {len(val)} validation, {len(test)} test pairs')

example = 2
x_eng, x_ger, label = train.pair(example)
eng_digit = train.eng[example][1] % 10  # SHD numbers the German digits 10-19
ger_digit = train.ger[int(train.partner[example])][1] % 10
panels = [(x_eng, f'English digit {eng_digit}, to the somata', 'tab:blue'),
          (x_ger, f'German digit {ger_digit}, to the dendrites', 'tab:green')]

fig, axes = plt.subplots(1, 2, figsize=(11, 2.6), sharey=True)
for ax, (frames, title, color) in zip(axes, panels):
    steps, channels = frames[:, 0, :].nonzero(as_tuple=True)
    ax.plot(steps * dt_us / 1e3, channels, '|', ms=2, color=color)
    ax.set_xlabel('audio time (ms)')
    ax.set_title(title)
axes[0].set_ylabel('input channel')
plt.tight_layout()
print(f'one training pair: {eng_digit} + {ger_digit} = label {label}')
if SUBSET:
    train, val, test = (Subset(d, range(min(SUBSET, len(d)))) for d in (train, val, test))
Downloading https://zenkelab.org/datasets/shd_train.h5.zip ...
Downloading https://zenkelab.org/datasets/shd_test.h5.zip ...
3409 training, 602 validation, 1079 test pairs
one training pair: 6 + 9 = label 15
../_images/7170191be21acce8af6ef7cc405214fd308b296fc9db1cfde2d4a7bca8cdc780.png

Training#

build_fig4b_network builds the networks of Tutorial 3 with two-compartment hidden neurons, as in the paper. They have 256 feedforward or 221 recurrent units (the input side counts both streams, and both networks have about 363,000 weights), recurrent spikes return to the somata, and each method uses the learning rate the paper selected on validation in this condition. For ChronoProp, it measures and fits the FI plane above before creating the network. BPTT needs no fit, because its surrogate gradient flows step by step through the soma and, through the coupling, into the dendrite.

Colab limitations

addSHD needs many epochs. The paper trained for 500, and its networks reached their best validation accuracy only between epochs 410 and 480 on average. For practical reasons we limit both the timestep and the training here, to Δt = 1 ms and 40 epochs. The accuracies below are therefore far from the paper’s final ones, although they follow the paper’s runs over the same epochs. For the full results, see Supplementary Fig. 7 of the paper.

results = {}
for method in ['chronoprop', 'bptt']:
    cp.set_seed(SEED)
    net, info = cp.configs.build_fig4b_network(ARCH, method, TIMESTEP, device)
    n_weights = sum(p.numel() for p in net.parameters())
    print(f"--- {method}: hidden {info['hidden']}, {n_weights:,} weights, "
          f"learning rate {info['lr']:g}")
    if method == 'chronoprop':
        print(f"    {info['window_steps']} steps per window, "
              f"FI plane fit R² = {info['fi']['r_squared']:.3f}")
        window = info['window_steps']
    else:
        window = 1  # BPTT has no time windows
    if cuda:
        net = cp.jit(net)  # compiled, as in the paper
    results[method] = cp.train.train(
        net, train, test, val_data=val, batch_size=128, epochs=EPOCHS, lr=info['lr'],
        device=device, window_steps=window, recurrent=ARCH == 'rec',
        num_workers=2, pin_memory=cuda)
--- chronoprop: hidden 221, 362,440 weights, learning rate 0.00015
    10 steps per window, FI plane fit R² = 0.956
Epoch 1/40 | train loss 3.0042 | val acc 8.64% | test acc 9.18% | 14.6 s
Epoch 2/40 | train loss 2.8197 | val acc 7.97% | test acc 8.62% | 13.4 s
Epoch 3/40 | train loss 2.7826 | val acc 9.30% | test acc 10.47% | 12.8 s
Epoch 4/40 | train loss 2.7683 | val acc 8.47% | test acc 10.75% | 13.4 s
Epoch 5/40 | train loss 2.7350 | val acc 9.30% | test acc 11.40% | 13.4 s
Epoch 6/40 | train loss 2.7105 | val acc 10.30% | test acc 12.79% | 13.6 s
Epoch 7/40 | train loss 2.6867 | val acc 11.13% | test acc 11.77% | 13.7 s
Epoch 8/40 | train loss 2.6778 | val acc 10.30% | test acc 11.31% | 13.6 s
Epoch 9/40 | train loss 2.6527 | val acc 10.47% | test acc 12.14% | 13.9 s
Epoch 10/40 | train loss 2.6459 | val acc 11.46% | test acc 10.10% | 13.8 s
Epoch 11/40 | train loss 2.6241 | val acc 13.12% | test acc 12.05% | 13.6 s
Epoch 12/40 | train loss 2.6043 | val acc 11.96% | test acc 11.96% | 13.9 s
Epoch 13/40 | train loss 2.5847 | val acc 12.62% | test acc 13.53% | 13.6 s
Epoch 14/40 | train loss 2.5852 | val acc 13.29% | test acc 13.99% | 13.9 s
Epoch 15/40 | train loss 2.5655 | val acc 13.79% | test acc 12.97% | 13.5 s
Epoch 16/40 | train loss 2.5663 | val acc 14.62% | test acc 13.44% | 13.0 s
Epoch 17/40 | train loss 2.5386 | val acc 14.12% | test acc 15.29% | 13.3 s
Epoch 18/40 | train loss 2.5346 | val acc 14.62% | test acc 15.48% | 13.5 s
Epoch 19/40 | train loss 2.5077 | val acc 14.12% | test acc 15.76% | 13.3 s
Epoch 20/40 | train loss 2.5111 | val acc 13.79% | test acc 15.38% | 13.9 s
Epoch 21/40 | train loss 2.4863 | val acc 15.78% | test acc 14.64% | 14.0 s
Epoch 22/40 | train loss 2.4872 | val acc 14.62% | test acc 14.92% | 14.0 s
Epoch 23/40 | train loss 2.4932 | val acc 15.95% | test acc 17.24% | 14.1 s
Epoch 24/40 | train loss 2.4510 | val acc 14.45% | test acc 16.68% | 14.0 s
Epoch 25/40 | train loss 2.4461 | val acc 14.95% | test acc 16.59% | 14.1 s
Epoch 26/40 | train loss 2.4370 | val acc 15.78% | test acc 17.05% | 13.7 s
Epoch 27/40 | train loss 2.4313 | val acc 16.78% | test acc 17.24% | 13.5 s
Epoch 28/40 | train loss 2.4376 | val acc 17.44% | test acc 17.79% | 13.7 s
Epoch 29/40 | train loss 2.4008 | val acc 17.77% | test acc 18.72% | 13.7 s
Epoch 30/40 | train loss 2.4114 | val acc 19.10% | test acc 18.91% | 13.8 s
Epoch 31/40 | train loss 2.3701 | val acc 19.60% | test acc 20.48% | 13.8 s
Epoch 32/40 | train loss 2.3847 | val acc 18.94% | test acc 20.57% | 13.1 s
Epoch 33/40 | train loss 2.3614 | val acc 19.60% | test acc 20.48% | 13.1 s
Epoch 34/40 | train loss 2.3561 | val acc 19.27% | test acc 20.20% | 13.4 s
Epoch 35/40 | train loss 2.3529 | val acc 20.10% | test acc 19.56% | 13.6 s
Epoch 36/40 | train loss 2.3347 | val acc 21.43% | test acc 23.17% | 13.7 s
Epoch 37/40 | train loss 2.3188 | val acc 22.59% | test acc 22.61% | 13.8 s
Epoch 38/40 | train loss 2.3074 | val acc 24.58% | test acc 20.11% | 13.9 s
Epoch 39/40 | train loss 2.2958 | val acc 21.26% | test acc 21.04% | 13.9 s
Epoch 40/40 | train loss 2.2770 | val acc 21.76% | test acc 23.26% | 13.7 s
--- bptt: hidden 221, 362,440 weights, learning rate 0.001
Epoch 1/40 | train loss 2.8783 | val acc 9.30% | test acc 11.49% | 15.0 s
Epoch 2/40 | train loss 2.7839 | val acc 8.80% | test acc 10.94% | 15.1 s
Epoch 3/40 | train loss 2.7544 | val acc 9.80% | test acc 11.77% | 15.1 s
Epoch 4/40 | train loss 2.7182 | val acc 10.96% | test acc 10.47% | 14.9 s
Epoch 5/40 | train loss 2.6909 | val acc 11.79% | test acc 11.77% | 14.8 s
Epoch 6/40 | train loss 2.8230 | val acc 8.47% | test acc 9.82% | 15.0 s
Epoch 7/40 | train loss 2.7451 | val acc 10.47% | test acc 11.12% | 15.0 s
Epoch 8/40 | train loss 2.7303 | val acc 12.29% | test acc 11.58% | 14.8 s
Epoch 9/40 | train loss 2.7599 | val acc 11.30% | test acc 11.12% | 14.8 s
Epoch 10/40 | train loss 2.7205 | val acc 8.47% | test acc 9.45% | 14.6 s
Epoch 11/40 | train loss 2.7851 | val acc 11.79% | test acc 11.21% | 14.7 s
Epoch 12/40 | train loss 2.8223 | val acc 10.13% | test acc 8.90% | 14.8 s
Epoch 13/40 | train loss 2.7375 | val acc 10.63% | test acc 10.57% | 14.4 s
Epoch 14/40 | train loss 2.7662 | val acc 9.97% | test acc 8.80% | 15.2 s
Epoch 15/40 | train loss 2.7664 | val acc 11.79% | test acc 10.19% | 14.7 s
Epoch 16/40 | train loss 2.7521 | val acc 10.30% | test acc 11.86% | 14.8 s
Epoch 17/40 | train loss 2.7422 | val acc 9.14% | test acc 12.51% | 14.8 s
Epoch 18/40 | train loss 2.7231 | val acc 10.80% | test acc 10.38% | 14.6 s
Epoch 19/40 | train loss 2.7033 | val acc 10.13% | test acc 11.03% | 14.8 s
Epoch 20/40 | train loss 2.6991 | val acc 13.62% | test acc 9.82% | 14.7 s
Epoch 21/40 | train loss 2.6802 | val acc 11.30% | test acc 10.75% | 14.7 s
Epoch 22/40 | train loss 2.6803 | val acc 10.13% | test acc 10.47% | 14.7 s
Epoch 23/40 | train loss 2.6708 | val acc 11.79% | test acc 12.05% | 15.0 s
Epoch 24/40 | train loss 2.6341 | val acc 11.13% | test acc 11.77% | 14.8 s
Epoch 25/40 | train loss 2.7658 | val acc 8.80% | test acc 9.55% | 14.8 s
Epoch 26/40 | train loss 2.7636 | val acc 9.14% | test acc 9.18% | 15.0 s
Epoch 27/40 | train loss 2.7373 | val acc 11.30% | test acc 10.75% | 14.6 s
Epoch 28/40 | train loss 2.6827 | val acc 10.30% | test acc 9.45% | 15.1 s
Epoch 29/40 | train loss 2.6848 | val acc 12.62% | test acc 10.47% | 14.9 s
Epoch 30/40 | train loss 2.6767 | val acc 10.13% | test acc 10.57% | 14.7 s
Epoch 31/40 | train loss 2.6562 | val acc 10.47% | test acc 11.40% | 14.9 s
Epoch 32/40 | train loss 2.6429 | val acc 9.97% | test acc 11.96% | 14.9 s
Epoch 33/40 | train loss 2.6430 | val acc 11.96% | test acc 10.66% | 14.8 s
Epoch 34/40 | train loss 2.6248 | val acc 12.29% | test acc 11.68% | 14.7 s
Epoch 35/40 | train loss 2.6334 | val acc 13.95% | test acc 12.05% | 14.6 s
Epoch 36/40 | train loss 2.6209 | val acc 10.96% | test acc 10.84% | 15.0 s
Epoch 37/40 | train loss 2.6068 | val acc 11.13% | test acc 13.81% | 14.3 s
Epoch 38/40 | train loss 2.5870 | val acc 15.12% | test acc 11.21% | 14.4 s
Epoch 39/40 | train loss 2.5758 | val acc 12.13% | test acc 13.44% | 14.7 s
Epoch 40/40 | train loss 2.5606 | val acc 15.45% | test acc 13.90% | 14.8 s

Comparison with the paper#

The figure compares the test accuracy reached here, at the epoch of best validation accuracy, with the paper’s mean ± s.d. over 10 seeds after 500 epochs. Light bars are the networks trained here and dark bars the paper’s.

names = {'chronoprop': 'ChronoProp', 'bptt': 'BPTT'}
dark = {'chronoprop': '#384860', 'bptt': '#E1963C'}
light = {'chronoprop': '#d7dadf', 'bptt': '#f5dcbd'}

fig, ax = plt.subplots(figsize=(4, 3))
for i, method in enumerate(['chronoprop', 'bptt']):
    here, _ = cp.train.test_at_best_val(results[method])
    ax.bar([-0.33, -0.15][i], here, 0.18, color=light[method], label=f'{names[method]} here')
for i, method in enumerate(['chronoprop', 'bptt']):
    paper = cp.configs.fig4b_cell(ARCH, TIMESTEP, method)
    ax.bar([0.15, 0.33][i], paper['mean'], 0.18, yerr=paper['sd'], color=dark[method],
           label=f'{names[method]} paper')
condition = {'rec': 'recurrent', 'ff': 'feedforward'}[ARCH]
ax.set_xticks([0], [f'{condition}, {TIMESTEP} timestep'])
ax.set_ylim(0, 100)
ax.set_ylabel('test accuracy (%)')
ax.spines[['top', 'right']].set_visible(False)
ax.legend(ncol=2, frameon=False, loc='lower center', bbox_to_anchor=(0.5, 1))
plt.tight_layout()
../_images/d1d989f79be233c1a1bef262d549356d69e95c77db564bb7ccd31ed7837e1412.png

In the paper, the comparison keeps the pattern of Tutorial 3 and of the adaptive neurons. BPTT is ahead in feedforward networks (43.93% against ChronoProp’s 33.54% at the coarse timestep), and ChronoProp is ahead in recurrent ones, by more at the fine timestep (57.69% against 19.12%) than at the coarse one (48.35% against 29.46%). Set TIMESTEP = 'fine' above to see the widest gap, at three to four times the cost per epoch.

Training cost#

Seconds per epoch and peak GPU memory of each method in this run.

for method in ['chronoprop', 'bptt']:
    r = results[method]
    line = f"{names[method]:10} {np.mean(r['epoch_seconds']):6.1f} s per epoch"
    if 'peak_memory_mb' in r:
        line += f", peak GPU memory {r['peak_memory_mb']:.0f} MB"
    print(line)
ChronoProp   13.7 s per epoch, peak GPU memory 282 MB
BPTT         14.8 s per epoch, peak GPU memory 259 MB

Summary#

ChronoProp trained networks of two-compartment neurons from an FI plane, measured once over the somatic and dendritic currents, and sent a gradient to each compartment’s weights. In 40 epochs of a recurrent network at the coarse timestep, it reached 20.11% test accuracy on addSHD and BPTT 13.90%. Both followed the paper’s runs over the same epochs, which go on to 48.35% and 29.46% after 500.

The two methods cost about the same here, with 7% less time per epoch for ChronoProp and 8% less peak memory for BPTT. At the coarse timestep a pair of recordings lasts only about 80 steps, so BPTT has a short chain to store, and the epoch totals also include loading the data and evaluating the networks, which cost the same for both. ChronoProp’s savings grow with the number of steps, as in Tutorial 2.

What’s next#