# solving mazes with diffusion models

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsolving-mazes-with-diffusion-models%2F161301%3E%5C
**Category:** 🧨 Diffusers\
**Created:** [July 1, 2025, 10:34am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsolving-mazes-with-diffusion-models%2F161301 "2025-07-01T10:34:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![omarlahia](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/omarlahia/32/39399_2.png) [@omarlahia](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fomarlahia)%5C
**Post date:** [July 1, 2025, 10:34am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsolving-mazes-with-diffusion-models%2F161301%2F1 "2025-07-01T10:34:58Z")

</div>

Hi everyone!! 👋

I recently started an experimental project to explore whether **diffusion models** can learn to solve **mazes** , and if these models are capable of learning structured patterns like paths from start to end, without using classic algorithms like A\* or Dijkstra.

* * *

### My Approach:

I trained a **U-Net model conditioned** on:

- The **maze structure**
- A **start/end matrix**

#### Data Representation (3-channel input):

- **Maze matrix** :
  - `1` → valid path
  - `0` → wall

- **Start/End matrix** :
  - `1` → start or end point
  - `0` → elsewhere

- **Solution path matrix** (target to denoise):
  - `1` → part of the solution path
  - `0` → all other cells

During training, I apply a **DDPM-style noise schedule** to the solution path matrix and train the model to predict the added noise , conditioned on the maze and start/end inputs.

During inference, the model starts from random noise and generates the solution path step-by-step through denoising.

👉 **Try it live** :  
🔗 [https://maze-diffusion.netlify.app/](https://maze-diffusion.netlify.app/)

🕰 **Note** : The server takes ~1.5 minutes to respond…  
It’s running on a humble **1 CPU, no GPU** , (be patient — it’s thinking hard 😅)
