MCPcopy Index your code
hub / github.com/kijai/ComfyUI-WanVideoWrapper / process

Method process

nodes.py:308–434  ·  view source on GitHub ↗
(self, positive_prompt, negative_prompt, t5=None, force_offload=True, model_to_offload=None, use_disk_cache=False, device="gpu")

Source from the content-addressed store, hash-verified

306
307
308 def process(self, positive_prompt, negative_prompt, t5=None, force_offload=True, model_to_offload=None, use_disk_cache=False, device="gpu"):
309 if t5 is None and not use_disk_cache:
310 raise ValueError("T5 encoder is required for text encoding. Please provide a valid T5 encoder or enable disk cache.")
311
312 echoshot = True if "[1]" in positive_prompt else False
313
314 if use_disk_cache:
315 context, context_null = get_cached_text_embeds(positive_prompt, negative_prompt)
316 if context is not None and context_null is not None:
317 return{
318 "prompt_embeds": context,
319 "negative_prompt_embeds": context_null,
320 "echoshot": echoshot,
321 },
322
323 if t5 is None:
324 raise ValueError("No cached text embeds found for prompts, please provide a T5 encoder.")
325
326 if model_to_offload is not None and device == "gpu":
327 try:
328 log.info(f"Moving video model to {offload_device}")
329 model_to_offload.model.to(offload_device)
330 except Exception:
331 pass
332
333 encoder = t5["model"]
334 dtype = t5["dtype"]
335
336 positive_prompts = []
337 all_weights = []
338
339 # Split positive prompts and process each with weights
340 if "|" in positive_prompt:
341 log.info("Multiple positive prompts detected, splitting by '|'")
342 positive_prompts_raw = [p.strip() for p in positive_prompt.split('|')]
343 elif "[1]" in positive_prompt:
344 log.info("Multiple positive prompts detected, splitting by [#] and enabling EchoShot")
345 import re
346 segments = re.split(r'\[\d+\]', positive_prompt)
347 positive_prompts_raw = [segment.strip() for segment in segments if segment.strip()]
348 assert len(positive_prompts_raw) > 1 and len(positive_prompts_raw) < 7, 'Input shot num must between 2~6 !'
349 else:
350 positive_prompts_raw = [positive_prompt.strip()]
351
352 for p in positive_prompts_raw:
353 cleaned_prompt, weights = self.parse_prompt_weights(p)
354 positive_prompts.append(cleaned_prompt)
355 all_weights.append(weights)
356
357 mm.soft_empty_cache()
358
359 if device == "gpu":
360 device_to = mm.get_torch_device()
361 else:
362 device_to = torch.device("cpu")
363
364 if encoder.quantization == "fp8_e4m3fn":
365 cast_dtype = torch.float8_e4m3fn

Callers

nothing calls this directly

Calls 6

parse_prompt_weightsMethod · 0.95
get_cached_text_embedsFunction · 0.85
get_cache_pathFunction · 0.85
toMethod · 0.80
deviceMethod · 0.45

Tested by

no test coverage detected