Searchable Intervention Dynamics for GAN Generators
Archival 2019 experiment. Kept for reproducibility and historical context. README refreshed in May 2026 for public release.
ContrastFlow is a winter-2019 AutoGAN extension that adds recurrent local contrast-transport cells to GAN generators so internal feature dynamics can be searched, visualized, ablated, and steered.
The visualizer shows a recurrent feature map update, not a final generated image. Each frame is one local contrast-transport step inside the generator.
| initial feature state | middle recurrent state | final recurrent state |
|---|---|---|
![]() |
![]() |
![]() |
The central idea is to make part of the generator explicitly dynamical:
h[t+1] = h[t] + gate(h[t]) * Transport(Contrast(h[t]), local_neighbors)
Instead of interpreting a GAN only after training, ContrastFlow exposes a designed intervention surface during generation.
flowchart LR
A["feature map h(t)"] --> B["local contrast"]
B --> C["local transport"]
C --> D["gated recurrent update"]
D --> E["intervention handle"]
E --> F["feature map h(t+1)"]
In this README, "causal" means explicit ablation and intervention handles inside the generator. It does not mean formal causal discovery.
By late 2019, AutoGAN had shown GAN architecture search, SAGAN had established self-attention for long-range feature interaction, Dynamic Filter Networks had shown adaptive local filters, GAN Dissection had shown causal unit intervention, and latent-space steering methods were emerging.
ContrastFlow's claim is the combination:
- searchable GAN primitive inside the AutoGAN-style search space
- recurrent local contrast transport over feature maps
- built-in intervention handles for generator dynamics
- contrastive prediction over internal recurrent time
The claim is not that ContrastFlow was the first recurrent GAN layer, the first interpretable GAN method, or the first GAN steering method. The contribution is an early combination of GAN NAS, local recurrent feature transport, and designed causal intervention hooks.
ContrastFlow was an early attempt to make neural generation inspectable and steerable from inside the model, not only through prompts, latents, or post-hoc visualization. The useful historical signal is the direction: model internals as systems that can be searched, watched, ablated, and controlled.
contrastflow/layer.py- differentiable recurrent local contrast transportcontrastflow/interventions.py- strength, mask, freeze, and reverse controlscontrastflow/contrastive_loss.py- internal-time contrastive predictioncontrastflow/visualizer.py- state maps and flow GIF exportmodels/autogan_contrastflow.py- AutoGAN generator with ContrastFlow cellscontrastflow/search_space.py- 2019-style search-space knobs
This repository intentionally keeps a 2019-era stack:
- Python 3.6
- PyTorch 1.1
- torchvision 0.3
- NumPy / SciPy
- Matplotlib / imageio
- TensorBoard / tensorboardX
Install:
pip install -r requirements.txtTrain the ContrastFlow AutoGAN variant:
sh exps/contrastflow_cifar10.shRun the local layer visualizer:
python demos/visualize_contrastflow.pyDocker reproduction for the 2019 environment:
docker build -f docker/Dockerfile.cuda9 -t contrastflow:2019 .
docker run --rm --gpus all -v "$PWD:/workspace" -w /workspace contrastflow:2019 python demos/visualize_contrastflow.pyContrastFlow exposes feature-dynamics controls:
flow_strengthcontrast_gainregion_maskchannel_maskfreeze_flowreverse_flow
These allow direct tests of which recurrent step, region, or channel group is responsible for local structure.
The intended comparisons are:
- vanilla AutoGAN
- AutoGAN plus ConvLSTM-style recurrence
- AutoGAN plus dynamic local filtering
- AutoGAN plus self-attention / SAGAN-style block
- ContrastFlow without recurrence
- ContrastFlow without contrastive prediction loss
- ContrastFlow without intervention hooks
See docs/ablation_plan.md.
This repository started from the public AutoGAN implementation:
@InProceedings{Gong_2019_ICCV,
author = {Gong, Xinyu and Chang, Shiyu and Jiang, Yifan and Wang, Zhangyang},
title = {AutoGAN: Neural Architecture Search for Generative Adversarial Networks},
booktitle = {The IEEE International Conference on Computer Vision (ICCV)},
month = {Oct},
year = {2019}
}ContrastFlow builds on that AutoGAN code path as a 2019-era generator dynamics experiment.



