# gvclab/personalive architecture

> Architecture diagram of the GitHub repository gvclab/personalive, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gvclab/personalive
- Repository: https://github.com/gvclab/personalive

## Overview

#### Purpose and Entry Points
PersonaLive is a PyTorch diffusion system for real-time, streamable portrait animation: a reference image is animated by motion from a driving video or webcam. Batch and live entry points are `inference_offline.py` and `inference_online.py`; the latter serves a browser UI at port 7860. Training is explicitly staged through `train_stage1.py`, `train_stage2.py`, and `train_stage3.py`.

#### Inference Orchestration
Offline inference consumes a reference image plus driving video, with optional long-video streaming generation and xFormers attention. Live inference selects normal, xFormers, or TensorRT execution. Configuration separates stage 1/2 inference from stage 3 temporal streaming:
- `inference_offline.py`
- `inference_online.py`
- `configs/inference/inference_stage1&2.yaml`
- `configs/inference/inference_stage3.yaml`

#### Animation Pipeline
The central boundary is motion extraction versus diffusion synthesis. LivePortrait-derived components derive facial motion/camera signals from driving frames; pose conditioning and motion features then drive reference-conditioned image/video diffusion pipelines.
- `src/liveportrait/motion_extractor.py`
- `src/models/pose_guider.py`
- `src/pipelines/pipeline_pose2img.py`
- `src/pipelines/pipeline_pose2vid.py`

#### Diffusion and Temporal Model Stack
Reference appearance is represented through a reference UNet/attention path, while denoising uses customized 2D/3D UNets. The video path adds temporal modules and explicit reference handling to preserve identity and continuity over generated frame windows. DDIM controls the iterative denoising schedule.
- `src/models/unet_2d_condition.py`
- `src/models/unet_3d_explicit_reference.py`
- `src/models/motion_module.py`
- `src/scheduler/scheduler_ddim.py`

#### Runtime Wrappers and Acceleration
The wrapper layer packages model loading and inference execution. Standard execution is CUDA/PyTorch; ONNX export and TensorRT provide an optimized UNet path, with a locally built engine expected for hardware compatibility. Pretrained PersonaLive, Stable Diffusion VAE/image-variation, ONNX, and TensorRT artifacts are external runtime inputs under `pretrained_weights/`.
- `src/wrapper.py`
- `src/wrapper_trt.py`
- `src/modeling/onnx_export.py`
- `torch2trt.py`

#### Live Streaming Interface
The online path bridges webcam/video capture, frame-by-frame animation, and browser transport. Python live-video workers have standard and TensorRT variants; a Svelte frontend supplies image/video inputs, controls, logging, and rendered-frame playback. This is a local streaming application rather than a hosted backend integration.
- `webcam/vid2vid.py`
- `webcam/vid2vid_trt.py`
- `webcam/connection_manager.py`
- `webcam/frontend/src/routes/+page.svelte`

#### Training and Data Flow
Training progresses from image-level warm-up, to adversarial image refinement using StyleGAN2 discrimination, to temporal-module fine-tuning for streamable video. Video datasets require aligned face/eye/mouth box artifacts; portrait dataset loaders and augmentation feed stage-specific configs. Stages consume predecessor checkpoints, making checkpoint paths the handoff boundary.
- `train_stage1.py`
- `train_stage2.py`
- `train_stage3.py`
- `src/dataset/portrait_video.py`
- `src/stylegan2/discriminator.py`
- `configs/train/personalive_stage3.yaml`

