MCPcopy Create free account
hub / github.com/apple/axlearn / test_prune_tree

Method test_prune_tree

axlearn/common/utils_test.py:947–972  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

945 check_jax_type(kwargs={"key": "1"})
946 with self.assertRaisesRegex(ValueError, "^Argument key has leaf with non-JAX type"):
947 check_jax_type(pretty_named_args={"key": "1"})
948
949 def test_prune_tree(self):
950 in_tree = {
951 "a": {
952 "b": {"d": "test"},
953 "c": {
954 "b": None,
955 "e": VDict({"ee": 123}),
956 },
957 },
958 "f": 345,
959 }
960 # Prune by path.
961 result = prune_tree(in_tree, lambda k, _: "b" in k)
962 self.assertEqual({"a": {"c": {"e": VDict({"ee": 123})}}, "f": 345}, result)
963 # VDict should be preserved.
964 self.assertIsInstance(result["a"]["c"]["e"], VDict)
965 # Prune by path with prefix/separator.
966 self.assertEqual(
967 {"a": {"c": {"b": None, "e": {"ee": 123}}}, "f": 345},
968 prune_tree(in_tree, lambda k, _: k == "prefix:a:b", prefix="prefix", separator=":"),
969 )
970 # Prune by value.
971 self.assertEqual(
972 {"a": {"b": {"d": "test"}, "c": {"b": None, "e": VDict()}}},
973 prune_tree(in_tree, lambda _, v: isinstance(v, int)),
974 )
975

Callers

nothing calls this directly

Calls 2

VDictClass · 0.90
prune_treeFunction · 0.90

Tested by

no test coverage detected