2026-08-12 14:12:42 +07:00
|
|
|
"""Prompt-only conditioning primitives independent of ComfyUI's node API."""
|
|
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class H3PromptTokenizer:
|
|
|
|
|
"""Tokenize raw H3 prompt text without Qwen chat-template tokens."""
|
|
|
|
|
|
|
|
|
|
def __init__(self, tokenizer_dir: str | Path):
|
2026-08-12 14:35:04 +07:00
|
|
|
from transformers import AutoTokenizer
|
2026-08-12 14:12:42 +07:00
|
|
|
|
2026-08-12 15:21:03 +07:00
|
|
|
self.tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
|
str(Path(tokenizer_dir)),
|
|
|
|
|
local_files_only=True,
|
|
|
|
|
fix_mistral_regex=True,
|
|
|
|
|
)
|
2026-08-12 14:12:42 +07:00
|
|
|
|
|
|
|
|
def __call__(self, prompt: str, *, device: torch.device | str = "cuda") -> torch.Tensor:
|
|
|
|
|
if not prompt:
|
|
|
|
|
prompt = " "
|
|
|
|
|
encoded = self.tokenizer(prompt, add_special_tokens=False, return_tensors="pt")
|
|
|
|
|
return encoded.input_ids.to(device)
|