---
title: 'Flexi-UNet: Scale-Adaptive Diffusion'
url: https://www.emergentmind.com/topics/flexi-unet
type: topic
---

# Flexi-UNet: Scale-Adaptive Diffusion

Flexi-UNet is a UNet variant introduced to efficiently support the Scale Space Diffusion (SSD) framework, enabling dynamic routing and computation at variable resolutions throughout the generative diffusion process. It modifies the canonical denoising diffusion probabilistic model (DDPM) pipelines by integrating scale-space theory, which offers explicit control over resolution schedules and network path traversal, thereby optimizing computational resources during both training and inference without substantial degradation in generation quality [2603.08709].

## 1. Mathematical Foundations in Scale Space Diffusion

Flexi-UNet is implemented in the context of the SSD framework, a generalization of DDPM achieved by replacing the traditional scalar noise schedule’s multiplier with a family of linear operators \(M_t\). This allows incorporation of degradations such as downsampling or blurring; specifically, 
\[
M_t = \frac{a_t}{a_{t-1}}\;\mathrm{Downsample}_{r(t)/r(t-1)}
\]
where \(r(t)\) is a monotonically decreasing resolution schedule, and \(x_0\) is sampled from the data distribution at full resolution. The noising process for each timestep is governed by:
\[
q(x_t \mid x_{t-1}) = \mathcal{N}(x_t \,;\, M_t\,x_{t-1},\,\Sigma_{t\mid t-1})
\]
with covariance
\[
\Sigma_{t\mid t-1} = \sigma_t^2I - \sigma_{t-1}^2\,M_t\,M_t^\top
\]
and the closed-form marginal:
\[
x_t = M_{1:t}\,x_0 + \sigma_t\,\epsilon, \quad \epsilon \sim \mathcal{N}(0, I)
\]
The reverse (denoising) step leverages the tractable Gaussian posterior
\[
q(x_{t-1} \mid x_t, x_0) = \mathcal{N}(\mu_{t\to t-1}, \Sigma_{t\to t-1})
\]
where
\[
\Sigma_{t\to t-1} = \sigma_{t-1}^2I - \frac{\sigma_{t-1}^4}{\sigma_t^2}M_t^\top M_t
\]
\[
\mu_{t\to t-1} = M_{1:t-1}\,x_0 + \frac{\sigma_{t-1}^2}{\sigma_t^2}M_t^\top(x_t - M_t\,M_{1:t-1}\,x_0)
\]
In practice, \(x_0\) is replaced by the Flexi-UNet model’s prediction at the appropriate lower resolution. Training proceeds with a Min-SNR-\(\gamma\) weighted loss:
\[
\mathcal{L} = \mathbb{E}_{x_0,\,t,\,\epsilon} \left[\min(s^2(t),\gamma)\,\|x_{0,\theta}^{\,r(t-1)}(x_t,t) - \tfrac{1}{a_{t-1}}M_{1:t-1}x_0\|_2^2\right]
\]
where \(s^2(t)=\bar\alpha_t/(1-\bar\alpha_t)\) is the standard SNR.

## 2. Flexi-UNet Topology and Dynamic Routing

Flexi-UNet modifies the standard ADM UNet to efficiently process variable input resolutions by dynamically activating only the relevant subset of encoder and decoder blocks. The maximum network depth is \(L\); resolutions are indexed from coarsest (\(\ell=0\)) to finest (\(\ell=L\)), each corresponding to input resolution \(r_\ell\). The dynamic routing is as follows:

- For input at \(r_\ell\), the image is fed to encoder blocks \(\ell+1, \ldots, L\).
- After the bottleneck, decoder blocks \(L, L-1, \ldots, \ell+1\) are used.
- For a resolution-preserving step (\(r(t)=r(t-1)\)), the network stops at decoder level \(\ell+1\) and outputs at resolution \(r_\ell\).
- For a resolution-increasing step (\(r(t-1) > r(t)\)), an extra decoder is applied to reach \(r_{\ell+1}\).

To address channel width mismatches, Flexi-UNet inserts 1×1 convolutions at every entry and exit point—these project the raw input into the feature dimensions expected by the encoder, and similarly, project features back to RGB at output. When a decoder block expects a skip connection from a bypassed encoder layer, a zero-tensor of the correct shape is used in place. Residual and attention weights, as well as time-embeddings, are shared identically with the baseline UNet.

Parameter scaling is efficient: Flexi-UNet adds only \(O(L)\) small 1×1 convolution layers, negligible relative to the main architecture. At maximum (full resolution), the network matches baseline UNet in FLOPs and parameters; at coarsest resolutions, it restricts computation to the innermost blocks, reducing both FLOPs and peak memory by roughly a factor of \(\ell/L\).

## 3. Pseudocode for Forward and Reverse Processes

### Forward (Noising) Pass

For \(t=1\) to \(T\):

1. Given input \(x_{t-1}\) at resolution \(r(t-1)\), compute:
   \[
   x_t \leftarrow M_t\,x_{t-1} + \sqrt{\Sigma_{t|t-1}}\,\epsilon
   \]

### Conditional Reverse (Denoising) Pass

