# kevin-thu/storymem architecture

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

- Interactive diagram: https://gitdiagram.com/kevin-thu/storymem
- Repository: https://github.com/kevin-thu/storymem

## Overview

StoryMem turns a structured, shot-level story script into a coherent multi-shot video: it generates an initial shot or accepts reference memory, then generates later shots using accumulated visual memory and extracts keyframes between shots. The README documents the workflow and optional MI2V/MM2V continuity modes; the source index and excerpts show the orchestration entry points and Wan model dependencies. Several implementation details are unsampled, so edges for README-described stages cite the README rather than implying further source inspection.

Main entry points: [`wan/memory2video.py`](https://github.com/kevin-thu/storymem/blob/main/wan/memory2video.py) (Memory-to-video), [`pipeline.py`](https://github.com/kevin-thu/storymem/blob/main/pipeline.py) (Shot orchestrator), [`generate.py`](https://github.com/kevin-thu/storymem/blob/main/generate.py) (Generation entry), [`wan/modules/t5.py`](https://github.com/kevin-thu/storymem/blob/main/wan/modules/t5.py) (T5 encoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_story["Story workflow"]
  node_scripts["Story scripts"]
  node_runner["Run interface<br/>[run_example.sh]"]
  node_orchestrator["Shot orchestrator<br/>[pipeline.py]"]
  node_generator["Generation entry<br/>[generate.py]"]
  node_memory["Shot memory<br/>[pipeline.py]"]
  node_keyframes["Keyframe extraction"]
  node_videos["Output videos<br/>[pipeline.py]"]
end

subgraph group_generation["Generation modes"]
  node_wan_t2v["Text-to-video<br/>[text2video.py]"]
  node_wan_i2v["Image-to-video<br/>[image2video.py]"]
  node_wan_m2v["Memory-to-video<br/>[memory2video.py]"]
  node_wan_ti2v["Text-image video<br/>[textimage2video.py]"]
  node_prompt["Prompt extension<br/>[prompt_extend.py]"]
  node_system_prompt["Extension prompts<br/>[system_prompt.py]"]
end

subgraph group_models["Model components"]
  node_text_encoder["T5 encoder<br/>[t5.py]"]
  node_tokenizers["Tokenizers<br/>[tokenizers.py]"]
  node_dit["Video diffusion model<br/>[model.py]"]
  node_memory_dit["Memory diffusion model<br/>[model_memory.py]"]
  node_attention["Attention kernels<br/>[attention.py]"]
  node_vae21["Wan 2.1 VAE<br/>[vae2_1.py]"]
  node_vae22["Wan 2.2 VAE<br/>[vae2_2.py]"]
  node_solver["Diffusion solvers<br/>[fm_solvers.py]"]
  node_unipc["UniPC solver"]
end

subgraph group_runtime["Runtime support"]
  node_configs["Model configs<br/>[shared_config.py]"]
  node_distributed["Distributed runtime"]
  node_fsdp["FSDP sharding<br/>[fsdp.py]"]
end

node_user(("Story author"))

node_user -->|"writes"| node_scripts
node_user -->|"starts"| node_runner
node_runner -.->|"runs"| node_orchestrator
node_orchestrator -->|"reads"| node_scripts
node_orchestrator -->|"dispatches"| node_generator
node_orchestrator -->|"updates"| node_memory
node_orchestrator -->|"extracts"| node_keyframes
node_orchestrator -->|"writes"| node_videos
node_generator -->|"generates first shot"| node_wan_t2v
node_generator -->|"generates later shots"| node_wan_m2v
node_generator -.->|"supports image input"| node_wan_i2v
node_generator -.->|"supports joint conditioning"| node_wan_ti2v
node_generator -->|"extends prompts"| node_prompt
node_prompt -->|"uses prompts"| node_system_prompt
node_wan_m2v -->|"loads"| node_memory_dit
node_wan_m2v -->|"uses"| node_text_encoder
node_wan_m2v -->|"uses"| node_vae21
node_wan_m2v -->|"samples with"| node_solver
node_wan_m2v -->|"samples with"| node_unipc
node_wan_m2v -->|"configures parallelism"| node_distributed
node_wan_m2v -->|"shards model"| node_fsdp
node_wan_t2v -->|"loads"| node_dit
node_wan_t2v -->|"uses"| node_text_encoder
node_wan_t2v -->|"uses"| node_vae21
node_wan_i2v -->|"loads"| node_dit
node_wan_i2v -->|"uses"| node_text_encoder
node_wan_i2v -->|"uses"| node_vae21
node_wan_ti2v -->|"loads"| node_dit
node_wan_ti2v -->|"uses"| node_text_encoder
node_wan_ti2v -->|"uses"| node_vae22
node_text_encoder -->|"tokenizes with"| node_tokenizers
node_dit -->|"uses"| node_attention
node_memory_dit -->|"uses"| node_attention
node_distributed -->|"parallelizes"| node_dit
node_wan_m2v -.->|"loads settings"| node_configs

click node_scripts "https://github.com/kevin-thu/storymem/tree/main/story"
click node_runner "https://github.com/kevin-thu/storymem/blob/main/run_example.sh"
click node_orchestrator "https://github.com/kevin-thu/storymem/blob/main/pipeline.py"
click node_generator "https://github.com/kevin-thu/storymem/blob/main/generate.py"
click node_memory "https://github.com/kevin-thu/storymem/blob/main/pipeline.py"
click node_keyframes "https://github.com/kevin-thu/storymem/blob/main/extract_keyframes.py"
click node_videos "https://github.com/kevin-thu/storymem/blob/main/pipeline.py"
click node_wan_t2v "https://github.com/kevin-thu/storymem/blob/main/wan/text2video.py"
click node_wan_i2v "https://github.com/kevin-thu/storymem/blob/main/wan/image2video.py"
click node_wan_m2v "https://github.com/kevin-thu/storymem/blob/main/wan/memory2video.py"
click node_wan_ti2v "https://github.com/kevin-thu/storymem/blob/main/wan/textimage2video.py"
click node_prompt "https://github.com/kevin-thu/storymem/blob/main/wan/utils/prompt_extend.py"
click node_system_prompt "https://github.com/kevin-thu/storymem/blob/main/wan/utils/system_prompt.py"
click node_configs "https://github.com/kevin-thu/storymem/blob/main/wan/configs/shared_config.py"
click node_text_encoder "https://github.com/kevin-thu/storymem/blob/main/wan/modules/t5.py"
click node_tokenizers "https://github.com/kevin-thu/storymem/blob/main/wan/modules/tokenizers.py"
click node_dit "https://github.com/kevin-thu/storymem/blob/main/wan/modules/model.py"
click node_memory_dit "https://github.com/kevin-thu/storymem/blob/main/wan/modules/model_memory.py"
click node_attention "https://github.com/kevin-thu/storymem/blob/main/wan/modules/attention.py"
click node_vae21 "https://github.com/kevin-thu/storymem/blob/main/wan/modules/vae2_1.py"
click node_vae22 "https://github.com/kevin-thu/storymem/blob/main/wan/modules/vae2_2.py"
click node_solver "https://github.com/kevin-thu/storymem/blob/main/wan/utils/fm_solvers.py"
click node_unipc "https://github.com/kevin-thu/storymem/blob/main/wan/utils/fm_solvers_unipc.py"
click node_distributed "https://github.com/kevin-thu/storymem/blob/main/wan/distributed/sequence_parallel.py"
click node_fsdp "https://github.com/kevin-thu/storymem/blob/main/wan/distributed/fsdp.py"

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_scripts,node_runner,node_orchestrator,node_generator,node_memory,node_keyframes,node_videos toneBlue
class node_wan_t2v,node_wan_i2v,node_wan_m2v,node_wan_ti2v,node_prompt,node_system_prompt toneAmber
class node_text_encoder,node_tokenizers,node_dit,node_memory_dit,node_attention,node_vae21,node_vae22,node_solver,node_unipc toneMint
class node_configs,node_distributed,node_fsdp toneRose
class node_user toneIndigo
```

## Components

### Story workflow

- [Story scripts](https://github.com/kevin-thu/storymem/tree/main/story): `story`
- [Run interface](https://github.com/kevin-thu/storymem/blob/main/run_example.sh): `run_example.sh`
- [Shot orchestrator](https://github.com/kevin-thu/storymem/blob/main/pipeline.py): `pipeline.py`
- [Generation entry](https://github.com/kevin-thu/storymem/blob/main/generate.py): `generate.py`
- [Shot memory](https://github.com/kevin-thu/storymem/blob/main/pipeline.py): `pipeline.py`
- [Keyframe extraction](https://github.com/kevin-thu/storymem/blob/main/extract_keyframes.py): `extract_keyframes.py`
- [Output videos](https://github.com/kevin-thu/storymem/blob/main/pipeline.py): `pipeline.py`

### Generation modes

- [Text-to-video](https://github.com/kevin-thu/storymem/blob/main/wan/text2video.py): `wan/text2video.py`
- [Image-to-video](https://github.com/kevin-thu/storymem/blob/main/wan/image2video.py): `wan/image2video.py`
- [Memory-to-video](https://github.com/kevin-thu/storymem/blob/main/wan/memory2video.py): `wan/memory2video.py`
- [Text-image video](https://github.com/kevin-thu/storymem/blob/main/wan/textimage2video.py): `wan/textimage2video.py`
- [Prompt extension](https://github.com/kevin-thu/storymem/blob/main/wan/utils/prompt_extend.py): `wan/utils/prompt_extend.py`
- [Extension prompts](https://github.com/kevin-thu/storymem/blob/main/wan/utils/system_prompt.py): `wan/utils/system_prompt.py`

### Model components

- [T5 encoder](https://github.com/kevin-thu/storymem/blob/main/wan/modules/t5.py): `wan/modules/t5.py`
- [Tokenizers](https://github.com/kevin-thu/storymem/blob/main/wan/modules/tokenizers.py): `wan/modules/tokenizers.py`
- [Video diffusion model](https://github.com/kevin-thu/storymem/blob/main/wan/modules/model.py): `wan/modules/model.py`
- [Memory diffusion model](https://github.com/kevin-thu/storymem/blob/main/wan/modules/model_memory.py): `wan/modules/model_memory.py`
- [Attention kernels](https://github.com/kevin-thu/storymem/blob/main/wan/modules/attention.py): `wan/modules/attention.py`
- [Wan 2.1 VAE](https://github.com/kevin-thu/storymem/blob/main/wan/modules/vae2_1.py): `wan/modules/vae2_1.py`
- [Wan 2.2 VAE](https://github.com/kevin-thu/storymem/blob/main/wan/modules/vae2_2.py): `wan/modules/vae2_2.py`
- [Diffusion solvers](https://github.com/kevin-thu/storymem/blob/main/wan/utils/fm_solvers.py): `wan/utils/fm_solvers.py`
- [UniPC solver](https://github.com/kevin-thu/storymem/blob/main/wan/utils/fm_solvers_unipc.py): `wan/utils/fm_solvers_unipc.py`

### Runtime support

- [Model configs](https://github.com/kevin-thu/storymem/blob/main/wan/configs/shared_config.py): `wan/configs/shared_config.py`
- [Distributed runtime](https://github.com/kevin-thu/storymem/blob/main/wan/distributed/sequence_parallel.py): `wan/distributed/sequence_parallel.py`
- [FSDP sharding](https://github.com/kevin-thu/storymem/blob/main/wan/distributed/fsdp.py): `wan/distributed/fsdp.py`

### Other components

- **Story author**

## Connections

- Story author → Story scripts: writes (evidence: `README.md`)
- Story author → Run interface: starts (evidence: `README.md`)
- Run interface → Shot orchestrator: runs
- Shot orchestrator → Story scripts: reads (evidence: `README.md`)
- Shot orchestrator → Generation entry: dispatches (evidence: `pipeline.py`)
- Shot orchestrator → Shot memory: updates (evidence: `README.md`)
- Shot orchestrator → Keyframe extraction: extracts (evidence: `pipeline.py`)
- Shot orchestrator → Output videos: writes (evidence: `README.md`)
- Generation entry → Text-to-video: generates first shot (evidence: `README.md`)
- Generation entry → Memory-to-video: generates later shots (evidence: `README.md`)
- Generation entry → Image-to-video: supports image input
- Generation entry → Text-image video: supports joint conditioning
- Generation entry → Prompt extension: extends prompts (evidence: `generate.py`)
- Prompt extension → Extension prompts: uses prompts (evidence: `wan/utils/prompt_extend.py`)
- Memory-to-video → Memory diffusion model: loads (evidence: `wan/memory2video.py`)
- Memory-to-video → T5 encoder: uses (evidence: `wan/memory2video.py`)
- Memory-to-video → Wan 2.1 VAE: uses (evidence: `wan/memory2video.py`)
- Memory-to-video → Diffusion solvers: samples with (evidence: `wan/memory2video.py`)
- Memory-to-video → UniPC solver: samples with (evidence: `wan/memory2video.py`)
- Memory-to-video → Distributed runtime: configures parallelism (evidence: `wan/memory2video.py`)
- Memory-to-video → FSDP sharding: shards model (evidence: `wan/memory2video.py`)
- Text-to-video → Video diffusion model: loads (evidence: `wan/text2video.py`)
- Text-to-video → T5 encoder: uses (evidence: `wan/text2video.py`)
- Text-to-video → Wan 2.1 VAE: uses (evidence: `wan/text2video.py`)
- Image-to-video → Video diffusion model: loads (evidence: `wan/image2video.py`)
- Image-to-video → T5 encoder: uses (evidence: `wan/image2video.py`)
- Image-to-video → Wan 2.1 VAE: uses (evidence: `wan/image2video.py`)
- Text-image video → Video diffusion model: loads (evidence: `wan/textimage2video.py`)
- Text-image video → T5 encoder: uses (evidence: `wan/textimage2video.py`)
- Text-image video → Wan 2.2 VAE: uses (evidence: `wan/textimage2video.py`)
- T5 encoder → Tokenizers: tokenizes with (evidence: `wan/modules/t5.py`)
- Video diffusion model → Attention kernels: uses (evidence: `wan/modules/model.py`)
- Memory diffusion model → Attention kernels: uses (evidence: `wan/modules/model_memory.py`)
- Distributed runtime → Video diffusion model: parallelizes (evidence: `wan/distributed/sequence_parallel.py`)
- Memory-to-video → Model configs: loads settings
