Hacking Generative Models with Differentiable Network Bending

Giacomo Aldegheri, Alina Rogalska, Ahmed Youssef, Eugenia IofinovaarXiv 2023 · DOI

Abstract

Traditional generative AI research prioritizes high-fidelity realism, often overlooking the creative potential of model failure and subversion. This paper introduces a differentiable framework for "network bending," allowing researchers to "hack" pre-trained generative models. By inserting small, trainable bending modules between the internal layers of a frozen generator and optimizing them via a CLIP-based loss, the authors steer models toward entirely new concepts. This process creates a unique "glitch art" aesthetic characterized by a visual tension between the model's original training data and its new, surreal objectives.

Introduction

In the digital art world, there is a long-standing tradition of "glitch art"—finding beauty in systems that fail or are repurposed for unintended tasks. However, most modern generative models are designed as "black boxes" aimed at perfection. Existing techniques for manipulating these models often require massive computational resources or offer limited artistic control over the internal mechanisms of the network.

To bridge this gap, the authors adapt network bending—a technique for manipulating intermediate layers—into a differentiable framework. This allows artists and researchers to use gradient descent to find specific "hacks" that push a model away from its original training distribution toward a new, often uncanny, objective. By training only tiny internal modules while keeping the rest of the network frozen, the approach achieves high-speed, creative redirection of generative models.

Methodology: Differentiable Network Bending

The core of this approach is the Bending Module (BM). Rather than retraining an entire model, the researchers insert a small, trainable neural network between two existing layers of a frozen generator (specifically a GAN).

Overview of the Differentiable Network Bending pipeline. A trainable Bending Module is inserted into a frozen generator, optimized via a CLIP-based loss.

The researchers experimented with three distinct BM architectures to achieve different visual effects:

  1. Convolutional: A simple CNN that modifies features locally.
  2. Convolutional + Coordinates: A CNN that also receives $(x, y)$ spatial coordinates, allowing it to generate structures that vary across the image plane.
  3. Convolutional + Sorting: A module that utilizes a differentiable sorting network to physically rearrange the spatial structure of the internal activation maps.

To train these modules, the authors employed two types of loss functions based on CLIP (Contrastive Language-Image Pre-training). The Standard CLIP Loss minimizes the distance between the generated image's embedding and a target text prompt's embedding. To prevent mode collapse and encourage visual variety, they also utilized an InfoNCE Loss, a contrastive objective that pushes the image toward the prompt while simultaneously pushing different images in a batch away from each other.

Experimental Setup

The authors utilized ButterflyGAN, a lightweight GAN trained on a dataset of approximately 1,000 butterfly images. This specific model was chosen because its narrow domain makes the "hacking" effect highly visible: the ghostly silhouette of a butterfly remains apparent even when the model is forced to generate something entirely different, such as a "brutalist robot."

Key Insights and Results

The paper primarily presents qualitative results that demonstrate the artistic potential of the method. Because only the tiny BM is being trained, the "hacking" process is remarkably efficient, taking approximately 3 minutes on a single consumer-grade GPU (RTX 3080 Ti).

Qualitative results showing the "glitch art" aesthetic. The model retains the structural memory of a butterfly while being steered toward novel text prompts.

The Beauty of Tension

The most compelling results arise from the "tension" between the original model's weights (which are optimized to produce butterflies) and the BM's objective (which might be steered toward a "psychedelic deity"). This creates an uncanny quality that is difficult to replicate with standard text-to-image models like Stable Diffusion, which lack this inherent structural resistance.

Diversity and Spatial Control

The researchers found that using a standard CLIP loss often led to "mode collapse," resulting in smooth but repetitive images. Switching to an InfoNCE loss significantly increased the variety of colors and textures. Furthermore, while coordinate-aware BMs improved the segmentation of different areas of the image compared to vanilla convolutional BMs, the models still struggled with global spatial reasoning. For instance, when prompted for a "French flag," the model might correctly generate the colors in local segments but fail to arrange them into three perfect vertical stripes.

Conclusion and Future Work

Differentiable network bending provides a fast, efficient way to explore the internal latent spaces of generative models for artistic purposes. While the method offers excellent control over texture and "vibe," it currently provides only coarse control over global geometry. Future work could explore applying these differentiable modules to much larger architectures, such as Diffusion models or large-scale Transformers, to determine if this unique "uncanny" aesthetic persists at higher resolutions and across broader datasets.

Summary updated

BibTeX
@misc{aldegheri2023hacking,
  author = {Giacomo Aldegheri and Alina Rogalska and Ahmed Youssef and Eugenia Iofinova},
  title = {{Hacking Generative Models with Differentiable Network Bending}},
  year = {2023},
  eprint = {2310.04816},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.04816},
}
Figure