1. Initialize \(x_T \sim \mathcal{N}(0, I)\) at coarsest resolution \(r(T)\).
2. For \(t = T\) down to 1:
    - Use FlexiUNet\((x_t, t, r(t), r(t-1))\) to predict \(\hat{x}_0\) at \(r(t-1)\).
    - Form posterior mean:
      \[
      \mu_{t\rightarrow t-1} = a_{t-1}\,\hat x_0 + \frac{\sigma_{t-1}^2}{\sigma_t^2} M_t^\top \left(x_t - M_t\,a_{t-1}\,\hat x_0\right)
      \]
    - Sample posterior noise: use Lanczos decomposition for non-isotropic \(\Sigma_{t\to t-1}\) or standard Gaussian otherwise.
    - Set \(x_{t-1} = \mu_{t\to t-1} +\) posterior noise.

## 4. Empirical Evaluation

### CelebA and ImageNet Results

Flexi-UNet was evaluated on CelebA at resolutions \(64\times64\), \(128\times128\), and \(256\times256\), and on ImageNet at \(64\times64\). Key metrics include FID, wall-clock training time, and per-iteration GFLOPs. Comparative results between DDPM-ε and Flexi-UNet at select resolution schedules are as follows:

| Dataset@Resolution       | Method                   | FID     | Time (h) | GFLOPs/iter |
|-------------------------|--------------------------|---------|----------|-------------|
| CelebA@64×64 (2 levels) | Flexi-UNet (2 levels)    | 2.14    | 62.6     | 50.6        |
| CelebA@64×64            | DDPM-ε                   | 2.22    | 70       | 60.05       |
| CelebA@128×128 (3 lvls) | Flexi-UNet (3 levels)    | 6.53    | 31.7     | 87.4        |
| CelebA@128×128          | DDPM-ε                   | 4.16    | 50.5     | 132.3       |
| CelebA@256×256 (3 lvls) | Flexi-UNet (3 levels)    | 7.79    | 59.0     | 317.4       |
| CelebA@256×256          | DDPM-ε                   | 5.52    | 87.3     | 497.0       |
| ImageNet@64×64 (2 lvls) | Flexi-UNet (2 levels)    | 13.08   | —        | —           |
| ImageNet@64×64          | DDPM-ε                   | 12.82   | —        | —           |

- At 2-level configurations, Flexi-UNet slightly improves FID, while reducing training time by approximately 10–20% and computational cost (GFLOPs) by 15–40%, depending on the number of levels.
- Increasing the number of levels reduces GFLOPs and time but increases the FID.
- Ablations show similar or improved inference time, especially with increased level granularity.

Schedules that dwell on higher resolutions yield improved FID but correspondingly increase training time—a tradeoff controlled by the resolution schedule (e.g., ConvexDecay\_0.5 vs. Equal).

## 5. Architecture Ablations and Resolution Schedule Impact

Ablation studies compare the Flexi-UNet against the full UNet and under different architectural parametrizations:

| Configuration           | FID  | Inference Time (s/image) |
|-------------------------|------|--------------------------|
| Full UNet, 2 levels     | 2.33 | 16.19                    |
| Flexi-UNet, 2 levels    | 2.26 | 15.38                    |
| Flexi-UNet, 4 levels    | 4.87 | 13.43                    |

These results indicate that Flexi-UNet can match or slightly improve perceptual metrics while benefiting from reduced computational demand at low-to-intermediate levels.

Schedules that allocate more steps to higher resolutions achieve better FID but slow down training. Thus, Flexi-UNet exposes explicit control over fidelity-computation tradeoffs via the choice of resolution schedule.

## 6. Limitations and Prospective Extensions

Flexi-UNet as evaluated utilizes DDPM-style sampling and a standard ADM UNet backbone. Potential improvements include integration with more advanced samplers (e.g., DDIM, DPM-solvers), resolution curriculum strategies, and per-level tuning of hyperparameters (SNR schedules, time embeddings). Flexi-UNet’s design is compatible with alternative architectures such as Vision-Transformer-based backbones (DiT, U-ViT) for SSD in latent-space domains.

The reported framework explores only 2× downsampling, but the generalized SSD formulation allows straightforward replacement of the linear degradation with Gaussian blurs, anisotropic filters, or other operators. A natural direction is to exploit this flexibility for further FLOP/memory reduction or perceptual quality improvements.

A plausible implication is that Flexi-UNet's coarse-to-fine computation policy may inform future generative model design, particularly in domains where hierarchical information flow and efficient computation at multiple scales are crucial [2603.08709].

## 7. Context and Significance

Flexi-UNet provides a minimal yet effective modification to canonical diffusion model architectures, targeting the computational inefficiency in conventional approaches when processing highly degraded (noisy or low-resolution) states. By adapting computation to the meaningful spatial content at each timestep, it realizes substantial savings in compute and memory while preserving the capacity to yield high-fidelity samples. This framework demonstrates that generative processes need not uniformly allocate resources to all timesteps, especially when coarser representations suffice. The alignment of Flexi-UNet and Scale Space Diffusion stands as a principled instance of scale-adaptive generative modeling, with broad implications for scalable diffusion-based architectures [2603.08709].

Source: https://www.emergentmind.com/topics/flexi-unet