Rayane Goghrod
← Writing

Neural Cellular Automata in PyTorch

A PyTorch reproduction of the Learning to Grow experiment from Growing Neural Cellular Automata.

Work in progress: The project currently reproduces the Learning to Grow experiment, with persistence, regeneration, and original NCA experiments planned next.

The model learns local cell update rules that grow a recognizable lizard from a single living cell.

View the project on GitHub ↗

Learning to grow

The animation shows a rollout from one living cell. Each cell carries 16 channels: four visible RGBA channels and 12 hidden channels. Convolutions provide neighborhood perception, and a stochastic update mask decides which cells update at each step.

Animated neural cellular automaton growing a green lizard from one living cell
One cell growing into the learned lizard over repeated NCA steps.

Current result

Training backpropagates through repeated NCA steps. In the latest 500-update run, training loss fell from 0.0986 to 0.0107. The model learns the growth process, but it still becomes unstable during very long rollouts.

Target
Target image of a green lizard used to train the neural cellular automaton
Final state
Final state produced by the trained neural cellular automaton, resembling the target lizard

Rollout metrics

Image error is pixel-wise mean squared error (MSE) over all four RGBA channels of the 40×40 target. I evaluated the stochastic update mask with 20 fixed random seeds.

Measurement RGBA MSE
Displayed final state at step 64 0.02207
Best mean result, at step 80 0.01123 ± 0.00074
Step 96 0.01951 ± 0.00140
Step 128 0.06118 ± 0.00305
Step 256 0.60126 ± 0.05772

The lowest mean error occurs at step 80. Using a divergence threshold of twice that minimum, with the error remaining above it through step 256, the model crosses the threshold at step 100 and exceeds the original seed’s error at step 149. It learns growth, but not persistence yet.

View the rollout evaluation data ↗

Sobel filter experiment

The reference implementation divides its Sobel filters by 8. I compared that version with unscaled filters over five matched training seeds. Each pair used the same initial weights and stochastic masks, with 60 optimizer updates, an 80-step rollout, and a batch size of 8. The lines show the mean and the shaded areas show one standard deviation across seeds.

Line chart comparing training loss for Sobel filters divided by eight and unscaled Sobel filters across five matched seeds
Mean RGBA MSE over five matched seeds; shaded areas show one standard deviation.
Variant Final-10 mean loss First update below 0.03
Sobel /8 0.03518 ± 0.00129 Not reached
Unscaled Sobel 0.02413 ± 0.00058 22

In this short experiment, the unscaled filters reduced the final-10 mean loss by 31.4%. This is an early optimization result, not evidence that unscaled Sobel filters are always better.

View the Sobel comparison data ↗

What I learned

  • Local update rules can coordinate many cells into a recognizable global structure.
  • Hidden cell state gives the system room to carry information beyond visible RGBA values.
  • Stochastic updates make the model learn without every cell changing on every step.
  • Backpropagation through time trains the same local rule across a full growth rollout.

Next steps

Next I plan to train for persistence, test regeneration after damage, and explore possible evolutionary experiments alongside gradient-based training.