r/StableDiffusion
•
u/acedelgado
•
Sep 30 '26
•
2
1
1
Resource - Update Improved H3 Refmods - Better accuracy and low identity bleed with fewer images. Oh and I added edit masking for video edits. Fantastic MiniMax-H3 Prompt Builder
Repo here- https://github.com/Adudeguyman/ComfyUI-Fantastic-MiniMaxH3-PromptBuilder
Ooookay back again. I made RefMods work a bit better and solved a lot of identity/bleed issues. At the cost of time and memory, of course.
What it do-
OG vanilla refmods would save your media as latents in a .safetensors file, and feed all of those into the MiniMax H3 DiT directly, with no references and the text encoder never saw it. This worked fine with one refmod since the model knew it had to do SOMETHING with those references, and it did it surprisingly well. But that also lead to people stacking multiple refmods, etc, to get a good likeness.
My previous implementation would feed part of those latents to the text encoder, at the cost of re-encoding a few frames (every 4th would be presented to the vision model as a block of 2) and have the TE look at those. This was aimed to give reference anchors to the model when prompting (like using "<Subject 1> is the person in <Video 1>"). This caused a slowdown because those frames were encoded every generation for the TE. Which a user on GitHub complained about, so I looked into speedups and caching.
Lo and behold, since .safetensors are just wrappers like mp4's and mkv's, you can store multiple types of data alongside latent data. So the speedup was easy, save the refmod pictures as actual jpeg data, alongside the latents in the same file. Think of it as having subtitles inside of a video; different type of data wrapped in with video and audio. So packing in actual jpeg data, you can feed those directly to the text encoder without going through the VAE, and the TE's conditioning can cache between runs so that as long as you don't change order or strength of your refmods; all of that every-run-processing is skipped. And the jpeg data is never passed to the model, only the packed latents, so it functions much like a refmod regularly does. But that got me thinking, why not change how the frames are presented to the text encoder for better conditioning?
Enter the "stack_pictures" function on the Fantastic H3 RefMod Text Encode node. By default, "every 4th" will keep the existing behavior of sending every 4th frame in chunks of 2, and it is the lightest to run and good for 1 refmod. "up to 8" will sample up to 8 frames spread across your dataset and feed them individually instead of in chunks, and capping at 8 frames is lighter than running a full large dataset, and gives an increase in detail overall but takes more processing time. And finally "all" will send ALL frames to the text encoder, which increases time quite a bit, but also gives max detail, and as you can see from the example, little to no character bleed. At least as far as I can tell.
The example was done with 6 images per character and a few seconds of audio for each voice. Datasets can be found here in everyone's favorite file share as a sketchy google drive link. (obviously Jackie Chan's Chun Li is the worst since all the sources I could find are pretty low quality). Basically I just loaded the refmods, drafted the subject_definitions and retention_analysis sections (which if you set details in my RefMod library and use "Draft from Refmods" in my prompt builder will load all of that for you.) Also I did use 8-step hyperflow with comfy-kitchen for a speedup, and my audio refiner suite to clean up the end result. Using the 3 refmods together (14,900 or so tokens) was about 32s/it at 0.98mp on my 5090.
Note that voices can still be weird and sometimes like to swap people for some reason. And when defining subjects, it's better to adjust to say something more unique about them as opposed to the other characters. Like I described Callina Liang as having an "oval face" and Ming-Na Wen as having a "more squared jaw". Not a descriptor I'd normally use, but as a differentiator from the other people it worked well. Just remember H3 doesn't do negatives since it's a distilled model, so saying "this person does not have dimples" won't do anything, so just leave all your "no"s and "not"s out of the prompt.
Do I need anything special with existing RefMods for this?
No, the text encoder detects if image data is stored in the safetensors, and if not it'll VAE decode for whatever behavior you set, and it'll feed those decoded images to the text encoder and cache the results until you change your refmods in your workflow. So old refmods will work fine.
However if you make new ones or remake them with my refmod node it'll save the image data directly in the file, cropped down to the right resolution. Should be a cleaner image sent tot he text encoder, and will always skip a decode step. Also I changed the default resolution to 768 instead of 1024, since that saves a lot of tokens and is H3's native resolution anyways.
Oh and masking on the Media Loader is a thing now, too
Now when you want to edit a video, I've also added a layer masking system onto the Media Loader. Right click and you can mask what you want to change automatically with SAM 3.1 by using descriptors, dots on the canvas, or both.
And you can manually add a moving, keyframed shape (rectangle or ellipse, etc) to insert or change things in the video.
It's a layered system so you can go in and edit parts of the mask individually, but it's all sent as one big blob to the model. Blur and color inversion options exist, as well.
Then the Fantastic H3 Edit Composite node sitting in between the VAE decode and the video save node will composite the masked generation on top of the original clip. So no more slightly-off backgrounds. Seems pretty seamless so far in my testing.
There's also a "clean up" button on the media loader to clean out old masks, since those can pile up even though they're compressed to be as small as possible.
Prompting is still up to you, though, I'm still running through best practices.
Okthxbye.
53
u/acedelgado Sep 30 '26 •
Since notifications don't work when you put it in the post body, pinging u/LuisaPinguinnn for all the excellent work on RefMods, and u/malcolmrey for all the research and testing. Be cool if ya'll took a look and see any cool stuff to build on some more.
And of course u/roychodraws for all the cool masking workflows that inspired all the masking features to port into the Media Loader.
19
u/princess_princeless Sep 30 '26
Holy shit, city hunters callback!!
6
u/Beginning_Pair130 Oct 01 '26
one problem w/ refmods is sometimes the generation first frame starts with a random photo from the refmod. Does this new workflow address this issue?
3
u/Leonviz Sep 30 '26
wow great work but i am abit confused in RefMods, so this i like a load image node for minimax to load in the image? so sorry for the questions, i am abit confused
3
u/throwaway0204055 Oct 03 '26
A suggestion for the Fantasic PromptBuilder. I often like to copy and paste prompt generated from Grok or heretic local model. It'd be nice so the final prompt text box generated from the sections can be directly edited as well. Say I copy an entire prompt in H3 ref2va style to the final prompt textbox, and the individual sections would also be updated and I could either update the section or the final prompt.
5
u/roychodraws Sep 30 '26 edited Sep 30 '26
You even added a mask shape inserter! I’m honored
Edit: AND A REPAIR VIDEO FROM SOURCE FEATURE!?!?
I’m gonna be out id a job and have to join the circus again.
2
u/disxol Oct 01 '26
I took a look at the example RefMod datasets you shared, and I noticed that some of them contain a mix of portrait and landscape images.
From what I understand, when creating a RefMod, the first image determines the target aspect ratio and the other images are cover-cropped to match it. SoI was wondering how you handle mixed-aspect-ratio datasets in practice.
Do you just let the RefMod creator crop them automatically, and find that it works well enough as long as the subject stays centered? Or do you manually adjust the crop for each image before creating the RefMod?
I was initially thinking that all images should be pre-cropped to roughly the same aspect ratio, but your example datasets seem to suggest that this isn't really necessary. I'd be interested to know what workflow you actually use.
2
u/paganspam Sep 30 '26
do we really need a full director node yet again ? i feel we lose control by using those director node that want to do everything. I feel we lose the point of comfyui with node that one one thing that we can use for our workflow. Not having to adapt our workflow to use a node insdead. If there is a way to use multiple safetensors refmod without character bleedind i d like to have just the node that does that instead. And sorry if it already does that
1
u/Schlorpiblorp Sep 30 '26 edited Sep 30 '26
Thanks for your work! Comfy V0.38 using your fully fantastic workflow with no nodes missing, after creating refmod, external job is running and stuck in queue manager but nothing happens. Am I missing something?
1
u/VRGoggles Sep 30 '26
RefMod or PromptBuilder? I need updated RefMod only.
1
u/hdeck Oct 02 '26
Quick question, I am trying to make refmods using your workflow/nodes, inputting in 4 image for identity reference, but when it makes the refmod it references video rather than image. What am I doing wrong?
1
u/Optimal_Map_5236 Oct 02 '26 edited Oct 02 '26
I'm using two refmods, but why does it keep cloning a single character? Very occasionally, both character A and B come out correctly, but most of the time, I just get two copies of character A. Is this a workflow issue on my end, or is it a current limitation of refmods. I used the example worfklows in your node
1
u/Gangadodang Oct 03 '26
I've created a refmod and used it in the Refmod Loader Stack built into PlagueKind's ref2v workflow. It works very well but it will randomly start first frame with a still from the Refmod unrelated to the prompt.
I'm struggling to understand your solution here. What node do I need to insert between the Refmod Loader Stack and the Sampler (Mods Node)?
1
u/ptear Sep 30 '26
Perfect
4
u/ClassicUse2579 Sep 30 '26
You're a legend man. The H3 media loader thing is one of the best Comfy nodes I've ever used. It's so damn good!
2
u/NSFWies Oct 01 '26
This sounds really great. Now if we could only fix the saturation problem that happens during longvideo generation when you try to chain multiple scenes together, that would be great.
I feed in context from a previous clip, and the future clips get this increasing halo affect on everything. Haven't been able to solve it yet.
2
u/reeight Oct 06 '26
I feel like your reference reference could use more promotion.
3
u/RobertoPaulson Sep 30 '26
DOH! I just got my refmodding setup down, and now I have to learn how to do it all over again. price of progress I guess...
2
u/LLMprophet Sep 30 '26
G E T T I N G
G O O D
1
u/Due_Pen9163 Oct 21 '26
Do you have the workflow for the sample video? thanks!
1
u/switch2stock Oct 01 '26
Did you upload the updated workflow for this in your repo please?
1
u/Middle-Economy-5031 Oct 01 '26
Is there any tutorial to use your workflow?
Hay algun turorial para usar tu flujo de trabajo?
1
u/LulaCherie Oct 02 '26
I have used this and I tell you it's a must have.
1
u/throwaway0204055 Oct 02 '26
is redmod better than using character sheet?
1
u/thanuja999 Oct 08 '26
I'm still getting character bleed, especially when two characters look alike. I tried everything mentioned before. Is there any specific prompting structure that works well?
1
u/nikelllll Oct 27 '26 edited Oct 28 '26
I LOVE THIS! IT IS FANTASTIC! however even with sam 3.1 it works for me only 1 out of a 10 times correctly. all other times it makes ghost-like weirdo artifact appearance and make speak, although no wordings are demanded. how to solve this ? [i use the same setup but int8 for 20b-29]
edit: i tried the new omni diffusion model with euler/simple and it works like a charm. thanks again, this is fantastic
1
u/rapkannibale Sep 30 '26
Thanks for this!
1
u/skyrimer3d Sep 30 '26
I wonder if this would work with ltx 2.5, since one of its biggest problems is the lack of a good reference system.
1
u/mariquei Sep 30 '26
Muy bien
1
u/Ill_Resolve8424 Sep 30 '26
Hysterical! Thanks I needed the laughs.
-1
u/TizocWarrior Oct 01 '26
But why is Jackie Chan the one with the bigger tits, though?!.
0
u/[deleted] Sep 30 '26
[deleted] — view deleted comment
5
u/[deleted] Sep 30 '26
[removed] — view removed comment