Add a separate preview node to prevent generator from running twice, unique_id is buggy

This commit is contained in:
Zuellni
2023-09-16 22:30:29 +02:00
parent 57bfd8cb13
commit 0ec46fb285
4 changed files with 29 additions and 11 deletions
+7 -4
View File
@@ -19,18 +19,21 @@ pip install https://github.com/jllllll/exllama/releases/download/0.0.17/exllama-
## Nodes ## Nodes
Comes with the following nodes: Comes with the following nodes:
### ExLlama Loader ### Loader
Used to load 4-bit GPTQ Llama/2 models. You can find a lot of them over at [Hugging Face](https://huggingface.co/TheBloke). Used to load 4-bit GPTQ Llama/2 models. You can find a lot of them over at [Hugging Face](https://huggingface.co/TheBloke).
ExLlama allocates [memory](https://github.com/turboderp/exllama/issues/259) according to `max_seq_len`. Lowering it is a good way to save on GPU RAM. ExLlama allocates [memory](https://github.com/turboderp/exllama/issues/259) according to `max_seq_len`. Lowering it is a good way to save on GPU RAM.
It's currently not possible to [offload](https://github.com/turboderp/exllama/issues/177) the model to CPU RAM. It's currently not possible to [offload](https://github.com/turboderp/exllama/issues/177) the model to CPU RAM.
### ExLlama Generator ### Generator
Generates a `string` based on the given `prompt` for use with other nodes. Generates a `string` based on the given `prompt` for use with other nodes.
Default values correspond to the `simple-1` preset from [text-generation-webui](https://github.com/oobabooga/text-generation-webui). Default values correspond to the `simple-1` preset from [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
ExLlama isn't [deterministic](https://github.com/turboderp/exllama/issues/201), so the outputs may differ even with the same seed. ExLlama isn't [deterministic](https://github.com/turboderp/exllama/issues/201), so the outputs may differ even with the same seed.
## Example ### Previewer
The workflow can be opened directly in ComfyUI. Displays generated prompts in the UI.
## Workflow
Can be opened directly in ComfyUI.
Model used: [MythoLogic-Mini-7B](https://huggingface.co/TheBloke/MythoLogic-Mini-7B-GPTQ). Model used: [MythoLogic-Mini-7B](https://huggingface.co/TheBloke/MythoLogic-Mini-7B-GPTQ).
![workflow](https://github.com/Zuellni/ComfyUI-ExLlama-Nodes/assets/123005779/2a8c71b2-3014-49b8-9252-29a30eba01c9) ![workflow](https://github.com/Zuellni/ComfyUI-ExLlama-Nodes/assets/123005779/2a8c71b2-3014-49b8-9252-29a30eba01c9)
+5 -3
View File
@@ -1,13 +1,15 @@
from .nodes import Generator, Loader from .nodes import Generator, Loader, Previewer
NODE_CLASS_MAPPINGS = { NODE_CLASS_MAPPINGS = {
"ZuellniExLlamaGenerator": Generator,
"ZuellniExLlamaLoader": Loader, "ZuellniExLlamaLoader": Loader,
"ZuellniExLlamaGenerator": Generator,
"ZuellniExLlamaPreviewer": Previewer,
} }
NODE_DISPLAY_NAME_MAPPINGS = { NODE_DISPLAY_NAME_MAPPINGS = {
"ZuellniExLlamaGenerator": "ExLlama Generator",
"ZuellniExLlamaLoader": "ExLlama Loader", "ZuellniExLlamaLoader": "ExLlama Loader",
"ZuellniExLlamaGenerator": "ExLlama Generator",
"ZuellniExLlamaPreviewer": "ExLlama Previewer",
} }
WEB_DIRECTORY = "." WEB_DIRECTORY = "."
+15 -2
View File
@@ -27,7 +27,6 @@ class Generator:
CATEGORY = "Zuellni/ExLlama" CATEGORY = "Zuellni/ExLlama"
FUNCTION = "generate" FUNCTION = "generate"
OUTPUT_NODE = True
RETURN_NAMES = ("TEXT",) RETURN_NAMES = ("TEXT",)
RETURN_TYPES = ("STRING",) RETURN_TYPES = ("STRING",)
@@ -58,7 +57,7 @@ class Generator:
text += chunk text += chunk
text = text.strip() text = text.strip()
return {"ui": {"text": [text]}, "result": (text,)} return (text,)
class Loader: class Loader:
@@ -91,3 +90,17 @@ class Loader:
tokenizer = ExLlamaTokenizer(str(model_dir / "tokenizer.model")) tokenizer = ExLlamaTokenizer(str(model_dir / "tokenizer.model"))
generator = ExLlamaAltGenerator(model, tokenizer, cache) generator = ExLlamaAltGenerator(model, tokenizer, cache)
return (generator,) return (generator,)
class Previewer:
@classmethod
def INPUT_TYPES(cls):
return {"required": {"text": ("STRING", {"forceInput": True})}}
CATEGORY = "Zuellni/ExLlama"
FUNCTION = "preview"
OUTPUT_NODE = True
RETURN_TYPES = ()
def preview(self, text):
return {"ui": {"text": [text]}}
+2 -2
View File
@@ -4,9 +4,9 @@ import { app } from "../../../scripts/app.js";
import { ComfyWidgets } from "../../../scripts/widgets.js"; import { ComfyWidgets } from "../../../scripts/widgets.js";
app.registerExtension({ app.registerExtension({
name: "Zuellni.ExLlama.Generator", name: "ZuellniExLlamaPreviewer",
async beforeRegisterNodeDef(nodeType, nodeData, app) { async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === "ZuellniExLlamaGenerator") { if (nodeData.name === "ZuellniExLlamaPreviewer") {
const onExecuted = nodeType.prototype.onExecuted; const onExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function (message) { nodeType.prototype.onExecuted = function (message) {