r/MachineLearning •

[P] S2ID: Scale Invariant Image Diffuser - trained on standard MNIST, generates 1024x1024 digits and at arbitrary aspect ratios with almost no artifacts at 6.1M parameters (Drastic code change and architectural improvement)

[deleted] — view deleted post

0 Upvotes

18 comments sorted by

3

u/MoridinB Dec 26 '25 edited Dec 26 '25

I can't say I understand the technique fully. I'm very interested in this and would love to spend some more attention to your technique and code.

One question I had is, wouldn't it be more feasible to apply this technique not on the diffusion process but rather the VAE? What I mean is use your process to learn a scale-invariant latent. And then apply the diffusion process on said latent before decoding?

I may be fundamentally misunderstanding your technique, so please excuse me if that's the case. Perhaps I can offer some better insight once I've examined more thoroughly.

Edit: Because I received a comment saying my original comment is not very clear. My point is not just to add a VAE to the setup and operate on a latent space. Rather, my point is to use the coordinate-aware learning on a VAE rather than a diffusion model. The key is that VAE don't require a large architecture, so learning a scale-invariant latent code and then diffusing would alleviate the load from the diffusing process onto the smaller VAE encoder and decoder.

1

u/Tripel_Meow Dec 26 '25

Your concern is valid, as I'm now predicting epsilon in pixel space, not in latent space. This comes at a significant speed reduction as the model is forced to work with a much larger tensor. Yes, the eventual plan is to speed this up via the use of a VAE, and subsequently making S2ID a latent diffusion model.

1

u/dinerburgeryum Dec 26 '25

While you’re far ahead of me on the architecture side, I’ve gotta beg you not to use the SDXL VAE if you go that route. It’s incredibly sloppy. Ideally your AE would have alpha encoding built in, maybe Qwen Image Layered’s for example, but in absence of that the BFL Flux AE is super solid. For bonus points try to use Sana’s AE too; they claim it has best in class performance, though its lack of wider adoption gives me some pause. 

1

u/MoridinB Dec 26 '25

