-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_render_pytorch_renderer.py
More file actions
67 lines (55 loc) · 1.75 KB
/
Copy pathtest_render_pytorch_renderer.py
File metadata and controls
67 lines (55 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Focused tests for the PyTorch render backend."""
from __future__ import annotations
import py_compile
from typing import Any
def _small_gnn_spec() -> dict:
return {
"modelName": "pytorch_smoke",
"model_parameters": {
"num_hidden_states": 2,
"num_obs": 2,
"num_timesteps": 7,
},
"initialparameterization": {
"A": [[0.9, 0.1], [0.1, 0.9]],
"B": [
[[0.9, 0.2], [0.1, 0.8]],
[[0.8, 0.1], [0.2, 0.9]],
],
"C": [0.0, 1.0],
"D": [0.5, 0.5],
},
}
def test_pytorch_renderer_generates_compilable_script_with_timestep(
tmp_path: Any,
) -> None:
from render.pytorch.pytorch_renderer import render_gnn_to_pytorch
output_path = tmp_path / "pytorch_smoke.py"
success, message, artifacts = render_gnn_to_pytorch(_small_gnn_spec(), output_path)
assert success, message
assert artifacts == [str(output_path)]
generated = output_path.read_text(encoding="utf-8")
assert "T = 7" in generated
py_compile.compile(str(output_path), doraise=True)
def test_render_success_policy_can_be_strict_about_framework_failures() -> None:
from render.processor import _render_succeeded
assert (
_render_succeeded(
success_count=1,
total_files=1,
total_framework_successes=1,
total_framework_attempts=2,
strict_framework_success=False,
)
is True
)
assert (
_render_succeeded(
success_count=1,
total_files=1,
total_framework_successes=1,
total_framework_attempts=2,
strict_framework_success=True,
)
is False
)