|
1 | 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | +"""Smoke, registry, preset, and stage-contract tests for Cosmos Predict pipeline.""" |
| 3 | + |
| 4 | +import json |
| 5 | +from pathlib import Path |
2 | 6 | import pytest |
3 | 7 | import torch |
4 | 8 | from unittest.mock import MagicMock |
5 | 9 |
|
6 | | -from fastvideo.api.sampling_param import SamplingParam |
7 | | -from fastvideo.fastvideo_args import FastVideoArgs |
8 | | -from fastvideo.registry import get_model_family, get_default_preset |
| 10 | +from fastvideo.api.presets import get_preset |
| 11 | +from fastvideo.configs.pipelines.cosmos_predict import CosmosPredictConfig, CosmosPredict14BConfig |
| 12 | +from fastvideo.fastvideo_args import FastVideoArgs, WorkloadType |
| 13 | +from fastvideo.registry import get_model_info, get_preset_selection |
9 | 14 | from fastvideo.pipelines.pipeline_batch_info import ForwardBatch |
10 | 15 | from fastvideo.pipelines.basic.cosmos_predict.pipeline_cosmos_predict import ( |
11 | 16 | CosmosPredictPipeline, |
12 | 17 | CosmosPredictLatentPreparationStage, |
| 18 | + EntryClass, |
13 | 19 | ) |
14 | 20 |
|
15 | 21 |
|
16 | | -def test_cosmos_predict_registry_and_preset_resolution(): |
17 | | - """Verify that presets are properly registered and resolvable via SamplingParam.""" |
18 | | - # 7B model check |
19 | | - param_7b = SamplingParam.from_pretrained("nvidia/Cosmos-1.0-Prompt2World-7B-Video") |
20 | | - assert param_7b.height == 704 |
21 | | - assert param_7b.width == 1280 |
22 | | - assert param_7b.num_frames == 93 |
23 | | - assert param_7b.num_inference_steps == 35 |
24 | | - assert get_model_family("nvidia/Cosmos-1.0-Prompt2World-7B-Video") == "cosmos_predict" |
25 | | - assert get_default_preset("nvidia/Cosmos-1.0-Prompt2World-7B-Video") == "cosmos_predict_preset" |
| 22 | +def test_cosmos_predict_registry_and_preset_resolution(tmp_path: Path): |
| 23 | + """Verify exact class resolution, required modules, configs, and official preset defaults.""" |
| 24 | + assert EntryClass is CosmosPredictPipeline |
| 25 | + assert CosmosPredictPipeline._required_config_modules == [ |
| 26 | + "text_encoder", "tokenizer", "vae", "transformer", "scheduler" |
| 27 | + ] |
| 28 | + |
| 29 | + # 7B model preset check |
| 30 | + preset_name_7b, family_7b = get_preset_selection("nvidia/Cosmos-1.0-Prompt2World-7B-Video") |
| 31 | + assert (preset_name_7b, family_7b) == ("cosmos_predict_preset", "cosmos_predict") |
| 32 | + preset_7b = get_preset(preset_name_7b, family_7b) |
| 33 | + assert preset_7b.defaults["height"] == 704 |
| 34 | + assert preset_7b.defaults["width"] == 1280 |
| 35 | + assert preset_7b.defaults["num_frames"] == 93 |
| 36 | + assert preset_7b.defaults["fps"] == 24 |
| 37 | + assert preset_7b.defaults["guidance_scale"] == 7.0 |
| 38 | + assert preset_7b.defaults["num_inference_steps"] == 35 |
| 39 | + |
| 40 | + # 14B model preset check |
| 41 | + preset_name_14b, family_14b = get_preset_selection("nvidia/Cosmos-1.0-Prompt2World-14B-Video") |
| 42 | + assert (preset_name_14b, family_14b) == ("cosmos_predict_14b_preset", "cosmos_predict") |
| 43 | + preset_14b = get_preset(preset_name_14b, family_14b) |
| 44 | + assert preset_14b.defaults["num_frames"] == 93 |
| 45 | + |
| 46 | + # Local layout model info resolution check |
| 47 | + model_dir = tmp_path / "Cosmos-1.0-Prompt2World-7B-Video" |
| 48 | + model_dir.mkdir() |
| 49 | + model_index = { |
| 50 | + "_class_name": "CosmosPredictPipeline", |
| 51 | + "_diffusers_version": "0.32.0", |
| 52 | + "scheduler": ["diffusers", "EDMEulerScheduler"], |
| 53 | + "text_encoder": ["transformers", "Qwen2_5_VLForConditionalGeneration"], |
| 54 | + "tokenizer": ["transformers", "AutoTokenizer"], |
| 55 | + "transformer": ["diffusers", "CosmosTransformer3DModel"], |
| 56 | + "vae": ["diffusers", "AutoencoderKLCosmos"], |
| 57 | + } |
| 58 | + for component in CosmosPredictPipeline._required_config_modules: |
| 59 | + (model_dir / component).mkdir() |
| 60 | + (model_dir / "model_index.json").write_text(json.dumps(model_index), encoding="utf-8") |
26 | 61 |
|
27 | | - # 14B model check |
28 | | - param_14b = SamplingParam.from_pretrained("nvidia/Cosmos-1.0-Prompt2World-14B-Video") |
29 | | - assert param_14b.height == 704 |
30 | | - assert param_14b.width == 1280 |
31 | | - assert param_14b.num_frames == 93 |
32 | | - assert get_model_family("nvidia/Cosmos-1.0-Prompt2World-14B-Video") == "cosmos_predict" |
33 | | - assert get_default_preset("nvidia/Cosmos-1.0-Prompt2World-14B-Video") == "cosmos_predict_14b_preset" |
| 62 | + info_7b = get_model_info(str(model_dir), workload_type=WorkloadType.T2V) |
| 63 | + assert info_7b.pipeline_cls is CosmosPredictPipeline |
| 64 | + assert info_7b.pipeline_config_cls is CosmosPredictConfig |
34 | 65 |
|
35 | 66 |
|
36 | 67 | def test_cosmos_predict_latent_preparation_temporal_downsampling(): |
|
0 commit comments