Initial release: Memento LoRA + KeyframeQuery weights
Browse files- README.md +158 -0
- backbone_high_noise.safetensors +3 -0
- backbone_low_noise.safetensors +3 -0
- config.json +72 -0
README.md
CHANGED
|
@@ -1,3 +1,161 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- video-generation
|
| 5 |
+
- wan
|
| 6 |
+
- lora
|
| 7 |
+
- memory-to-video
|
| 8 |
+
- character-consistency
|
| 9 |
+
- long-video
|
| 10 |
+
base_model:
|
| 11 |
+
- Wan-AI/Wan2.2-T2V-A14B
|
| 12 |
+
- Wan-AI/Wan2.2-I2V-A14B
|
| 13 |
---
|
| 14 |
+
|
| 15 |
+
# Memento - LoRA Weights for Consistent Long Video Generation
|
| 16 |
+
|
| 17 |
+
Memento enables character-consistent multi-shot long video generation by extending Wan2.2-A14B with a learnable memory mechanism and identity reconstruction.
|
| 18 |
+
|
| 19 |
+
## Model Details
|
| 20 |
+
|
| 21 |
+
| Property | Value |
|
| 22 |
+
|----------|-------|
|
| 23 |
+
| Base model | Wan2.2-A14B (T2V + I2V) |
|
| 24 |
+
| Architecture | Dual DiT (low noise + high noise) with flow matching, boundary at t=0.9 |
|
| 25 |
+
| LoRA rank | 128 |
|
| 26 |
+
| LoRA targets | Self-attention (Q/K/V/O) + Cross-attention (Q/K/V/O) + FFN layers |
|
| 27 |
+
| Additional modules | KeyframeQuery (learnable memory selection, 12 queries) |
|
| 28 |
+
| Parameters | ~3.2 GB per noise model (LoRA + KeyframeQuery) |
|
| 29 |
+
| Precision | bfloat16 |
|
| 30 |
+
| Resolution | 832x480, 81 frames per shot (~5s at 16fps) |
|
| 31 |
+
|
| 32 |
+
## Key Features
|
| 33 |
+
|
| 34 |
+
- **Memory-to-Video (M2V)**: Maintains a latent memory pool across shots, enabling character consistency across an entire story
|
| 35 |
+
- **Learnable KeyframeQuery**: Selects the most relevant memory frames per shot using split local+global queries
|
| 36 |
+
- **Identity Reconstruction**: Uses character appearance descriptions to condition identity preservation
|
| 37 |
+
- **Split Identity Attention**: Separates identity and memory attention paths for better consistency
|
| 38 |
+
- **Dual Query Mode**: Low noise and high noise models use independent keyframe queries optimized for their respective denoising stages
|
| 39 |
+
|
| 40 |
+
## Files
|
| 41 |
+
|
| 42 |
+
```
|
| 43 |
+
backbone_low_noise.pth # Low noise model: LoRA weights + KeyframeQuery (t < 0.9)
|
| 44 |
+
backbone_high_noise.pth # High noise model: LoRA weights + KeyframeQuery (t >= 0.9)
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
Each file contains:
|
| 48 |
+
- `trainable_state_dict`: 800 LoRA parameter tensors + 24 KeyframeQuery parameter tensors
|
| 49 |
+
- `config`: training configuration metadata
|
| 50 |
+
|
| 51 |
+
## Usage
|
| 52 |
+
|
| 53 |
+
### Requirements
|
| 54 |
+
|
| 55 |
+
- 8x NVIDIA GPUs (A100 80GB recommended)
|
| 56 |
+
- PyTorch 2.0+
|
| 57 |
+
- Base models: [Wan2.2-T2V-A14B](https://huggingface.co/Wan-AI/Wan2.2-T2V-A14B) and [Wan2.2-I2V-A14B](https://huggingface.co/Wan-AI/Wan2.2-I2V-A14B)
|
| 58 |
+
- Dependencies: `transformers`, `peft`, `json5`, `av`, `decord`, `diffusers`
|
| 59 |
+
|
| 60 |
+
### Directory Setup
|
| 61 |
+
|
| 62 |
+
```
|
| 63 |
+
memento_src/
|
| 64 |
+
├── models/
|
| 65 |
+
│ ├── Wan2.2-T2V-A14B/ # Base T2V model
|
| 66 |
+
│ ├── Wan2.2-I2V-A14B/ # Base I2V model
|
| 67 |
+
│ └── memento_lora/ # This repo's weights
|
| 68 |
+
│ ├── backbone_low_noise.pth
|
| 69 |
+
│ └── backbone_high_noise.pth
|
| 70 |
+
└── ...
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
### Single Story Inference
|
| 74 |
+
|
| 75 |
+
```bash
|
| 76 |
+
cd memento_src
|
| 77 |
+
|
| 78 |
+
torchrun --nproc_per_node=8 --master_port=8200 \
|
| 79 |
+
pipeline_learnable_acce.py \
|
| 80 |
+
--story_script_path ./story_rewritten_aligned/showcase/astronaut.json \
|
| 81 |
+
--t2v_model_path ./models/Wan2.2-T2V-A14B \
|
| 82 |
+
--i2v_model_path ./models/Wan2.2-I2V-A14B \
|
| 83 |
+
--lora_weight_path ./models/memento_lora \
|
| 84 |
+
--size "832*480" \
|
| 85 |
+
--max_memory_size 8 \
|
| 86 |
+
--max_memory_frames 8 \
|
| 87 |
+
--output_dir ./results/astronaut \
|
| 88 |
+
--ulysses_size 8 \
|
| 89 |
+
--offload_model \
|
| 90 |
+
--lora_rank 128 \
|
| 91 |
+
--mi2v \
|
| 92 |
+
--t2v_first_shot \
|
| 93 |
+
--t5_fsdp \
|
| 94 |
+
--dit_fsdp \
|
| 95 |
+
--split_identity_attn \
|
| 96 |
+
--split_learnable_query \
|
| 97 |
+
--global_query_num 2 \
|
| 98 |
+
--use_subject_recon \
|
| 99 |
+
--use_both_query \
|
| 100 |
+
--compile_dit
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### Batch Inference
|
| 104 |
+
|
| 105 |
+
```bash
|
| 106 |
+
bash run_inference.sh ./story_rewritten_aligned/showcase ./results ./models/memento_lora
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### Key Inference Flags
|
| 110 |
+
|
| 111 |
+
| Flag | Description |
|
| 112 |
+
|------|-------------|
|
| 113 |
+
| `--t2v_first_shot` | Generate first shot with T2V model (no memory conditioning) |
|
| 114 |
+
| `--mi2v` | Use last frame of previous shot as I2V condition for continuous shots |
|
| 115 |
+
| `--split_identity_attn` | Enable split identity+memory attention mechanism |
|
| 116 |
+
| `--split_learnable_query` | Use separate local and global queries for memory selection |
|
| 117 |
+
| `--global_query_num 2` | Number of global (appearance-focused) memory queries |
|
| 118 |
+
| `--use_subject_recon` | Enable identity reconstruction conditioning |
|
| 119 |
+
| `--use_both_query` | Each noise model uses its own KeyframeQuery for memory selection |
|
| 120 |
+
| `--compile_dit` | Apply torch.compile for ~15% speedup (slower first step) |
|
| 121 |
+
| `--max_memory_size 8` | Maximum memory frames fed to DiT |
|
| 122 |
+
| `--max_memory_frames 8` | Frames sampled from previous shot for memory update |
|
| 123 |
+
|
| 124 |
+
### Story Script Format
|
| 125 |
+
|
| 126 |
+
```json
|
| 127 |
+
{
|
| 128 |
+
"reconstruct_target": "[Person A] physical appearance description\n[Person B] physical appearance description",
|
| 129 |
+
"scenes": [
|
| 130 |
+
{
|
| 131 |
+
"scene_num": 1,
|
| 132 |
+
"cut": [true, false, false],
|
| 133 |
+
"video_prompts": [
|
| 134 |
+
"global caption: [Person A]: appearance; shot caption: [Person A] action in present tense...",
|
| 135 |
+
"global caption: [Person A]: appearance; shot caption: [Person A] continues action...",
|
| 136 |
+
"global caption: [Person A]: appearance; shot caption: [Person A] final action..."
|
| 137 |
+
]
|
| 138 |
+
}
|
| 139 |
+
]
|
| 140 |
+
}
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
- `reconstruct_target`: Character identity descriptions (appearance only, no actions). One per line.
|
| 144 |
+
- `cut[i]`: `true` = new camera angle (no I2V conditioning), `false` = continuous from previous shot
|
| 145 |
+
- `global caption`: Lists appearances of characters **visible in this shot only**
|
| 146 |
+
- `shot caption`: 1-3 sentences describing the visual action in present tense
|
| 147 |
+
|
| 148 |
+
## How It Works
|
| 149 |
+
|
| 150 |
+
1. **Shot 1**: Generated purely by T2V model using the first video_prompt
|
| 151 |
+
2. **Subsequent shots**: Memory pool accumulates keyframes from all previous shots. The KeyframeQuery module selects the most relevant 8 frames based on the current shot's prompt. These memory frames + identity description condition the generation to maintain character consistency.
|
| 152 |
+
3. **Continuous shots** (`cut=false`): Additionally use the last frame of the previous shot as an I2V starting frame for smooth visual transitions.
|
| 153 |
+
|
| 154 |
+
## Citation
|
| 155 |
+
|
| 156 |
+
```bibtex
|
| 157 |
+
@article{memento2025,
|
| 158 |
+
title={Memento: Reconstruct to Remember for Consistent Long Video Generation},
|
| 159 |
+
year={2025}
|
| 160 |
+
}
|
| 161 |
+
```
|
backbone_high_noise.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:abeea090c9e01c7b5292b7ec5a83e91655e3776e985b6cc49a7c9bed59759168
|
| 3 |
+
size 1647301008
|
backbone_low_noise.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d863230da54c34758b77a251982c047f355bc1c8e7eb6bc468209635219a2d72
|
| 3 |
+
size 1647300184
|
config.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "memento",
|
| 3 |
+
"model_name": "Memento",
|
| 4 |
+
"version": "1.0",
|
| 5 |
+
"license": "apache-2.0",
|
| 6 |
+
"description": "Memento LoRA + KeyframeQuery weights for character-consistent multi-shot long video generation, built on Wan2.2-A14B.",
|
| 7 |
+
"base_model": {
|
| 8 |
+
"t2v": "Wan-AI/Wan2.2-T2V-A14B",
|
| 9 |
+
"i2v": "Wan-AI/Wan2.2-I2V-A14B",
|
| 10 |
+
"architecture": "Dual DiT (low-noise + high-noise) with flow matching",
|
| 11 |
+
"boundary": 0.9
|
| 12 |
+
},
|
| 13 |
+
"lora": {
|
| 14 |
+
"rank": 128,
|
| 15 |
+
"alpha": 128,
|
| 16 |
+
"dropout": 0.0,
|
| 17 |
+
"hidden_dim": 5120,
|
| 18 |
+
"target_modules": [
|
| 19 |
+
"self_attn.q",
|
| 20 |
+
"self_attn.k",
|
| 21 |
+
"self_attn.v",
|
| 22 |
+
"self_attn.o",
|
| 23 |
+
"cross_attn.q",
|
| 24 |
+
"cross_attn.k",
|
| 25 |
+
"cross_attn.v",
|
| 26 |
+
"cross_attn.o",
|
| 27 |
+
"ffn.0",
|
| 28 |
+
"ffn.2"
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
"keyframe_query": {
|
| 32 |
+
"num_local_queries": 10,
|
| 33 |
+
"num_global_queries": 2,
|
| 34 |
+
"num_keyframes": 10,
|
| 35 |
+
"query_dim": 5120,
|
| 36 |
+
"memory_patch_in_channels": 16,
|
| 37 |
+
"memory_patch_size": [1, 2, 2]
|
| 38 |
+
},
|
| 39 |
+
"precision": "bfloat16",
|
| 40 |
+
"video": {
|
| 41 |
+
"resolution": "832x480",
|
| 42 |
+
"frames_per_shot": 81,
|
| 43 |
+
"fps": 16
|
| 44 |
+
},
|
| 45 |
+
"files": {
|
| 46 |
+
"low_noise_weights": "backbone_low_noise.safetensors",
|
| 47 |
+
"high_noise_weights": "backbone_high_noise.safetensors"
|
| 48 |
+
},
|
| 49 |
+
"inference": {
|
| 50 |
+
"num_gpus": 8,
|
| 51 |
+
"ulysses_size": 8,
|
| 52 |
+
"lora_rank": 128,
|
| 53 |
+
"size": "832*480",
|
| 54 |
+
"max_memory_size": 8,
|
| 55 |
+
"max_memory_frames": 8,
|
| 56 |
+
"global_query_num": 2,
|
| 57 |
+
"sample_guide_scale": 3.5,
|
| 58 |
+
"sample_solver": "unipc",
|
| 59 |
+
"flags": {
|
| 60 |
+
"mi2v": true,
|
| 61 |
+
"t2v_first_shot": true,
|
| 62 |
+
"t5_fsdp": true,
|
| 63 |
+
"dit_fsdp": true,
|
| 64 |
+
"split_identity_attn": true,
|
| 65 |
+
"split_learnable_query": true,
|
| 66 |
+
"use_subject_recon": true,
|
| 67 |
+
"use_both_query": true,
|
| 68 |
+
"offload_model": true,
|
| 69 |
+
"compile_dit": true
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
}
|