Can you make your GGUF node compatible with torch.compile?
Hi,
For hunyuan, using torch.compile is important because it provides a huge speed boost, I know someone made an issue on your github 2 months ago, but I think it's the moment to really focus on making that work, making a slow model faster is always a good achievement.
https://github.com/city96/ComfyUI-GGUF/issues/118
I'm trying lol. The main problem is that even if I resolve the issue where it exceeds the trace depth, torch.compile
still fails to trace the custom tensor class we use - which basically means it'd require a full rewrite of the entire weight handling & dequantization logic to use nn.Parameter
instead (which is what the first test implementation had, and it was super fragile when loading/unloading models).
Maybe a more simple solution would be to transform your .gguf into a gguf.safetensors format, that's what kijai did on mochi and we were able to use torch.compile with it
https://huggingface.co/Kijai/Mochi_preview_comfy/tree/main
That's just the storage format, it has nothing to do with whether you can use torch compile or not. Once it's loaded it doesn't matter whether the data was stored in a safetensors or a gguf file.
I see, maybe you should look at kijai's mochi code to see how he managed to make his gguf work with torch compile then.
Just update ComfyUI, I've been using .gguf with torch.compile and sage attention for a day now
@tav2tav
How? I got this error when trying a GGUF model with torch.compile on Hunyuan.
Maybe it's the sampler that's not working with it. Ignore the prompt:
{"last_node_id":100,"last_link_id":273,"nodes":[{"id":99,"type":"ModelCompile+","pos":[458.2304992675781,-467.5818176269531],"size":[315,106],"flags":{},"order":9,"mode":0,"inputs":[{"name":"model","type":"MODEL","link":273}],"outputs":[{"name":"MODEL","type":"MODEL","links":[271],"slot_index":0}],"properties":{"Node name for S&R":"ModelCompile+"},"widgets_values":[false,false,"default"]},{"id":78,"type":"UnetLoaderGGUF","pos":[106.78589630126953,-338.59088134765625],"size":[315,58],"flags":{},"order":0,"mode":0,"inputs":[],"outputs":[{"name":"MODEL","type":"MODEL","links":[217,272],"slot_index":0}],"properties":{"Node name for S&R":"UnetLoaderGGUF"},"widgets_values":["hunyuan-video-t2v-720p-Q5_K_M.gguf"]},{"id":79,"type":"VHS_VideoCombine","pos":[1499.2349853515625,-273.07159423828125],"size":[289.7805480957031,310],"flags":{},"order":13,"mode":0,"inputs":[{"name":"images","type":"IMAGE","link":237},{"name":"audio","type":"AUDIO","link":null,"shape":7},{"name":"meta_batch","type":"VHS_BatchManager","link":null,"shape":7},{"name":"vae","type":"VAE","link":null,"shape":7}],"outputs":[{"name":"Filenames","type":"VHS_FILENAMES","links":null}],"properties":{"Node name for S&R":"VHS_VideoCombine"},"widgets_values":{"frame_rate":24,"loop_count":0,"filename_prefix":"AnimateDiff","format":"video/h265-mp4","pix_fmt":"yuv420p","crf":19,"save_metadata":true,"pingpong":false,"save_output":true,"videopreview":{"hidden":false,"paused":false,"params":{"filename":"AnimateDiff_00094.mp4","subfolder":"","type":"output","format":"video/h265-mp4","frame_rate":24,"workflow":"AnimateDiff_00094.png","fullpath":"/home/tav/Desktop/ComfyUI/output/AnimateDiff_00094.mp4"},"muted":false}}},{"id":73,"type":"VAEDecodeTiled","pos":[1140.0003662109375,-454.5455322265625],"size":[210,102],"flags":{},"order":11,"mode":0,"inputs":[{"name":"samples","type":"LATENT","link":262},{"name":"vae","type":"VAE","link":211}],"outputs":[{"name":"IMAGE","type":"IMAGE","links":[235,237],"slot_index":0}],"properties":{"Node name for S&R":"VAEDecodeTiled"},"widgets_values":[256,96]},{"id":16,"type":"KSamplerSelect","pos":[457.3968200683594,-309.37164306640625],"size":[315,58],"flags":{},"order":1,"mode":0,"inputs":[],"outputs":[{"name":"SAMPLER","type":"SAMPLER","links":[259],"shape":3}],"properties":{"Node name for S&R":"KSamplerSelect"},"widgets_values":["dpmpp_2m"]},{"id":100,"type":"ModelSamplingSD3","pos":[107.23002624511719,-459.1136779785156],"size":[315,58],"flags":{},"order":6,"mode":0,"inputs":[{"name":"model","type":"MODEL","link":272}],"outputs":[{"name":"MODEL","type":"MODEL","links":[273],"slot_index":0}],"properties":{"Node name for S&R":"ModelSamplingSD3"},"widgets_values":[7]},{"id":11,"type":"DualCLIPLoader","pos":[110.86199951171875,-217.58624267578125],"size":[310.1802978515625,106],"flags":{},"order":2,"mode":0,"inputs":[],"outputs":[{"name":"CLIP","type":"CLIP","links":[267,268],"slot_index":0,"shape":3}],"properties":{"Node name for S&R":"DualCLIPLoader"},"widgets_values":["clip_l.safetensors","llava_llama3_fp8_scaled.safetensors","hunyuan_video"]},{"id":17,"type":"BasicScheduler","pos":[461.0906982421875,-201.8182373046875],"size":[315,106],"flags":{},"order":5,"mode":0,"inputs":[{"name":"model","type":"MODEL","link":217,"slot_index":0}],"outputs":[{"name":"SIGMAS","type":"SIGMAS","links":[258],"shape":3}],"properties":{"Node name for S&R":"BasicScheduler"},"widgets_values":["normal",20,1]},{"id":10,"type":"VAELoader","pos":[800.2166748046875,194.67315673828125],"size":[350,60],"flags":{},"order":3,"mode":0,"inputs":[],"outputs":[{"name":"VAE","type":"VAE","links":[211],"slot_index":0,"shape":3}],"properties":{"Node name for S&R":"VAELoader"},"widgets_values":["hunyuan_video_vae_fp32.safetensors"]},{"id":44,"type":"CLIPTextEncode","pos":[368.12396240234375,-40.165283203125],"size":[422.84503173828125,164.31304931640625],"flags":{},"order":8,"mode":0,"inputs":[{"name":"clip","type":"CLIP","link":268}],"outputs":[{"name":"CONDITIONING","type":"CONDITIONING","links":[254],"slot_index":0}],"title":"CLIP Text Encode (Positive Prompt)","properties":{"Node name for S&R":"CLIPTextEncode"},"widgets_values":["Anime style Fennec girl, a yellow pegasus with pink mane, walks through Times Square New York. She looks a bit nervous as the crowd of anime people cheer her on."],"color":"#232","bgcolor":"#353"},{"id":45,"type":"EmptyHunyuanLatentVideo","pos":[794.6473999023438,-469.5484313964844],"size":[315,130],"flags":{},"order":4,"mode":0,"inputs":[],"outputs":[{"name":"LATENT","type":"LATENT","links":[256],"slot_index":0}],"properties":{"Node name for S&R":"EmptyHunyuanLatentVideo"},"widgets_values":[1280,720,117,1]},{"id":75,"type":"SaveAnimatedWEBP","pos":[1177.2725830078125,-282.72723388671875],"size":[298.4847106933594,368.5954284667969],"flags":{},"order":12,"mode":0,"inputs":[{"name":"images","type":"IMAGE","link":235}],"outputs":[],"properties":{},"widgets_values":["ComfyUI",24,false,90,"default",null]},{"id":92,"type":"CLIPTextEncode","pos":[370.49957275390625,174.330078125],"size":[416.6979064941406,164.31304931640625],"flags":{},"order":7,"mode":0,"inputs":[{"name":"clip","type":"CLIP","link":267}],"outputs":[{"name":"CONDITIONING","type":"CONDITIONING","links":[253],"slot_index":0}],"title":"CLIP Text Encode (Positive Prompt)","properties":{"Node name for S&R":"CLIPTextEncode"},"widgets_values":[""],"color":"#232","bgcolor":"#353"},{"id":95,"type":"SamplerCustom","pos":[797.9667358398438,-291.42828369140625],"size":[355.20001220703125,442],"flags":{},"order":10,"mode":0,"inputs":[{"name":"model","type":"MODEL","link":271},{"name":"positive","type":"CONDITIONING","link":254},{"name":"negative","type":"CONDITIONING","link":253},{"name":"sampler","type":"SAMPLER","link":259},{"name":"sigmas","type":"SIGMAS","link":258},{"name":"latent_image","type":"LATENT","link":256}],"outputs":[{"name":"output","type":"LATENT","links":[],"slot_index":0},{"name":"denoised_output","type":"LATENT","links":[262],"slot_index":1}],"properties":{"Node name for S&R":"SamplerCustom"},"widgets_values":[true,500,"fixed",1]}],"links":[[211,10,0,73,1,"VAE"],[217,78,0,17,0,"MODEL"],[235,73,0,75,0,"IMAGE"],[237,73,0,79,0,"IMAGE"],[253,92,0,95,2,"CONDITIONING"],[254,44,0,95,1,"CONDITIONING"],[256,45,0,95,5,"LATENT"],[258,17,0,95,4,"SIGMAS"],[259,16,0,95,3,"SAMPLER"],[262,95,1,73,0,"LATENT"],[267,11,0,92,0,"CLIP"],[268,11,0,44,0,"CLIP"],[271,99,0,95,0,"MODEL"],[272,78,0,100,0,"MODEL"],[273,100,0,99,0,"MODEL"]],"groups":[],"config":{},"extra":{"ds":{"scale":1.331000000000003,"offset":[17.027251613355176,561.3414301288841]},"groupNodes":{}},"version":0.4}
@tav2tav
Impressive, I got it working aswell, you need this node from "essentials" instead of comfy core but it's indeed working!
https://github.com/cubiq/ComfyUI_essentials
There's an issue though, it's not working with loras.