Skip to content

Commit c9ca6d1

Browse files
[docs] add docs for ssim testing (#918)
1 parent 754292c commit c9ca6d1

File tree

4 files changed

+136
-3
lines changed

4 files changed

+136
-3
lines changed

.buildkite/scripts/pr_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ case "$TEST_TYPE" in
7575
;;
7676
"ssim")
7777
log "Running SSIM tests..."
78-
MODAL_COMMAND="$MODAL_ENV python3 -m modal run $MODAL_TEST_FILE::run_ssim_tests"
78+
MODAL_COMMAND="$MODAL_ENV HF_API_KEY=$HF_API_KEY python3 -m modal run $MODAL_TEST_FILE::run_ssim_tests"
7979
;;
8080
"training")
8181
log "Running training tests..."

docs/contributing/overview.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@ uv pip install ninja
7070
7171
python setup.py install
7272
```
73+
74+
## Testing
75+
76+
Please refer to the [Testing Guide](testing.md) for more information on how to add and run tests in FastVideo.

docs/contributing/testing.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Testing in FastVideo
2+
3+
This guide explains how to add and run tests in FastVideo. The testing suite is divided into several categories to ensure correctness across components, training workflows, and inference quality.
4+
5+
## Test Types
6+
7+
* **Unit Tests**: Located in `fastvideo/tests/dataset`, `fastvideo/tests/entrypoints`, and `fastvideo/tests/workflow`. These test individual functions and classes.
8+
* **Component Tests**: Located in `fastvideo/tests/encoders`, `fastvideo/tests/transformers`, and `fastvideo/tests/vaes`. These verify the loading and basic functionality of model components.
9+
* **SSIM Tests**: Located in `fastvideo/tests/ssim`. These are regression tests that compare generated videos against reference videos using the Structural Similarity Index Measure (SSIM) to detect quality degradation.
10+
* **Training Tests**: Located in `fastvideo/tests/training`. These validate training loops, loss calculations, and specific training techniques like LoRA, Distillation, and VSA.
11+
* **Inference Tests**: Located in `fastvideo/tests/inference`. These test specialized inference pipelines and optimizations (e.g., STA, V-MoBA).
12+
13+
For now, we will focus on **SSIM Tests**.
14+
15+
## SSIM Tests
16+
17+
SSIM tests are located in `fastvideo/tests/ssim`. These tests generate videos using specific models and parameters, and compare them against reference videos to ensure that changes in the codebase do not degrade generation quality or alter the output unexpectedly.
18+
19+
!!! note
20+
If you are adding an SSIM test, this serves as a safeguard. Any future code changes that break or cause errors with the specific arguments and configurations you defined will trigger a failure. Therefore, it is important to include multiple settings and arguments that cover the core features of your new pipeline to ensure robust regression testing.
21+
22+
### Directory Structure
23+
24+
```
25+
fastvideo/tests/ssim/
26+
├── <GPU>_reference_videos/ # Reference videos organized by GPU type (e.g., L40S_reference_videos)
27+
│ ├── <Model_Name>/
28+
│ │ ├── <Backend>/ # e.g., FLASH_ATTN, TORCH_SDPA
29+
│ │ │ └── <Video_File>
30+
├── test_causal_similarity.py
31+
├── test_inference_similarity.py
32+
├── update_reference_videos.sh
33+
└── ...
34+
```
35+
36+
### Adding a New SSIM Test
37+
38+
To add a new SSIM test, follow these steps:
39+
40+
1. **Create or Update a Test File**: You can add a new test function to an existing file (like `test_inference_similarity.py`) or create a new one if testing a distinct category of models.
41+
42+
2. **Define Model Parameters**: Define the configuration for the model you want to test. This includes model path, dimensions, inference steps, and other generation parameters. **Note:** Consider using lower `num_inference_steps` or reduced resolution (e.g., 480p instead of 720p) to keep test execution time reasonable, provided it doesn't compromise the test's ability to detect regression.
43+
44+
```python
45+
MY_MODEL_PARAMS = {
46+
"num_gpus": 1,
47+
"model_path": "organization/model-name",
48+
"height": 480,
49+
"width": 832,
50+
"num_frames": 45,
51+
"num_inference_steps": 20,
52+
# ... other parameters
53+
}
54+
```
55+
56+
3. **Implement the Test Function**:
57+
* Use `pytest.mark.parametrize` to run the test with different prompts, backends, and models.
58+
* Set the attention backend environment variable.
59+
* Initialize the `VideoGenerator`.
60+
* Generate the video.
61+
* Compare the generated video with the reference video using `compute_video_ssim_torchvision`.
62+
63+
Example structure:
64+
65+
```python
66+
@pytest.mark.parametrize("prompt", TEST_PROMPTS)
67+
@pytest.mark.parametrize("ATTENTION_BACKEND", ["FLASH_ATTN"])
68+
def test_my_model_similarity(prompt, ATTENTION_BACKEND):
69+
# Setup output directories
70+
# ...
71+
72+
# Initialize Generator
73+
generator = VideoGenerator.from_pretrained(...)
74+
generator.generate_video(prompt, ...)
75+
76+
# Compare with Reference
77+
ssim_values = compute_video_ssim_torchvision(reference_path, generated_path, use_ms_ssim=True)
78+
assert ssim_values[0] >= 0.98 # Threshold
79+
```
80+
81+
4. **Reference Videos**:
82+
* When running the test for the first time (or when updating the reference), the test will fail because the reference video is missing. The generated video will be saved in `fastvideo/tests/ssim/generated_videos`.
83+
* Inspect the generated video to ensure it meets quality expectations.
84+
* Move the generated video to the appropriate reference folder: `fastvideo/tests/ssim/<GPU>_reference_videos/<Model>/<Backend>/`.
85+
* You can use the helper script `update_reference_videos.sh` to automate copying videos from `generated_videos` to `L40S_reference_videos`. Note: Check the script to ensure paths match your environment (it defaults to `L40S_reference_videos`).
86+
87+
### Running Tests Locally
88+
89+
To run the SSIM tests locally:
90+
91+
```bash
92+
pytest fastvideo/tests/ssim/ -vs
93+
```
94+
95+
Ensure you have the necessary GPUs available as defined in your test parameters.
96+
97+
## Modal Workflow
98+
99+
FastVideo uses [Modal](https://modal.com/) for running tests in a CI environment. The workflow scripts are located in `fastvideo/tests/modal/`.
100+
101+
### `pr_test.py`
102+
103+
The main entry point for CI tests is `fastvideo/tests/modal/pr_test.py`. This script defines Modal functions that execute the pytest suites on specific hardware (e.g., L40S, H100).
104+
105+
### Updating Modal Configuration
106+
107+
If you add a new test that requires:
108+
* **Different GPU Hardware**: You may need to change the `@app.function(gpu=...)` decorator.
109+
* **Longer Execution Time**: Increase the `timeout` parameter.
110+
* **New Environment Variables/Secrets**: Add them to `secrets=[...]` or the image environment. For example, if your model is gated on Hugging Face, ensure `HF_API_KEY` is passed.
111+
112+
For SSIM tests, the `run_ssim_tests` function in `pr_test.py` currently runs:
113+
114+
```python
115+
@app.function(gpu="L40S:2", image=image, timeout=2700, secrets=[modal.Secret.from_dict({"HF_API_KEY": os.environ.get("HF_API_KEY", "")})])
116+
def run_ssim_tests():
117+
run_test("hf auth login --token $HF_API_KEY && pytest ./fastvideo/tests/ssim -vs")
118+
```
119+
120+
If your new test file is inside `fastvideo/tests/ssim`, it will automatically be picked up by this command. However, ensure that the `gpu="L40S:2"` configuration is sufficient for your model. If your model requires more GPUs (e.g., 4 or 8), you might need to create a separate Modal function or update the existing one.
121+
122+
### Workflow Scripts
123+
124+
The shell script that triggers these tests in the CI pipeline is located at `.buildkite/scripts/pr_test.sh`. If you add a new test category (e.g., a new folder outside of `ssim`), you will need to:
125+
1. Add a new function in `fastvideo/tests/modal/pr_test.py`.
126+
2. Add a new case in `.buildkite/scripts/pr_test.sh` to handle the new test type.
127+
128+
!!! note
129+
If you are a maintainer, you'll need to finally manually update the workflow script in Buildkite. Otherwise, a maintainer will help you update.

fastvideo/tests/modal/pr_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def run_vae_tests():
7474
def run_transformer_tests():
7575
run_test("hf auth login --token $HF_API_KEY && pytest ./fastvideo/tests/transformers -vs")
7676

77-
@app.function(gpu="L40S:2", image=image, timeout=2700)
77+
@app.function(gpu="L40S:2", image=image, timeout=2700, secrets=[modal.Secret.from_dict({"HF_API_KEY": os.environ.get("HF_API_KEY", "")})])
7878
def run_ssim_tests():
79-
run_test("pytest ./fastvideo/tests/ssim -vs")
79+
run_test("hf auth login --token $HF_API_KEY && pytest ./fastvideo/tests/ssim -vs")
8080

8181
@app.function(gpu="L40S:4", image=image, timeout=900, secrets=[modal.Secret.from_dict({"WANDB_API_KEY": os.environ.get("WANDB_API_KEY", "")})])
8282
def run_training_tests():

0 commit comments

Comments
 (0)