21 lines
689 B
Python
21 lines
689 B
Python
|
|
"""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):
|
||
|
|
from transformers import AutoTokenizer
|
||
|
|
|
||
|
|
self.tokenizer = AutoTokenizer.from_pretrained(str(tokenizer_dir), local_files_only=True)
|
||
|
|
|
||
|
|
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)
|