Main entry points: [`src/pipelines/pipeline_pose2vid.py`](https://github.com/gvclab/personalive/blob/main/src/pipelines/pipeline_pose2vid.py) (Pose-to-video pipeline), [`src/pipelines/pipeline_pose2img.py`](https://github.com/gvclab/personalive/blob/main/src/pipelines/pipeline_pose2img.py) (Pose-to-image pipeline), [`train_stage2.py`](https://github.com/gvclab/personalive/blob/main/train_stage2.py) (Stage 2 training), [`train_stage3.py`](https://github.com/gvclab/personalive/blob/main/train_stage3.py) (Stage 3 training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference &amp; Streaming"]
  node_offline["Offline inference<br/>batch entry point"]
  node_online["Online inference<br/>live entry point"]
  node_inference_config["Inference configs<br/>stage config"]
  node_temporal_config["Streaming config<br/>stage config"]
  node_live_worker["Live video worker<br/>stream worker<br/>[vid2vid.py]"]
  node_trt_live_worker["TensorRT live worker<br/>stream worker<br/>[vid2vid_trt.py]"]
  node_connection_manager["Browser transport<br/>connection manager"]
  node_frontend["Svelte frontend<br/>browser UI<br/>[+page.svelte]"]
end

subgraph group_synthesis["Animation &amp; Diffusion"]
  node_motion_extractor["Motion extractor<br/>facial motion model"]
  node_pose_guider["Pose guider<br/>conditioning model<br/>[pose_guider.py]"]
  node_pose2img["Pose-to-image pipeline<br/>image diffusion pipeline"]
  node_pose2vid["Pose-to-video pipeline<br/>video diffusion pipeline"]
  node_unet2d["2D conditioning UNet<br/>denoiser"]
  node_unet3d["3D reference UNet<br/>temporal denoiser"]
  node_motion_module["Temporal modules<br/>temporal model<br/>[motion_module.py]"]
  node_ddim["DDIM scheduler<br/>diffusion scheduler<br/>[scheduler_ddim.py]"]
end

subgraph group_acceleration["Runtime Acceleration"]
  node_wrapper["PyTorch wrapper<br/>runtime wrapper<br/>[wrapper.py]"]
  node_trt_wrapper["TensorRT wrapper<br/>optimized runtime<br/>[wrapper_trt.py]"]
  node_onnx_export["ONNX export<br/>model exporter<br/>[onnx_export.py]"]
  node_torch2trt["TensorRT engine builder<br/>[torch2trt.py]"]
end

subgraph group_training["Training"]
  node_stage1["Stage 1 training<br/>image warm-up<br/>[train_stage1.py]"]
  node_stage2["Stage 2 training<br/>adversarial refinement<br/>[train_stage2.py]"]
  node_stage3["Stage 3 training<br/>temporal fine-tuning<br/>[train_stage3.py]"]
  node_dataset[("Portrait video dataset<br/>dataset loader<br/>[portrait_video.py]")]
  node_discriminator["StyleGAN2 discriminator<br/>adversarial model<br/>[discriminator.py]"]
  node_stage3_config["Stage 3 config<br/>training config"]
end

node_offline -->|"loads"| node_inference_config
node_offline -->|"uses for streaming"| node_temporal_config
node_online -->|"starts"| node_live_worker
node_online -.->|"selects when optimized"| node_trt_live_worker
node_frontend -->|"browser stream"| node_connection_manager
node_connection_manager -->|"frames"| node_live_worker
node_live_worker -->|"driving frames"| node_motion_extractor
node_motion_extractor -->|"motion and camera"| node_pose_guider
node_pose_guider -->|"pose conditioning"| node_pose2img
node_pose_guider -->|"pose conditioning"| node_pose2vid
node_pose2img -->|"denoises with"| node_unet2d
node_pose2vid -->|"denoises with"| node_unet3d
node_motion_module -->|"temporal layers"| node_unet3d
node_ddim -->|"sampling schedule"| node_pose2img
node_ddim -->|"sampling schedule"| node_pose2vid
node_wrapper -->|"runs"| node_pose2img
node_wrapper -->|"runs"| node_pose2vid
node_trt_live_worker -->|"uses"| node_trt_wrapper
node_trt_wrapper -->|"optimized execution"| node_pose2vid
node_onnx_export -->|"exported model"| node_torch2trt
node_torch2trt -->|"engine"| node_trt_wrapper
node_dataset -->|"training data"| node_stage1
node_stage1 -->|"checkpoint handoff"| node_stage2
node_dataset -->|"training data"| node_stage2
node_discriminator -->|"adversarial supervision"| node_stage2
node_stage2 -->|"checkpoint handoff"| node_stage3
node_dataset -->|"video training data"| node_stage3
node_stage3_config -->|"configures"| node_stage3
node_stage3 -->|"fine-tunes"| node_motion_module

click node_offline "https://github.com/gvclab/personalive/blob/main/inference_offline.py"
click node_online "https://github.com/gvclab/personalive/blob/main/inference_online.py"
click node_inference_config "https://github.com/gvclab/personalive/blob/main/configs/inference/inference_stage1%262.yaml"
click node_temporal_config "https://github.com/gvclab/personalive/blob/main/configs/inference/inference_stage3.yaml"
click node_live_worker "https://github.com/gvclab/personalive/blob/main/webcam/vid2vid.py"
click node_trt_live_worker "https://github.com/gvclab/personalive/blob/main/webcam/vid2vid_trt.py"
click node_connection_manager "https://github.com/gvclab/personalive/blob/main/webcam/connection_manager.py"
click node_frontend "https://github.com/gvclab/personalive/blob/main/webcam/frontend/src/routes/%2Bpage.svelte"
click node_motion_extractor "https://github.com/gvclab/personalive/blob/main/src/liveportrait/motion_extractor.py"
click node_pose_guider "https://github.com/gvclab/personalive/blob/main/src/models/pose_guider.py"
click node_pose2img "https://github.com/gvclab/personalive/blob/main/src/pipelines/pipeline_pose2img.py"
click node_pose2vid "https://github.com/gvclab/personalive/blob/main/src/pipelines/pipeline_pose2vid.py"
click node_unet2d "https://github.com/gvclab/personalive/blob/main/src/models/unet_2d_condition.py"
click node_unet3d "https://github.com/gvclab/personalive/blob/main/src/models/unet_3d_explicit_reference.py"
click node_motion_module "https://github.com/gvclab/personalive/blob/main/src/models/motion_module.py"
click node_ddim "https://github.com/gvclab/personalive/blob/main/src/scheduler/scheduler_ddim.py"
click node_wrapper "https://github.com/gvclab/personalive/blob/main/src/wrapper.py"
click node_trt_wrapper "https://github.com/gvclab/personalive/blob/main/src/wrapper_trt.py"
click node_onnx_export "https://github.com/gvclab/personalive/blob/main/src/modeling/onnx_export.py"
click node_torch2trt "https://github.com/gvclab/personalive/blob/main/torch2trt.py"
click node_stage1 "https://github.com/gvclab/personalive/blob/main/train_stage1.py"
click node_stage2 "https://github.com/gvclab/personalive/blob/main/train_stage2.py"
click node_stage3 "https://github.com/gvclab/personalive/blob/main/train_stage3.py"
click node_dataset "https://github.com/gvclab/personalive/blob/main/src/dataset/portrait_video.py"
click node_discriminator "https://github.com/gvclab/personalive/blob/main/src/stylegan2/discriminator.py"
click node_stage3_config "https://github.com/gvclab/personalive/blob/main/configs/train/personalive_stage3.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_offline,node_online,node_inference_config,node_temporal_config,node_live_worker,node_trt_live_worker,node_connection_manager,node_frontend toneBlue
class node_motion_extractor,node_pose_guider,node_pose2img,node_pose2vid,node_unet2d,node_unet3d,node_motion_module,node_ddim toneAmber
class node_wrapper,node_trt_wrapper,node_onnx_export,node_torch2trt toneMint
class node_stage1,node_stage2,node_stage3,node_dataset,node_discriminator,node_stage3_config toneRose
```

## Components

### Inference & Streaming

- [Offline inference](https://github.com/gvclab/personalive/blob/main/inference_offline.py): batch entry point · Animates a reference image from a driving video. · `inference_offline.py`
- [Online inference](https://github.com/gvclab/personalive/blob/main/inference_online.py): live entry point · Serves the local browser UI on port 7860. · `inference_online.py`
- [Inference configs](https://github.com/gvclab/personalive/blob/main/configs/inference/inference_stage1%262.yaml): stage config · Separates image stages from temporal streaming. · `configs/inference/inference_stage1&2.yaml`
- [Streaming config](https://github.com/gvclab/personalive/blob/main/configs/inference/inference_stage3.yaml): stage config · `configs/inference/inference_stage3.yaml`
- [Live video worker](https://github.com/gvclab/personalive/blob/main/webcam/vid2vid.py): stream worker · Captures and animates video frames. · `webcam/vid2vid.py`
- [TensorRT live worker](https://github.com/gvclab/personalive/blob/main/webcam/vid2vid_trt.py): stream worker · `webcam/vid2vid_trt.py`
- [Browser transport](https://github.com/gvclab/personalive/blob/main/webcam/connection_manager.py): connection manager · Moves rendered frames to the local client. · `webcam/connection_manager.py`
- [Svelte frontend](https://github.com/gvclab/personalive/blob/main/webcam/frontend/src/routes/%2Bpage.svelte): browser UI · Provides inputs, controls, logs, and playback. · `webcam/frontend/src/routes/+page.svelte`

### Animation & Diffusion

- [Motion extractor](https://github.com/gvclab/personalive/blob/main/src/liveportrait/motion_extractor.py): facial motion model · Derives facial motion and camera signals from driving frames. · `src/liveportrait/motion_extractor.py`
- [Pose guider](https://github.com/gvclab/personalive/blob/main/src/models/pose_guider.py): conditioning model · Converts extracted motion into diffusion conditioning. · `src/models/pose_guider.py`
- [Pose-to-image pipeline](https://github.com/gvclab/personalive/blob/main/src/pipelines/pipeline_pose2img.py): image diffusion pipeline · Generates reference-conditioned portrait frames. · `src/pipelines/pipeline_pose2img.py`
- [Pose-to-video pipeline](https://github.com/gvclab/personalive/blob/main/src/pipelines/pipeline_pose2vid.py): video diffusion pipeline · Generates temporal frame windows with explicit reference handling. · `src/pipelines/pipeline_pose2vid.py`
- [2D conditioning UNet](https://github.com/gvclab/personalive/blob/main/src/models/unet_2d_condition.py): denoiser · Image-stage diffusion denoiser. · `src/models/unet_2d_condition.py`
- [3D reference UNet](https://github.com/gvclab/personalive/blob/main/src/models/unet_3d_explicit_reference.py): temporal denoiser · Video denoiser with explicit reference conditioning. · `src/models/unet_3d_explicit_reference.py`
- [Temporal modules](https://github.com/gvclab/personalive/blob/main/src/models/motion_module.py): temporal model · Adds continuity across generated video windows. · `src/models/motion_module.py`
- [DDIM scheduler](https://github.com/gvclab/personalive/blob/main/src/scheduler/scheduler_ddim.py): diffusion scheduler · Controls iterative denoising. · `src/scheduler/scheduler_ddim.py`

### Runtime Acceleration

- [PyTorch wrapper](https://github.com/gvclab/personalive/blob/main/src/wrapper.py): runtime wrapper · Packages model loading and CUDA/PyTorch execution. · `src/wrapper.py`
- [TensorRT wrapper](https://github.com/gvclab/personalive/blob/main/src/wrapper_trt.py): optimized runtime · Runs the optimized UNet execution path. · `src/wrapper_trt.py`
- [ONNX export](https://github.com/gvclab/personalive/blob/main/src/modeling/onnx_export.py): model exporter · Exports the optimized UNet path for TensorRT. · `src/modeling/onnx_export.py`
- [TensorRT engine builder](https://github.com/gvclab/personalive/blob/main/torch2trt.py): engine builder · Builds hardware-compatible local engines. · `torch2trt.py`

### Training

- [Stage 1 training](https://github.com/gvclab/personalive/blob/main/train_stage1.py): image warm-up · `train_stage1.py`
- [Stage 2 training](https://github.com/gvclab/personalive/blob/main/train_stage2.py): adversarial refinement · Refines images with adversarial training. · `train_stage2.py`
- [Stage 3 training](https://github.com/gvclab/personalive/blob/main/train_stage3.py): temporal fine-tuning · Fine-tunes streamable video temporal modules. · `train_stage3.py`
- [Portrait video dataset](https://github.com/gvclab/personalive/blob/main/src/dataset/portrait_video.py): dataset loader · Consumes portrait video and aligned facial-region artifacts. · `src/dataset/portrait_video.py`
- [StyleGAN2 discriminator](https://github.com/gvclab/personalive/blob/main/src/stylegan2/discriminator.py): adversarial model · `src/stylegan2/discriminator.py`
- [Stage 3 config](https://github.com/gvclab/personalive/blob/main/configs/train/personalive_stage3.yaml): training config · `configs/train/personalive_stage3.yaml`

## Connections

- Offline inference → Inference configs: loads
- Offline inference → Streaming config: uses for streaming
- Online inference → Live video worker: starts
- Online inference → TensorRT live worker: selects when optimized
- Svelte frontend → Browser transport: browser stream
- Browser transport → Live video worker: frames
- Live video worker → Motion extractor: driving frames
- Motion extractor → Pose guider: motion and camera
- Pose guider → Pose-to-image pipeline: pose conditioning
- Pose guider → Pose-to-video pipeline: pose conditioning
- Pose-to-image pipeline → 2D conditioning UNet: denoises with
- Pose-to-video pipeline → 3D reference UNet: denoises with
- Temporal modules → 3D reference UNet: temporal layers
- DDIM scheduler → Pose-to-image pipeline: sampling schedule
- DDIM scheduler → Pose-to-video pipeline: sampling schedule
- PyTorch wrapper → Pose-to-image pipeline: runs
- PyTorch wrapper → Pose-to-video pipeline: runs
- TensorRT live worker → TensorRT wrapper: uses
- TensorRT wrapper → Pose-to-video pipeline: optimized execution
- ONNX export → TensorRT engine builder: exported model
- TensorRT engine builder → TensorRT wrapper: engine
- Portrait video dataset → Stage 1 training: training data
- Stage 1 training → Stage 2 training: checkpoint handoff
- Portrait video dataset → Stage 2 training: training data
- StyleGAN2 discriminator → Stage 2 training: adversarial supervision
- Stage 2 training → Stage 3 training: checkpoint handoff
- Portrait video dataset → Stage 3 training: video training data
- Stage 3 config → Stage 3 training: configures
- Stage 3 training → Temporal modules: fine-tunes