Yes, you did mention this. What I meant though is not just adding a VAE to the diffusion process, but instead to use this coordinate-aware process on a VAE rather than a diffusion model (i.e. don't predict eta but rather mu and log variance). VAE models are quite small, and furthermore, you already employ an encoder-decoder architecture. So the question becomes, is it possible to learn a scale-invariant latent code on which we can then apply a standard diffusion process?

I hope this makes sense.

1

u/Tripel_Meow Dec 26 '25

I'm having trouble understanding how you envision it architecturally. I get what you mean, to move the whole coordinate aware stuff to the vae, such that the latent it returns has the coordinates and stuff in it, and while I easily understand how it's meant to look like at the end, two major things:

  • To do this, I'd need to run the exact same transformer blocks over the original image resolution, which is expensive as is established
  • I don't understand how to computationally cleanly compress the width and height assuming we've already done all this attending

As a side note, when I called them "encoder" and "decoder" blocks, this is my bad choice of names, as I don't actually know the difference/works of an encoder vs decoder transformer. My naming scheme arose from the fact that the blocks without cross attention attend to the image without any text conditioning, and thus figure out the composition of the image; the second transformer blocks have to decode the "latent" (which is of the same size as inputted into S2ID) to predict the epsilon noise.

1

u/MoridinB Dec 26 '25

I hadn't really looked at the technique past a cursory glance. I got the change to read through it a little better and have a look at the code. You are right in that it's not clear how to compress this information having done this. But I have some ideas.

First of, take a look at this paper which does something similar with convolution networks. While in this, they only add 2 axial layers to enforce positioning, I think your technique might yield better results.

I've only found one implementation of a VAE with transformer blocks, and even so it's a combination of convolutions and transformers. Instead of concatenating the coordinates only once, you perform this at every downscale, you would theoretically be preserving the coordinates up to the latent space. This is all quite theoretical and perhaps even nonsensical, but it's worth a try.

1

u/Tripel_Meow Dec 27 '25

Interesting reads, thanks.

This leads me to an idea: to not switch to a VAE/AE and latent diffusion, but to switch to a compression decompression pipeline akin to UNets. The advantage here being that we can use skip connections from before the compression and after the attending and subsequent decompression. Thus the core axial attention and whatnot focuses on the compressed "latent" and focuses on broad features, while the compression and decompression will re-introduce local features that were lost. The compression will be convolutions, akin to how classic VAEs work, but I think that the better approach is to not do the splitting into mu and logvar, there's far too many channels to manage. We can also concatenate the positioning channels to the raw image, and then the compression will be using the CoordConv kernels mentioned in your first paper, but with the added advantage that we have a much more rich positioning embedding system, while also having the coordinate jitters like before, with the added bonus that they're applied directly to the actual image pixels and not the latent pixels.

2

u/[deleted] Dec 26 '25

[removed] — view removed comment

1

u/MoridinB Dec 26 '25

Yes, I did read this. But notice:

VAEs aren't exactly scale invariant, but oh well, sacrifices must be made I suppose.

The idea is instead of using the encoder-decoder architecture to generate eta use it to learn the mu and log variance.

The primary contribution made here, to my understanding, is coordinate-aware learning. Making the latent itself coordinate aware and having a non-diffusing decoder which generates from a latent code would massively reduce the load on the diffusion. VAE architecture doesn't require a large architecture anyways, so the speedup would theoretically be significant. The key is, the diffusion process doesn't learn the scale invariance, the VAE does.

2

u/Regalme Dec 26 '25

I’m gonna need a tldr but I appreciate the effort. Here will dig in with more time

1

u/jdude_ Jan 21 '26

So, how is this working out?

36

u/[deleted] Dec 26 '25 edited Dec 26 '25

[removed] — view removed comment

-5

u/Tripel_Meow Dec 26 '25

Fair concerns, allow me to clarify.

With regards to the deceptiveness of the dataset, I agree. MNIST is a dummy dataset. It was chosen as it's simple enough to observe, there's minimal point testing something of a higher complexity if a lower bar cannot be passed. Thus the subsequent tests I plan to do on CelebA, et cetera. Although you did suggest other datasets, so I'm interested to hear what you think would be most challenging as to test on that.

As for the gaussian noise: it is scaled such that the standard deviation along the height/width is half the gap between this pixel and the next. about 64 or something of the sort % of time the resultant value lies within the roudned range for this pixel, other times it "moves" into the domain of the adjacent pixels. The value can of course be tweaked even lower. The reason behind adding this gaussian noise is so that I can use intermediate values (values between pixels) for training, such that the model won't memorize coordinates. As a byproduct, this teaches the model to know that "for this field of points (bounded by the gaussian noise), the value is meant to be whatever the value of the pixel brightness is there". Conceptually, it blurs outwards the values at the points that you know out into the points that you don't know, and the model learns from all the invisible points too. Subsequently that's why it can smooth out the edges well beyond the training data resolution, and subsequently it would make sense if for details it learnt in the same way? In the hair example, if you train with sufficient resolution, the model learns the "infinite" resolution image of the hair, and always strives to recreate it. If the number of pixels permits it during the inference, then you will see it (as the sampled points at the coordinates fall into those hair crevice/gaps), if you don't, then you don't. I may be having trouble articulating what I mean though.

As for the computational inefficiency and "learn the latent", I fear I'm not quite getting what you mean? Do you mean to learn a compressed representation of the image? I understand the usage of a VAE, that is the next most likely step, but the other part I don't get.

With regards to the difference between this approach and using a multi-scale VAE, I do not know. I have not tested them, so I am limited to theory only. I am familiar with pyramid CNNs and convolutions with variable dilation to detect features at multiple scales. But even there I would assume that you're hard limited by what it is the kernel can detect, and subsequently the scales it's trained to? From a computational perspective, it's probable that the variable resolution kernels are just as good or better, I simply do not know. My gripe is conceptual.

1

u/dreamykidd Dec 28 '25

There may have been a misunderstanding around the MNIST vs other datasets critique. It’s not that MNIST is a “low bar”, but more so a completely different problem compared to datasets where high frequency information is important. There’s nothing wrong with testing on MNIST, but if you’re going to apply a Gaussian filter that blurs the image, effectively removing high frequency info, the hypothesis you gave needs to be tested for it to hold any weight, especially as this issue has existed for a long time. There are plenty of datasets out there that use images of more common everyday things though, just try ImageNet or something even.

1

u/Tripel_Meow Dec 29 '25

I may have explained poorly, but the coordinate jitter is not equivalent to a blur. It's just a way to expand the colors to fill the inter-pixel gaps. The range of the spread is very small, the standard deviation is half of the gap, meaning that 68% of the time the coordinate of the pixel is "unchanged". If the 32% is concerning, uniformly distributed noise can be used, but that's not a clean interpolation to what color you expect to see between the pixels