NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Training-Free Constrained Generation With Stable Diffusion Models

Stefano Zampini, Jacob K Christopher, Luca Oneto, Davide Anguita, Ferdinando Fioretto

TL;DR

Stable Diffusion models are powerful but often fail to respect hard physical or design constraints. This paper introduces a training-free method that enforces these constraints during the latent diffusion sampling process. By backpropagating constraint violations from the decoded image space back to the latent space, the method achieves high-quality generation that adheres to complex physical properties or safety filters without requiring model retraining.

The Challenge of Hard Constraints in Latent Space

Diffusion models have transformed data synthesis, yet their application in scientific and engineering domains is limited by the need for rigorous compliance with specifications like physical laws or safety standards. Historically, enforcing "hard constraints" has been difficult because state-of-the-art models like Stable Diffusion operate in a compressed latent space, where physical properties (e.g., material porosity) are not easily defined. Previous approaches using text conditioning or soft penalties during training only offer statistical suggestions rather than strict guarantees. This research bridges that gap, enabling strict constraints to be applied directly to latent diffusion models at inference time.

Methodology: Proximal Langevin Dynamics

The core of the proposed approach is a sampling algorithm based on Proximal Langevin Dynamics. The process involves three key components:

  1. Latent Space Correction via the Decoder: At each denoising step, the model performs a standard update on the latent vector. To enforce constraints, the latent vector is passed through the model's frozen decoder to generate an image. The constraint violation is measured in this image space, and the gradient of the violation is backpropagated through the decoder to adjust the latent vector.
  2. Zero Retraining: The method utilizes the gradients of the existing frozen decoder and score network, requiring no fine-tuning of the base model.
  3. Handling Black-Box Simulators: For non-differentiable constraints, such as complex physics simulations, the authors employ a technique inspired by Differentiable Perturbed Optimizers (DPO). By injecting random perturbations into simulator inputs, they estimate gradients via finite differences, allowing industry-standard software to guide the generation.

Experimental Evaluation

The method was evaluated across three distinct domains: microstructure generation, metamaterial inverse design, and copyright-safe generation.

Microstructure Generation

Using a dataset of high-resolution material microstructures, the authors tested strict porosity constraints. The proposed method achieved a 0% error rate for generating materials with specific porosity levels while maintaining high image quality (FID of 13.5). In contrast, standard conditional Stable Diffusion failed to meet the porosity constraint nearly 70% of the time.

Microstructure generation results showing 0% porosity error and high visual quality compared to baselines.

Metamaterial Inverse Design

The framework was applied to periodic stochastic cellular structures subjected to large-strain compression. The goal was to generate materials matching specific stress-strain curves. The method provided a 4.6x improvement in Mean Squared Error (MSE) over previous state-of-the-art specialized models.

Iterative refinement of metamaterial structures to match target stress-strain curves, showing significant MSE reduction.

To test safety constraints, the model was tasked with generating a safe character ("Jerry") while avoiding a copyrighted one ("Mickey Mouse"). The model successfully avoided the copyrighted character 90% of the time, significantly outperforming the baseline (67%) without degrading image quality.

Key Insights

  • The Decoder as a Bridge: The frozen decoder acts as a differentiable bridge, allowing measurements in the image space to guide adjustments in the latent space.
  • Theoretical Guarantees: The authors mathematically prove that for convex constraint sets, the process converges to a feasible point while maintaining the original data distribution's quality.
  • Simulators in the Loop: The integration of black-box simulators (like Abaqus) directly into the generative loop allows for "testing" materials during synthesis.

Limitations and Future Outlook

While effective, evaluating constraints—especially via external simulators—can be computationally intensive. Future work aims to extend this training-free correction to video diffusion models for temporal constraints and to integrate even more complex, non-differentiable simulators.

Summary updated

BibTeX
@inproceedings{zampini2025training,
  author = {Stefano Zampini and Jacob K Christopher and Luca Oneto and Davide Anguita and Ferdinando Fioretto},
  title = {{Training-Free Constrained Generation With Stable Diffusion Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=TrNB08KuHK},
}
Figure