Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import json
|
|
@@ -9,7 +10,6 @@ HERE = os.path.dirname(os.path.abspath(__file__))
|
|
| 9 |
if HERE not in sys.path:
|
| 10 |
sys.path.insert(0, HERE)
|
| 11 |
|
| 12 |
-
# Make a Space-root comfy/ folder (if present) take precedence.
|
| 13 |
if os.path.isdir(os.path.join(HERE, "comfy")) and os.path.isfile(
|
| 14 |
os.path.join(HERE, "comfy", "quant_ops.py")
|
| 15 |
):
|
|
@@ -24,30 +24,38 @@ if "COMFY_ALLOW_VENDORED" not in os.environ:
|
|
| 24 |
os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "0")
|
| 25 |
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
try:
|
| 41 |
import comfy.quant_ops as _cq
|
| 42 |
sys.stderr.write(f"[main] comfy.quant_ops resolved to {getattr(_cq, '__file__', None)}\n")
|
| 43 |
_names = sorted(n for n in dir(_cq) if not n.startswith("_"))
|
| 44 |
-
sys.stderr.write(f"[main] comfy.quant_ops public: {_names[:40]}\n")
|
| 45 |
sys.stderr.write(f"[main] has AsymW4A8Int8Layout: {'AsymW4A8Int8Layout' in _names}\n")
|
| 46 |
sys.stderr.flush()
|
| 47 |
except Exception as _e:
|
| 48 |
sys.stderr.write(f"[main] comfy.quant_ops import FAILED: {type(_e).__name__}: {_e}\n")
|
| 49 |
sys.stderr.flush()
|
| 50 |
|
|
|
|
|
|
|
| 51 |
|
| 52 |
def _patch_gradio_client():
|
| 53 |
import gradio_client.utils as gu
|
|
@@ -177,6 +185,56 @@ def _try_register(name, module_path, func_name):
|
|
| 177 |
CONVERTERS[name] = (module_path, func_name, fn)
|
| 178 |
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
def _discover():
|
| 181 |
try:
|
| 182 |
from convert_to_quant.w4a8 import convert_to_w4a8, w4a8_available
|
|
@@ -188,24 +246,7 @@ def _discover():
|
|
| 188 |
except Exception as e:
|
| 189 |
WARNINGS.append(f"w4a8: import failed ({type(e).__name__}: {e})")
|
| 190 |
|
| 191 |
-
|
| 192 |
-
_try_register("int8", "convert_to_quant.convert_to_int8", "convert_to_int8")
|
| 193 |
-
_try_register("int8", "convert_to_quant.int8", "convert_to_int8")
|
| 194 |
-
|
| 195 |
-
for cand_mod in (
|
| 196 |
-
"convert_to_quant.convert_convrot_w4a4",
|
| 197 |
-
"convert_to_quant.convert_w4a4",
|
| 198 |
-
"convert_to_quant.convert_convrot",
|
| 199 |
-
"convert_to_quant.convrot_w4a4",
|
| 200 |
-
"convert_to_quant.w4a4",
|
| 201 |
-
):
|
| 202 |
-
_try_register("convrot_w4a4", cand_mod, "convert_to_w4a4")
|
| 203 |
-
if "convrot_w4a4" in CONVERTERS:
|
| 204 |
-
break
|
| 205 |
-
|
| 206 |
-
_try_register("fp8", "convert_to_quant.convert_fp8", "convert_to_fp8")
|
| 207 |
-
_try_register("fp8", "convert_to_quant.convert_to_fp8", "convert_to_fp8")
|
| 208 |
-
_try_register("fp8", "convert_to_quant.fp8", "convert_to_fp8")
|
| 209 |
|
| 210 |
|
| 211 |
_discover()
|
|
@@ -333,3 +374,4 @@ with gr.Blocks(title="Quant Converter") as demo:
|
|
| 333 |
|
| 334 |
if __name__ == "__main__":
|
| 335 |
demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
|
|
|
|
|
|
| 1 |
+
//main.py
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
import json
|
|
|
|
| 10 |
if HERE not in sys.path:
|
| 11 |
sys.path.insert(0, HERE)
|
| 12 |
|
|
|
|
| 13 |
if os.path.isdir(os.path.join(HERE, "comfy")) and os.path.isfile(
|
| 14 |
os.path.join(HERE, "comfy", "quant_ops.py")
|
| 15 |
):
|
|
|
|
| 24 |
os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "0")
|
| 25 |
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|
| 26 |
|
| 27 |
+
|
| 28 |
+
def _dump_convert_to_quant_layout():
|
| 29 |
+
try:
|
| 30 |
+
import convert_to_quant
|
| 31 |
+
import pkgutil as _pkgutil
|
| 32 |
+
import os as _os
|
| 33 |
+
_pkg_dir = _os.path.dirname(convert_to_quant.__file__)
|
| 34 |
+
_mods = sorted(m.name for m in _pkgutil.iter_modules([_pkg_dir]))
|
| 35 |
+
sys.stderr.write(f"[main] convert_to_quant at {_pkg_dir}\n")
|
| 36 |
+
sys.stderr.write(f"[main] submodules: {_mods}\n")
|
| 37 |
+
cv_dir = _os.path.join(_pkg_dir, "converters")
|
| 38 |
+
if _os.path.isdir(cv_dir):
|
| 39 |
+
_cv = sorted(m.name for m in _pkgutil.iter_modules([cv_dir]))
|
| 40 |
+
sys.stderr.write(f"[main] convert_to_quant.converters: {_cv}\n")
|
| 41 |
+
sys.stderr.flush()
|
| 42 |
+
except Exception as _e:
|
| 43 |
+
sys.stderr.write(f"[main] convert_to_quant listing failed: {type(_e).__name__}: {_e}\n")
|
| 44 |
+
sys.stderr.flush()
|
| 45 |
+
|
| 46 |
|
| 47 |
try:
|
| 48 |
import comfy.quant_ops as _cq
|
| 49 |
sys.stderr.write(f"[main] comfy.quant_ops resolved to {getattr(_cq, '__file__', None)}\n")
|
| 50 |
_names = sorted(n for n in dir(_cq) if not n.startswith("_"))
|
|
|
|
| 51 |
sys.stderr.write(f"[main] has AsymW4A8Int8Layout: {'AsymW4A8Int8Layout' in _names}\n")
|
| 52 |
sys.stderr.flush()
|
| 53 |
except Exception as _e:
|
| 54 |
sys.stderr.write(f"[main] comfy.quant_ops import FAILED: {type(_e).__name__}: {_e}\n")
|
| 55 |
sys.stderr.flush()
|
| 56 |
|
| 57 |
+
_dump_convert_to_quant_layout()
|
| 58 |
+
|
| 59 |
|
| 60 |
def _patch_gradio_client():
|
| 61 |
import gradio_client.utils as gu
|
|
|
|
| 185 |
CONVERTERS[name] = (module_path, func_name, fn)
|
| 186 |
|
| 187 |
|
| 188 |
+
def _scan_for_converters():
|
| 189 |
+
import importlib
|
| 190 |
+
import pkgutil
|
| 191 |
+
|
| 192 |
+
try:
|
| 193 |
+
import convert_to_quant
|
| 194 |
+
except Exception as e:
|
| 195 |
+
WARNINGS.append(f"convert_to_quant: import failed ({type(e).__name__}: {e})")
|
| 196 |
+
return
|
| 197 |
+
|
| 198 |
+
pkg_dir = os.path.dirname(os.path.abspath(convert_to_quant.__file__))
|
| 199 |
+
top_modules = [m.name for m in pkgutil.iter_modules([pkg_dir])]
|
| 200 |
+
|
| 201 |
+
candidate_paths = []
|
| 202 |
+
for name in top_modules:
|
| 203 |
+
candidate_paths.append(f"convert_to_quant.{name}")
|
| 204 |
+
|
| 205 |
+
cv_dir = os.path.join(pkg_dir, "converters")
|
| 206 |
+
if os.path.isdir(cv_dir):
|
| 207 |
+
for m in pkgutil.iter_modules([cv_dir]):
|
| 208 |
+
candidate_paths.append(f"convert_to_quant.converters.{m.name}")
|
| 209 |
+
|
| 210 |
+
candidate_paths.append("convert_to_quant.converters")
|
| 211 |
+
|
| 212 |
+
seen_canonical = set()
|
| 213 |
+
scan_log = []
|
| 214 |
+
|
| 215 |
+
for mod_path in candidate_paths:
|
| 216 |
+
try:
|
| 217 |
+
mod = importlib.import_module(mod_path)
|
| 218 |
+
except Exception:
|
| 219 |
+
continue
|
| 220 |
+
for attr_name in dir(mod):
|
| 221 |
+
if not attr_name.startswith("convert_to_"):
|
| 222 |
+
continue
|
| 223 |
+
attr = getattr(mod, attr_name, None)
|
| 224 |
+
if not callable(attr):
|
| 225 |
+
continue
|
| 226 |
+
canonical = attr_name[len("convert_to_"):]
|
| 227 |
+
if canonical in seen_canonical:
|
| 228 |
+
continue
|
| 229 |
+
seen_canonical.add(canonical)
|
| 230 |
+
CONVERTERS[canonical] = (mod_path, attr_name, attr)
|
| 231 |
+
scan_log.append(f"{canonical} <- {mod_path}.{attr_name}")
|
| 232 |
+
|
| 233 |
+
for line in scan_log:
|
| 234 |
+
sys.stderr.write(f"[main] registered converter {line}\n")
|
| 235 |
+
sys.stderr.flush()
|
| 236 |
+
|
| 237 |
+
|
| 238 |
def _discover():
|
| 239 |
try:
|
| 240 |
from convert_to_quant.w4a8 import convert_to_w4a8, w4a8_available
|
|
|
|
| 246 |
except Exception as e:
|
| 247 |
WARNINGS.append(f"w4a8: import failed ({type(e).__name__}: {e})")
|
| 248 |
|
| 249 |
+
_scan_for_converters()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
|
| 252 |
_discover()
|
|
|
|
| 374 |
|
| 375 |
if __name__ == "__main__":
|
| 376 |
demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
|
| 377 |
+
xzxz
|