Skip to content

Commit 65042f7

Browse files
Make it easier to set a custom template for hunyuan video.
1 parent 7c7c70c commit 65042f7

File tree

7 files changed

+13
-10
lines changed

7 files changed

+13
-10
lines changed

comfy/sd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def add_patches(self, patches, strength_patch=1.0, strength_model=1.0):
134134
def clip_layer(self, layer_idx):
135135
self.layer_idx = layer_idx
136136

137-
def tokenize(self, text, return_word_ids=False):
138-
return self.tokenizer.tokenize_with_weights(text, return_word_ids)
137+
def tokenize(self, text, return_word_ids=False, **kwargs):
138+
return self.tokenizer.tokenize_with_weights(text, return_word_ids, **kwargs)
139139

140140
def add_hooks_to_dict(self, pooled_dict: dict[str]):
141141
if self.apply_hooks_to_conds:

comfy/sd1_clip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def _try_get_embedding(self, embedding_name:str):
482482
return (embed, leftover)
483483

484484

485-
def tokenize_with_weights(self, text:str, return_word_ids=False):
485+
def tokenize_with_weights(self, text:str, return_word_ids=False, **kwargs):
486486
'''
487487
Takes a prompt and converts it to a list of (token, weight, word id) elements.
488488
Tokens can both be integer tokens and pre computed CLIP tensors.
@@ -596,7 +596,7 @@ def __init__(self, embedding_directory=None, tokenizer_data={}, clip_name="l", t
596596
tokenizer = tokenizer_data.get("{}_tokenizer_class".format(self.clip), tokenizer)
597597
setattr(self, self.clip, tokenizer(embedding_directory=embedding_directory, tokenizer_data=tokenizer_data))
598598

599-
def tokenize_with_weights(self, text:str, return_word_ids=False):
599+
def tokenize_with_weights(self, text:str, return_word_ids=False, **kwargs):
600600
out = {}
601601
out[self.clip_name] = getattr(self, self.clip).tokenize_with_weights(text, return_word_ids)
602602
return out

comfy/sdxl_clip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, embedding_directory=None, tokenizer_data={}):
2626
self.clip_l = clip_l_tokenizer_class(embedding_directory=embedding_directory)
2727
self.clip_g = SDXLClipGTokenizer(embedding_directory=embedding_directory)
2828

29-
def tokenize_with_weights(self, text:str, return_word_ids=False):
29+
def tokenize_with_weights(self, text:str, return_word_ids=False, **kwargs):
3030
out = {}
3131
out["g"] = self.clip_g.tokenize_with_weights(text, return_word_ids)
3232
out["l"] = self.clip_l.tokenize_with_weights(text, return_word_ids)

comfy/text_encoders/flux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, embedding_directory=None, tokenizer_data={}):
1818
self.clip_l = clip_l_tokenizer_class(embedding_directory=embedding_directory)
1919
self.t5xxl = T5XXLTokenizer(embedding_directory=embedding_directory)
2020

21-
def tokenize_with_weights(self, text:str, return_word_ids=False):
21+
def tokenize_with_weights(self, text:str, return_word_ids=False, **kwargs):
2222
out = {}
2323
out["l"] = self.clip_l.tokenize_with_weights(text, return_word_ids)
2424
out["t5xxl"] = self.t5xxl.tokenize_with_weights(text, return_word_ids)

comfy/text_encoders/hunyuan_video.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ def __init__(self, embedding_directory=None, tokenizer_data={}):
4141
self.llama_template = """<|start_header_id|>system<|end_header_id|>\n\nDescribe the video by detailing the following aspects: 1. The main content and theme of the video.2. The color, shape, size, texture, quantity, text, and spatial relationships of the objects.3. Actions, events, behaviors temporal relationships, physical movement changes of the objects.4. background environment, light, style and atmosphere.5. camera angles, movements, and transitions used in the video:<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n""" # 95 tokens
4242
self.llama = LLAMA3Tokenizer(embedding_directory=embedding_directory, min_length=1)
4343

44-
def tokenize_with_weights(self, text:str, return_word_ids=False):
44+
def tokenize_with_weights(self, text:str, return_word_ids=False, llama_template=None, **kwargs):
4545
out = {}
4646
out["l"] = self.clip_l.tokenize_with_weights(text, return_word_ids)
4747

48-
llama_text = "{}{}".format(self.llama_template, text)
48+
if llama_template is None:
49+
llama_text = "{}{}".format(self.llama_template, text)
50+
else:
51+
llama_text = "{}{}".format(llama_template, text)
4952
out["llama"] = self.llama.tokenize_with_weights(llama_text, return_word_ids)
5053
return out
5154

comfy/text_encoders/hydit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, embedding_directory=None, tokenizer_data={}):
3737
self.hydit_clip = HyditBertTokenizer(embedding_directory=embedding_directory)
3838
self.mt5xl = MT5XLTokenizer(tokenizer_data={"spiece_model": mt5_tokenizer_data}, embedding_directory=embedding_directory)
3939

40-
def tokenize_with_weights(self, text:str, return_word_ids=False):
40+
def tokenize_with_weights(self, text:str, return_word_ids=False, **kwargs):
4141
out = {}
4242
out["hydit_clip"] = self.hydit_clip.tokenize_with_weights(text, return_word_ids)
4343
out["mt5xl"] = self.mt5xl.tokenize_with_weights(text, return_word_ids)

comfy/text_encoders/sd3_clip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, embedding_directory=None, tokenizer_data={}):
4343
self.clip_g = sdxl_clip.SDXLClipGTokenizer(embedding_directory=embedding_directory)
4444
self.t5xxl = T5XXLTokenizer(embedding_directory=embedding_directory)
4545

46-
def tokenize_with_weights(self, text:str, return_word_ids=False):
46+
def tokenize_with_weights(self, text:str, return_word_ids=False, **kwargs):
4747
out = {}
4848
out["g"] = self.clip_g.tokenize_with_weights(text, return_word_ids)
4949
out["l"] = self.clip_l.tokenize_with_weights(text, return_word_ids)

0 commit comments

Comments
 (0)