'update'
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
+7
-7
@@ -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, "")
|
||||
|
||||
+9
-9
@@ -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})
|
||||
|
||||
+8
-8
@@ -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(
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import mz_utils
|
||||
import mz_prompt_utils
|
||||
import tempfile
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user