From 62a7707a8ee958095c8a469db3471cd6ae1344b2 Mon Sep 17 00:00:00 2001 From: wailovet Date: Wed, 24 Apr 2024 02:39:14 +0800 Subject: [PATCH] 'update' --- __init__.py | 2 +- mz_llama3.py | 14 +++++++------- mz_llama_cpp.py | 18 +++++++++--------- mz_llava.py | 16 ++++++++-------- mz_utils.py => mz_prompt_utils.py | 0 mz_qwen.py | 2 +- 6 files changed, 26 insertions(+), 26 deletions(-) rename mz_utils.py => mz_prompt_utils.py (100%) diff --git a/__init__.py b/__init__.py index 6b67af8..aaa25ba 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ import os import sys -from .mz_utils import Utils +from .mz_prompt_utils import Utils from nodes import MAX_RESOLUTION import comfy.utils import shutil diff --git a/mz_llama3.py b/mz_llama3.py index f2a61d6..252e0ad 100644 --- a/mz_llama3.py +++ b/mz_llama3.py @@ -1,5 +1,5 @@ import json -import mz_utils +import mz_prompt_utils import mz_llama_cpp import importlib @@ -7,7 +7,7 @@ import importlib def get_exist_model(model_name): - modelscope_model_path = mz_utils.Utils.modelscope_download_model( + modelscope_model_path = mz_prompt_utils.Utils.modelscope_download_model( model_type="llama3", model_name=model_name, only_get_path=True, @@ -17,7 +17,7 @@ def get_exist_model(model_name): return modelscope_model_path model_url = f"https://huggingface.co/QuantFactory/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/{model_name}" - hf_model_path = mz_utils.Utils.hf_download_model(model_url, only_get_path=True) + hf_model_path = mz_prompt_utils.Utils.hf_download_model(model_url, only_get_path=True) if hf_model_path is not None: return hf_model_path @@ -50,7 +50,7 @@ def query_beautify_prompt_text(model_name, n_gpu_layers, text, style_presets, do if model_file is None: if download_source == "modelscope": - model_file = mz_utils.Utils.modelscope_download_model( + model_file = mz_prompt_utils.Utils.modelscope_download_model( model_type="llama3", model_name=model_name, ) @@ -58,7 +58,7 @@ def query_beautify_prompt_text(model_name, n_gpu_layers, text, style_presets, do model_url = f"https://huggingface.co/QuantFactory/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/{model_name}" if download_source == "hf-mirror.com": model_url = f"https://hf-mirror.com/QuantFactory/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/{model_name}" - model_file = mz_utils.Utils.hf_download_model(model_url) + model_file = mz_prompt_utils.Utils.hf_download_model(model_url) schema = mz_llama_cpp.get_schema_obj( keys_type={ @@ -95,7 +95,7 @@ def query_beautify_prompt_text(model_name, n_gpu_layers, text, style_presets, do schema=schema, options=options, ) - mz_utils.Utils.print_log(f"response_json: {response_json}") + mz_prompt_utils.Utils.print_log(f"response_json: {response_json}") response = json.loads(response_json) mz_llama_cpp.freed_gpu_memory(model_file=model_file) @@ -148,7 +148,7 @@ def query_beautify_prompt_text(model_name, n_gpu_layers, text, style_presets, do while full_response.find(", ,") != -1: full_response = full_response.replace(", ,", ",") - full_response = mz_utils.Utils.prompt_zh_to_en(full_response) + full_response = mz_prompt_utils.Utils.prompt_zh_to_en(full_response) style_presets_prompt_text = style_presets_prompt.get(style_presets, "") diff --git a/mz_llama_cpp.py b/mz_llama_cpp.py index 776f3ad..4525ea4 100644 --- a/mz_llama_cpp.py +++ b/mz_llama_cpp.py @@ -4,7 +4,7 @@ import subprocess import sys import torch try: - import mz_utils + import mz_prompt_utils except ImportError: pass @@ -79,7 +79,7 @@ def check_llama_cpp_requirements(): def freed_gpu_memory(model_file): check_llama_cpp_requirements() - model_and_opt = mz_utils.Utils.cache_get(f"llama_cpp_model_and_opt_{model_file}") + model_and_opt = mz_prompt_utils.Utils.cache_get(f"llama_cpp_model_and_opt_{model_file}") if model_and_opt is None: return 0 @@ -89,7 +89,7 @@ def freed_gpu_memory(model_file): del model torch.cuda.empty_cache() - mz_utils.Utils.cache_set(f"llama_cpp_model_and_opt_{model_file}", None) + mz_prompt_utils.Utils.cache_set(f"llama_cpp_model_and_opt_{model_file}", None) def llama_cpp_messages(model_file, n_gpu_layers, chat_handler=None, messages=[], options={}): if options is None: @@ -101,7 +101,7 @@ def llama_cpp_messages(model_file, n_gpu_layers, chat_handler=None, messages=[], from llama_cpp import Llama - model_and_opt = mz_utils.Utils.cache_get(f"llama_cpp_model_and_opt_{model_file}") + model_and_opt = mz_prompt_utils.Utils.cache_get(f"llama_cpp_model_and_opt_{model_file}") # compared is_opts_changed = False @@ -135,23 +135,23 @@ def llama_cpp_messages(model_file, n_gpu_layers, chat_handler=None, messages=[], "options": options, "n_gpu_layers": n_gpu_layers, } - mz_utils.Utils.cache_set(f"llama_cpp_model_and_opt_{model_file}", model_and_opt) + mz_prompt_utils.Utils.cache_set(f"llama_cpp_model_and_opt_{model_file}", model_and_opt) model = model_and_opt.get("model") response_format = options.get("response_format", None) - mz_utils.Utils.print_log(f"======================================================LLAMA_CPP======================================================") + mz_prompt_utils.Utils.print_log(f"======================================================LLAMA_CPP======================================================") # mz_utils.Utils.print_log("llama_cpp messages:", messages) - mz_utils.Utils.print_log("llama_cpp response_format:", response_format) + mz_prompt_utils.Utils.print_log("llama_cpp response_format:", response_format) output = model.create_chat_completion( messages=messages, max_tokens=options.get("max_tokens", None), response_format=response_format, temperature=options.get("temperature", 0.8), ) - mz_utils.Utils.print_log(f"LLAMA_CPP: \n{output}") + mz_prompt_utils.Utils.print_log(f"LLAMA_CPP: \n{output}") choices = output.get("choices", []) # mz_utils.Utils.print_log(f"LLAMA_CPP choices: \n{choices}") if len(choices) == 0: @@ -298,7 +298,7 @@ def llava_cpp_simple_interrogator( content = [] if image is not None: - data_uri = mz_utils.Utils.pil_image_to_base64(image) + data_uri = mz_prompt_utils.Utils.pil_image_to_base64(image) content.append({"type": "image_url", "image_url": {"url": data_uri}}) content.append({"type" : "text", "text": question}) diff --git a/mz_llava.py b/mz_llava.py index 8487728..f29216b 100644 --- a/mz_llava.py +++ b/mz_llava.py @@ -1,6 +1,6 @@ import json import os -import mz_utils +import mz_prompt_utils import mz_llama_cpp import importlib @@ -16,7 +16,7 @@ huggingface_models_map = { def get_exist_model(model_name): - modelscope_model_path = mz_utils.Utils.modelscope_download_model( + modelscope_model_path = mz_prompt_utils.Utils.modelscope_download_model( model_type="llava", model_name=model_name, only_get_path=True, @@ -36,7 +36,7 @@ def get_exist_model(model_name): model_url = f"https://hf-mirror.com/{author}/{model_names[0]}/resolve/main/{model_names[1]}" - hf_model_path = mz_utils.Utils.hf_download_model(model_url, only_get_path=True) + hf_model_path = mz_prompt_utils.Utils.hf_download_model(model_url, only_get_path=True) if hf_model_path is not None: return hf_model_path @@ -48,19 +48,19 @@ def get_exist_model(model_name): def image_interrogator(model_name, mmproj_name, n_gpu_layers, image, resolution, download_source=None, options={}): if options is None: options = {} - image = mz_utils.Utils.resize_max(image, resolution, resolution) + image = mz_prompt_utils.Utils.resize_max(image, resolution, resolution) model_file = get_exist_model(model_name) mmproj_file = get_exist_model(mmproj_name) if model_file is None or mmproj_file is None: if download_source == "modelscope": if model_file is None: - model_file = mz_utils.Utils.modelscope_download_model( + model_file = mz_prompt_utils.Utils.modelscope_download_model( model_type="llava", model_name=model_name, ) if mmproj_file is None: - mmproj_file = mz_utils.Utils.modelscope_download_model( + mmproj_file = mz_prompt_utils.Utils.modelscope_download_model( model_type="llava", model_name=mmproj_name, ) @@ -79,7 +79,7 @@ def image_interrogator(model_name, mmproj_name, n_gpu_layers, image, resolution, if model_file is None: - model_file = mz_utils.Utils.hf_download_model(model_url) + model_file = mz_prompt_utils.Utils.hf_download_model(model_url) mmproj_name = mmproj_name.split("?")[0] mmproj_names = mmproj_name.split("/") @@ -89,7 +89,7 @@ def image_interrogator(model_name, mmproj_name, n_gpu_layers, image, resolution, mmproj_url = f"https://huggingface.co/{author}/{mmproj_names[0]}/resolve/main/{mmproj_names[1]}" if mmproj_file is None: - mmproj_file = mz_utils.Utils.hf_download_model(mmproj_url) + mmproj_file = mz_prompt_utils.Utils.hf_download_model(mmproj_url) response = mz_llama_cpp.llava_cpp_simple_interrogator( diff --git a/mz_utils.py b/mz_prompt_utils.py similarity index 100% rename from mz_utils.py rename to mz_prompt_utils.py diff --git a/mz_qwen.py b/mz_qwen.py index 51d1ff5..3db9c39 100644 --- a/mz_qwen.py +++ b/mz_qwen.py @@ -3,7 +3,7 @@ import re import shutil import subprocess import sys -import mz_utils +import mz_prompt_utils import tempfile