File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
10
10
### Added
11
11
12
+ - Add ` assert_tensor_spec_with_default ` for input signature testing
12
13
- Add support for loading SafeTensors checkpoints
13
14
- #v1 Add ` is_orbax_checkpoint() ` method for validation checks
14
15
Original file line number Diff line number Diff line change @@ -89,6 +89,16 @@ def __post_init__(self):
89
89
]
90
90
91
91
92
+ def assert_tensor_spec_with_default (
93
+ input_signature : PyTree ,
94
+ ) -> PyTree :
95
+ """Asserts that the input signature is a TensorSpecWithDefault."""
96
+ def check_fn (x ):
97
+ assert isinstance (x , TensorSpecWithDefault ), f'x: { x } '
98
+ return x
99
+ return jax .tree_util .tree_map (check_fn , input_signature )
100
+
101
+
92
102
def remove_signature_defaults (input_signature : PyTree ) -> PyTree :
93
103
"""Removes TensorSpecWithDefault from an input_signature."""
94
104
Original file line number Diff line number Diff line change @@ -65,6 +65,24 @@ def test_missing_default(self):
65
65
):
66
66
utils .with_default_args (lambda x : x [0 ] + x [1 ], input_signature )
67
67
68
+ def test_assert_tensor_spec_with_default (self ):
69
+ input_signature = [
70
+ TensorSpecWithDefault (
71
+ tf .TensorSpec ([None ], tf .int32 ),
72
+ np .asarray ([1 , 2 ]),
73
+ )
74
+ ]
75
+ utils .assert_tensor_spec_with_default (input_signature )
76
+
77
+ input_signature_bad_type = [
78
+ tf .TensorSpec ([None ], tf .int32 ),
79
+ ]
80
+ with self .assertRaisesRegex (
81
+ AssertionError ,
82
+ 'x: TensorSpec' ,
83
+ ):
84
+ utils .assert_tensor_spec_with_default (input_signature_bad_type )
85
+
68
86
def test_with_default_args_nested (self ):
69
87
def f (required_arg , optional_args ):
70
88
return (
You can’t perform that action at this time.
0 commit comments