2023-04-15 22:46:58 +00:00
|
|
|
from comfy import sd1_clip
|
2023-02-05 19:36:28 +00:00
|
|
|
import os
|
2023-01-03 06:53:32 +00:00
|
|
|
|
2023-10-27 19:54:04 +00:00
|
|
|
class SD2ClipHModel(sd1_clip.SDClipModel):
|
2024-08-17 14:15:13 +00:00
|
|
|
def __init__(self, arch="ViT-H-14", device="cpu", max_length=77, freeze=True, layer="penultimate", layer_idx=None, dtype=None, model_options={}):
|
2023-07-15 05:10:33 +00:00
|
|
|
if layer == "penultimate":
|
|
|
|
layer="hidden"
|
2023-12-06 20:55:09 +00:00
|
|
|
layer_idx=-2
|
2023-07-15 05:10:33 +00:00
|
|
|
|
2023-02-05 19:36:28 +00:00
|
|
|
textmodel_json_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), "sd2_clip_config.json")
|
2024-08-20 14:00:16 +00:00
|
|
|
super().__init__(device=device, freeze=freeze, layer=layer, layer_idx=layer_idx, textmodel_json_config=textmodel_json_config, dtype=dtype, special_tokens={"start": 49406, "end": 49407, "pad": 0}, return_projected_pooled=True, model_options=model_options)
|
2023-02-05 20:20:18 +00:00
|
|
|
|
2023-10-27 19:54:04 +00:00
|
|
|
class SD2ClipHTokenizer(sd1_clip.SDTokenizer):
|
2024-07-24 20:43:53 +00:00
|
|
|
def __init__(self, tokenizer_path=None, embedding_directory=None, tokenizer_data={}):
|
2023-06-22 17:03:50 +00:00
|
|
|
super().__init__(tokenizer_path, pad_with_end=False, embedding_directory=embedding_directory, embedding_size=1024)
|
2023-10-27 19:54:04 +00:00
|
|
|
|
|
|
|
class SD2Tokenizer(sd1_clip.SD1Tokenizer):
|
2024-07-24 20:43:53 +00:00
|
|
|
def __init__(self, embedding_directory=None, tokenizer_data={}):
|
|
|
|
super().__init__(embedding_directory=embedding_directory, tokenizer_data=tokenizer_data, clip_name="h", tokenizer=SD2ClipHTokenizer)
|
2023-10-27 19:54:04 +00:00
|
|
|
|
|
|
|
class SD2ClipModel(sd1_clip.SD1ClipModel):
|
2024-08-17 14:15:13 +00:00
|
|
|
def __init__(self, device="cpu", dtype=None, model_options={}, **kwargs):
|
|
|
|
super().__init__(device=device, dtype=dtype, model_options=model_options, clip_name="h", clip_model=SD2ClipHModel, **kwargs)
|