Skip to content

Commit 909321d

Browse files
committed
add unit test
1 parent 59d63c7 commit 909321d

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

CHANGELOGS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Change Logs
44
0.7.11
55
++++++
66

7+
* :pr:`223`: adds task image-to-video
8+
* :pr:`220`: adds option --ort-logs to display onnxruntime logs when creating the session
79
* :pr:`220`: adds a patch for PR `#40791 <https://github.com/huggingface/transformers/pull/40791>`_ in transformers
810

911
0.7.10
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import unittest
2+
import torch
3+
import transformers
4+
from onnx_diagnostic.ext_test_case import (
5+
ExtTestCase,
6+
hide_stdout,
7+
requires_diffusers,
8+
requires_torch,
9+
)
10+
from onnx_diagnostic.torch_models.hghub.model_inputs import get_untrained_model_with_inputs
11+
from onnx_diagnostic.torch_export_patches import torch_export_patches
12+
from onnx_diagnostic.torch_export_patches.patch_inputs import use_dyn_not_str
13+
14+
15+
class TestTasksImageToVideo(ExtTestCase):
16+
@hide_stdout()
17+
@requires_diffusers("0.35")
18+
@requires_torch("2.8.99")
19+
def test_cosmos_predict(self):
20+
kwargs = {
21+
"_diffusers_version": "0.34.0.dev0",
22+
"_class_name": "CosmosTransformer3DModel",
23+
"max_size": [128, 240, 240],
24+
"text_embed_dim": 128,
25+
"use_cache": True,
26+
"in_channels": 3,
27+
"out_channels": 16,
28+
"num_layers": 2,
29+
"model_type": "dia",
30+
"patch_size": [1, 2, 2],
31+
"rope_scale": [1.0, 3.0, 3.0],
32+
"attention_head_dim": 16,
33+
"mlp_ratio": 0.4,
34+
"initializer_range": 0.02,
35+
"num_attention_heads": 16,
36+
"is_encoder_decoder": True,
37+
"adaln_lora_dim": 16,
38+
"concat_padding_mask": True,
39+
"extra_pos_embed_type": None,
40+
}
41+
config = transformers.DiaConfig(**kwargs)
42+
mid = "nvidia/Cosmos-Predict2-2B-Video2World"
43+
data = get_untrained_model_with_inputs(
44+
mid,
45+
verbose=1,
46+
add_second_input=True,
47+
subfolder="transformer",
48+
config=config,
49+
inputs_kwargs=dict(image_height=8 * 50, image_width=8 * 80),
50+
)
51+
self.assertEqual(data["task"], "image-to-video")
52+
model, inputs, ds = data["model"], data["inputs"], data["dynamic_shapes"]
53+
model(**inputs)
54+
model(**data["inputs2"])
55+
with torch.fx.experimental._config.patch(
56+
backed_size_oblivious=True
57+
), torch_export_patches(
58+
patch_transformers=True, patch_diffusers=True, verbose=10, stop_if_static=1
59+
):
60+
torch.export.export(
61+
model, (), kwargs=inputs, dynamic_shapes=use_dyn_not_str(ds), strict=False
62+
)
63+
64+
65+
if __name__ == "__main__":
66+
unittest.main(verbosity=2)

onnx_diagnostic/torch_models/hghub/model_inputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def get_untrained_model_with_inputs(
282282

283283
# This line is important. Some models may produce different
284284
# outputs even with the same inputs in training mode.
285-
model.eval()
285+
model.eval() # type: ignore[uion-attr]
286286
res = fct(model, config, add_second_input=add_second_input, **kwargs)
287287

288288
res["input_kwargs"] = kwargs

0 commit comments

Comments
 (0)