tf-models-nightly 2.18.0.dev20241029__py2.py3-none-any.whl → 2.19.0.dev20241031__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- official/modeling/hyperparams/base_config.py +18 -15
- official/modeling/hyperparams/base_config_test.py +20 -0
- {tf_models_nightly-2.18.0.dev20241029.dist-info → tf_models_nightly-2.19.0.dev20241031.dist-info}/METADATA +1 -1
- {tf_models_nightly-2.18.0.dev20241029.dist-info → tf_models_nightly-2.19.0.dev20241031.dist-info}/RECORD +8 -8
- {tf_models_nightly-2.18.0.dev20241029.dist-info → tf_models_nightly-2.19.0.dev20241031.dist-info}/AUTHORS +0 -0
- {tf_models_nightly-2.18.0.dev20241029.dist-info → tf_models_nightly-2.19.0.dev20241031.dist-info}/LICENSE +0 -0
- {tf_models_nightly-2.18.0.dev20241029.dist-info → tf_models_nightly-2.19.0.dev20241031.dist-info}/WHEEL +0 -0
- {tf_models_nightly-2.18.0.dev20241029.dist-info → tf_models_nightly-2.19.0.dev20241031.dist-info}/top_level.txt +0 -0
@@ -18,6 +18,7 @@ import copy
|
|
18
18
|
import dataclasses
|
19
19
|
import functools
|
20
20
|
import inspect
|
21
|
+
import types
|
21
22
|
import typing
|
22
23
|
from typing import Any, List, Mapping, Optional, Type, Union
|
23
24
|
|
@@ -58,8 +59,13 @@ def bind(config_cls):
|
|
58
59
|
|
59
60
|
|
60
61
|
def _is_optional(field):
|
61
|
-
|
62
|
-
|
62
|
+
# Two styles of annotating optional fields:
|
63
|
+
# Optional[T] -> typing.Union
|
64
|
+
# T | None -> types.UnionType
|
65
|
+
is_union = typing.get_origin(field) in (Union, types.UnionType)
|
66
|
+
# An optional field is a union of a type, and NoneType.
|
67
|
+
args = typing.get_args(field)
|
68
|
+
return is_union and len(args) == 2 and type(None) in args
|
63
69
|
|
64
70
|
|
65
71
|
@dataclasses.dataclass
|
@@ -189,6 +195,9 @@ class Config(params_dict.ParamsDict):
|
|
189
195
|
if not subconfig_type:
|
190
196
|
subconfig_type = Config
|
191
197
|
|
198
|
+
def _is_subtype(x, target) -> bool:
|
199
|
+
return isinstance(x, type) and issubclass(x, target)
|
200
|
+
|
192
201
|
annotations = cls._get_annotations()
|
193
202
|
if k in annotations:
|
194
203
|
# Directly Config subtype.
|
@@ -198,22 +207,16 @@ class Config(params_dict.ParamsDict):
|
|
198
207
|
traverse_in = True
|
199
208
|
while traverse_in:
|
200
209
|
i += 1
|
201
|
-
if (
|
202
|
-
issubclass(type_annotation, Config)):
|
210
|
+
if _is_subtype(type_annotation, Config):
|
203
211
|
subconfig_type = type_annotation
|
204
212
|
break
|
205
213
|
else:
|
206
|
-
#
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
element_type if issubclass(element_type, params_dict.ParamsDict)
|
213
|
-
else subconfig_type)
|
214
|
-
break
|
215
|
-
elif _is_optional(type_annotation):
|
216
|
-
# Strip the `Optional` annotation and process the subtype.
|
214
|
+
# If the field is a sequence of sub-config types or an Optional
|
215
|
+
# sub-config, then strip the container and process the sub-config.
|
216
|
+
is_sequence = _is_subtype(
|
217
|
+
typing.get_origin(type_annotation), cls.SEQUENCE_TYPES
|
218
|
+
)
|
219
|
+
if is_sequence or _is_optional(type_annotation):
|
217
220
|
type_annotation = typing.get_args(type_annotation)[0]
|
218
221
|
continue
|
219
222
|
traverse_in = False
|
@@ -61,6 +61,12 @@ class DumpConfig6(base_config.Config):
|
|
61
61
|
test_config1: Optional[DumpConfig1] = None
|
62
62
|
|
63
63
|
|
64
|
+
@dataclasses.dataclass
|
65
|
+
class ModernOptionalConfig(base_config.Config):
|
66
|
+
leaf: DumpConfig1 | None = None
|
67
|
+
leaves: tuple[DumpConfig1 | None, ...] = tuple()
|
68
|
+
|
69
|
+
|
64
70
|
class BaseConfigTest(parameterized.TestCase, tf.test.TestCase):
|
65
71
|
|
66
72
|
def assertHasSameTypes(self, c, d, msg=''):
|
@@ -422,6 +428,20 @@ class BaseConfigTest(parameterized.TestCase, tf.test.TestCase):
|
|
422
428
|
"DumpConfig6(test_config1=DumpConfig1(a=1, b='abc'))")
|
423
429
|
self.assertIsInstance(c.test_config1, DumpConfig1)
|
424
430
|
|
431
|
+
def test_modern_optional_syntax(self):
|
432
|
+
config = ModernOptionalConfig()
|
433
|
+
self.assertIsNone(config.leaf)
|
434
|
+
self.assertEqual(config.leaves, tuple())
|
435
|
+
|
436
|
+
replaced = config.replace(leaf={'a': 2}, leaves=({'a': 3}, {'b': 'foo'}))
|
437
|
+
self.assertEqual(replaced.leaf.a, 2)
|
438
|
+
self.assertEqual(replaced.leaf.b, 'text')
|
439
|
+
self.assertLen(replaced.leaves, 2)
|
440
|
+
self.assertEqual(replaced.leaves[0].a, 3)
|
441
|
+
self.assertEqual(replaced.leaves[0].b, 'text')
|
442
|
+
self.assertEqual(replaced.leaves[1].a, 1)
|
443
|
+
self.assertEqual(replaced.leaves[1].b, 'foo')
|
444
|
+
|
425
445
|
|
426
446
|
if __name__ == '__main__':
|
427
447
|
tf.test.main()
|
@@ -205,8 +205,8 @@ official/modeling/activations/sigmoid_test.py,sha256=BcG8HgPHcddhBHyqIO2xVvw1sBz
|
|
205
205
|
official/modeling/activations/swish.py,sha256=1T7WlQJ2plHk3JWyBiHz-BFgnkWcwudI_UU_hu6N9UQ,2301
|
206
206
|
official/modeling/activations/swish_test.py,sha256=7cfqupqDQ1_b0F7y7tlXKcqUP4tN7LBxgn8Hjzf4a18,1421
|
207
207
|
official/modeling/hyperparams/__init__.py,sha256=vs543Hge6bXJVYMNcsLBLSv-AvkqiC5FbRziP5gD3uA,846
|
208
|
-
official/modeling/hyperparams/base_config.py,sha256=
|
209
|
-
official/modeling/hyperparams/base_config_test.py,sha256=
|
208
|
+
official/modeling/hyperparams/base_config.py,sha256=mHwYaOj4hwyhlZSh2pxrdJf4-xg00lW-nF_t-LYCKH0,12582
|
209
|
+
official/modeling/hyperparams/base_config_test.py,sha256=eAg7tcnFDiMINA84LutiPGVqRRDpG4JGSc5mzn_MOxM,13350
|
210
210
|
official/modeling/hyperparams/oneof.py,sha256=_fRv3YICiAru-u5q2YT0QEGA1-t8LBsKGAwfN3jwbA0,1870
|
211
211
|
official/modeling/hyperparams/oneof_test.py,sha256=obwub_gkT4El0U5O58damISqVHKF-i5HBeyGA5ot74s,1991
|
212
212
|
official/modeling/hyperparams/params_dict.py,sha256=63fftQdUlycgJErxcyIj7655zL57isskkwLcUP41lfY,17810
|
@@ -1222,9 +1222,9 @@ tensorflow_models/tensorflow_models_test.py,sha256=nc6A9K53OGqF25xN5St8EiWvdVbda
|
|
1222
1222
|
tensorflow_models/nlp/__init__.py,sha256=4tA5Pf4qaFwT-fIFOpX7x7FHJpnyJT-5UgOeFYTyMlc,807
|
1223
1223
|
tensorflow_models/uplift/__init__.py,sha256=mqfa55gweOdpKoaQyid4A_4u7xw__FcQeSIF0k_pYmI,999
|
1224
1224
|
tensorflow_models/vision/__init__.py,sha256=zBorY_v5xva1uI-qxhZO3Qh-Dii-Suq6wEYh6hKHDfc,833
|
1225
|
-
tf_models_nightly-2.
|
1226
|
-
tf_models_nightly-2.
|
1227
|
-
tf_models_nightly-2.
|
1228
|
-
tf_models_nightly-2.
|
1229
|
-
tf_models_nightly-2.
|
1230
|
-
tf_models_nightly-2.
|
1225
|
+
tf_models_nightly-2.19.0.dev20241031.dist-info/AUTHORS,sha256=1dG3fXVu9jlo7bul8xuix5F5vOnczMk7_yWn4y70uw0,337
|
1226
|
+
tf_models_nightly-2.19.0.dev20241031.dist-info/LICENSE,sha256=WxeBS_DejPZQabxtfMOM_xn8qoZNJDQjrT7z2wG1I4U,11512
|
1227
|
+
tf_models_nightly-2.19.0.dev20241031.dist-info/METADATA,sha256=Q0QU9WWp1zzQQvaJs__iOZhOR-HImMDL9PyBpozbL-k,1432
|
1228
|
+
tf_models_nightly-2.19.0.dev20241031.dist-info/WHEEL,sha256=kGT74LWyRUZrL4VgLh6_g12IeVl_9u9ZVhadrgXZUEY,110
|
1229
|
+
tf_models_nightly-2.19.0.dev20241031.dist-info/top_level.txt,sha256=gum2FfO5R4cvjl2-QtP-S1aNmsvIZaFFT6VFzU0f4-g,33
|
1230
|
+
tf_models_nightly-2.19.0.dev20241031.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|