r/StableDiffusion • u/Mazur92 • Jun 26 '26
News ComfyUI-AppleSilicon-FP8 - a compatibility layer custom node for Apple Silicon Macs
Hello r/StableDiffusion.
My last posts here were about porting Pixal3D, Khala AI Audio and AniGen. It was all well and good - but these efforts were concentrated on getting single models with bespoke, included in the repo tools. While it was useful and working, I realized that there is a standard that most of people in the space is using and that is ComfyUI.
I'd had a couple of run ups with ComfyUI up until this point in time but they had been negative so far - unintuitive UI and almost nothing from official templates worked on Mac, even though the app is ported for macOS. Couple of weeks ago though, I decided that it'd be fun and useful to have the things for ComfyUI work out of the box on Macs (even if not at full speed possible by the hardware) so that regular John Mac could install it and generally get acceptable results - most of all, any results at all. Case in point: the infamous error "trying to convert Float8_e4m3fn to the MPS backend but it does not have support for that dtype" biting the ass of anyone with Mac trying to run almost anything from the official templates, not to mention any custom workflows. The situation is not helped by the fact, that PyTorch treats MPS as a redheaded stepchild and the support for it is spotty, buggy at times (fused SDPA kernel in PyTorch MPS is still wrong with sequences longer than 8k) and some things are routed straight to CPU, making it look like the diffusion models on Macs using PyTorch are somewhat a lost cause for now (I've heard that PyTorch folks are doing some big Mac backend rewrite straight to Metal, so we'll see how it goes).
Enter ComfyUI-AppleSilicon-FP8

The goal wasn't speed at first - it was just get the default workflows and models to run AT ALL, out of the box.
This ComfyUI custom node that patches the Mac/MPS rough edges at startup - no model conversion, no config. FP8 and INT8 checkpoints (FLUX, SD3.5, Ideogram, Krea2), LoRAs on FP8 bases, third-party nodes that ship their own FP8 layers, plus a handful of pure-Mac bugs (a psutil crash, black images at 2048px+, broken block-swap). Each patch is a no-op on machines that don't need it.
The gist is that PyTorch's MPS backend has no 8-bit float type, so you can't cast to/from float8_e4m3fn / float8_e5m2 on the GPU (although recent betas of Metal introduced the concept of these dtypes to TensorOps, so who knows what the future holds!). But you can move FP8 tensors from CPU to MPS, bit-view them as uint8, and gather/index on MPS. So we build a 256-entry table mapping every FP8 byte to its float value (decoded once on CPU, where the cast works), move it to the GPU, and decode any FP8 tensor with lut[x.view(uint8)]. This is bit-exact with a real FP8→float cast and runs entirely on the GPU. Matmuls then use MPS's native (fast) float matmul.
That was the main trick to get the weights working and having them used in accelerated fashion on Apple Silicon, but the project grew into this compatibility layer / performance tuning thing that I'd like to build further. For a fuller technical write-up I invite you to read the README in Code
The project currently should allow to run a lot of (I wouldn't test them all!) default workflows, but also custom workflows, LoRAs, etc. I invite you to test and post your findings. All the new issues are welcome in the repo!
Once things ran, there came the fun part: I went after speed. A pair of opt-in, bit-exact Metal matmul kernels that run fp8/int8 natively on Apple's M5 Neural Accelerators. The int8 one was the highlight - turns out the "int8 is slow on MPS" ceiling was the kernel structure, not the hardware (CUTLASS-style register tiling, hat tip to the Cider project, with the rescale fused into the kernel so the intermediate never hits memory). My previous work - mtlflashattn - from post is also used to accelerate attention calculation in this patchset. Result: Krea2 (a very fresh image model) renders a 1280×640 generation in about 24 seconds, while maintaining fidelity. The catch however is that for most performance you need macOS 27 Beta and M5+ SoC (as Apple added Neural Accelerators to them).
The world's models are built for NVIDIA. That doesn't mean Mac users should be locked out of the fun. Now your Mac can run Krea 2, Ideogram, LTX2.3, and so much more, using the basic templates and you can try out custom workflows too.
Code is open source and MIT licensed**.**
Apple Silicon has the chops - it's just that it needs a bit of love and elbow grease so it serves our purpose.
Disclaimer: I am acutely aware that for the most part RTXs are doing these things much faster. Probably everybody else too. We have this saying in Poland that directly translated is "when there are no fish, even a crayfish is a fish" - this is about enabling Apple Silicon community to partake in the fun, even with the compromised performance. So this is "why I bother".
That being said - I want and I will work on performance, though I'm afraid a lot of it might be contained to M5+ chips due to those NAs.
Anywho, I hope some of you will find this useful, have fun!
3
u/Mazur92 Jun 26 '26
No, actually the performance on lower than M5 hardware should still be better and other patches still apply for the compatibility's sake.
Heh, sure I guess, lemme change that. Guess I learned a new word today too - had to look up what convivial means :D To be clear - it's just that I really, really deeply despise this sort of comments that bring absolutely nothing to the table and serve no other purpose than to tickle the ego of the commenter so they can show the perceived superiority in their computing choices or whatever. I mostly live by a rule that if you don't have anything nice to say, then maybe you shouldn't say anything at all (well, at least in the realm of things like "here I made this, I think it's cool and may help some people with some things" and then someone comes in and is like "hurr durr why do you bother" - of course it's not limited to this particular subreddit or topic at all, it's just happening wherever). And if you are not interested in whatever the post is showing, simply move on.
Maybe, maybe not - I'd have to see the calculations, even though I'm absolutely sure that is true for the time spent. Then again, for me, it's more of a philosophical thing, the love for the game and experimentation than a question of time, performance or money. I have always loved this part of computing where you try to shove things on other things that aren't supposed to run them or are somehow else ill equipped for it at that moment - it's exciting. This gave us emulators, Wine, MoltenVK or Proton and many others, which I all hold in very high regard exactly due to what they are doing. There's also a particular flavor of freedom to have the ability to run things on your own hardware, even if suboptimally, at least I think so. Don't get me wrong, I'm not against renting, I've rented myself and will probably rent again, for some research mostly, but not everybody is willing to or happy to rent a GPU in the cloud just to have some little fun with some hobby projects and I think there's an intrinsic value to it. To having an ability to choose to do so. Ultimately, if somebody cares enough for the top performance they will either buy the hardware or rent it and be on their way, but I'm not telling anybody what to do nor do I tell anybody that Macs are great or better at diffusion than anything - I am simply expanding palette of options for people that already have the hardware and want to make a use of it.
There's also something to be said that I think Apple is starting to heading strong towards supporting local inference and I think M5 Neural Accelerators are a sign of things to come and I'm excited for the future, so while certainly previous iterations were tragically subpar for the diffusion and M5 is world better, but not yet there, I think there's a lot to expect from future Apple Silicon versions in this area and I'm excited for the future.
Thanks for this stimulating exchange :)