33import logging
44import torch
55import gguf
6+ import re
67import os
78
89from .ops import GGMLTensor
@@ -202,18 +203,21 @@ def llama_permute(raw_sd, n_head, n_head_kv):
202203 sd [k ] = v
203204 return sd
204205
206+ def strip_quant_suffix (name ):
207+ pattern = r"[-_]?(?:ud-)?i?q[0-9]_[a-z0-9_\-]{1,8}$"
208+ match = re .search (pattern , name , re .IGNORECASE )
209+ if match :
210+ name = name [:match .start ()]
211+ return name
212+
205213def gguf_mmproj_loader (path ):
206214 # Reverse version of Qwen2VLVisionModel.modify_tensors
207215 logging .info ("Attenpting to find mmproj file for text encoder..." )
208216
209217 # get name to match w/o quant suffix
210218 tenc_fname = os .path .basename (path )
211219 tenc = os .path .splitext (tenc_fname )[0 ].lower ()
212- for q in [x .name for x in gguf .GGMLQuantizationType ]:
213- if q .lower () in tenc :
214- tenc = tenc .rsplit (q .lower (), 1 )[0 ]
215- break
216- tenc = tenc [:- 1 ] # dash/underscore/etc
220+ tenc = strip_quant_suffix (tenc )
217221
218222 # try and find matching mmproj
219223 target = []
@@ -228,7 +232,7 @@ def gguf_mmproj_loader(path):
228232 target .append (fname )
229233
230234 if len (target ) == 0 :
231- logging .error (f"Error: Can't find mmproj file for '{ tenc_fname } '! Qwen-Image-Edit will be broken!" )
235+ logging .error (f"Error: Can't find mmproj file for '{ tenc_fname } ' (matching:' { tenc } ') ! Qwen-Image-Edit will be broken!" )
232236 return {}
233237 if len (target ) > 1 :
234238 logging .error (f"Ambiguous mmproj for text encoder '{ tenc_fname } ', will use first match." )
0 commit comments