MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / process

Method process

lightx2v/disagg/services/encoder.py:516–692  ·  view source on GitHub ↗

Generates encoder outputs from prompt and image input.

(self, config)

Source from the content-addressed store, hash-verified

514 """
515 Generates encoder outputs from prompt and image input.
516 """
517 seed_all(get_input_value(config, "seed"))
518 self.logger.info("Starting processing in EncoderService...")
519 room = int(config.get("data_bootstrap_room", 0))
520 encoder_metrics = config.setdefault("request_metrics", {}).setdefault("stages", {}).setdefault("encoder", {})
521 encoder_metrics["compute_start_ts"] = time.time()
522
523 room_buffers = self._rdma_buffers.get(room)
524 sender = self.data_sender.get(room)
525
526 prompt = get_input_value(config, "prompt", None)
527 if prompt is None:
528 raise ValueError("prompt is required in config.")
529
530 # 1. Text Encoding
531 text_len = config["text_len"]
532
533 context = self.text_encoder.infer([prompt])
534 context = torch.stack([torch.cat([u, u.new_zeros(text_len - u.size(0), u.size(1))]) for u in context])
535
536 if config.get("enable_cfg", False):
537 context_null = self.text_encoder.infer([get_input_value(config, "negative_prompt", None) or ""])
538 context_null = torch.stack([torch.cat([u, u.new_zeros(text_len - u.size(0), u.size(1))]) for u in context_null])
539 else:
540 context_null = None
541
542 text_encoder_output = {
543 "context": context,
544 "context_null": context_null,
545 }
546
547 task = config.get("task")
548 clip_encoder_out = None
549
550 if task == "t2v":
551 latent_h = get_input_value(config, "size")[0] // config["vae_stride"][1]
552 latent_w = get_input_value(config, "size")[1] // config["vae_stride"][2]
553 latent_shape = [
554 config.get("num_channels_latents", 16),
555 (get_input_value(config, "num_frames") - 1) // config["vae_stride"][0] + 1,
556 latent_h,
557 latent_w,
558 ]
559 image_encoder_output = None
560 elif task == "i2v":
561 image_path = get_input_value(config, "image_path", None)
562 if image_path is None:
563 raise ValueError("image_path is required for i2v task.")
564
565 # 2. Image Encoding + VAE Encoding
566 img, _ = read_image_input(image_path)
567
568 if self.image_encoder is not None:
569 # Assuming image_encoder.visual handles list of images
570 clip_encoder_out = self.image_encoder.visual([img]).squeeze(0).to(GET_DTYPE())
571
572 if self.vae_encoder is None:
573 raise RuntimeError("VAE encoder is required but was not loaded.")

Callers 1

runMethod · 0.95

Calls 15

_wait_sender_successMethod · 0.95
read_image_inputFunction · 0.90
GET_DTYPEFunction · 0.90
_buffer_viewFunction · 0.85
_sha256_tensorFunction · 0.85
infoMethod · 0.80
setdefaultMethod · 0.80

Tested by

no test coverage detected