Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

hydra_resolvers_test.py 1.3 KB

You have to be logged in to leave a comment. Sign In
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
  1. import unittest
  2. from omegaconf import OmegaConf
  3. from super_gradients.common.environment.ddp_utils import register_hydra_resolvers
  4. class HydraResolversTest(unittest.TestCase):
  5. def setUp(self) -> None:
  6. register_hydra_resolvers()
  7. def test_add(self):
  8. conf = OmegaConf.create({"a": 1, "b": 2, "c": 3, "a_plus_b": "${add: ${a},${b}}", "a_plus_b_plus_c": "${add: ${a}, ${b}, ${c}}"})
  9. assert conf["a_plus_b"] == 3
  10. assert conf["a_plus_b_plus_c"] == 6
  11. def test_list(self):
  12. conf = OmegaConf.create(
  13. {
  14. "my_list": [10, 20, 30, 40, 50],
  15. "third_of_list": "${getitem: ${my_list}, 2}",
  16. "first_of_list": "${first: ${my_list}}",
  17. "last_of_list": "${last: ${my_list}}",
  18. }
  19. )
  20. self.assertEqual(conf["third_of_list"], 30)
  21. self.assertEqual(conf["first_of_list"], 10)
  22. self.assertEqual(conf["last_of_list"], 50)
  23. def test_cond(self):
  24. conf = OmegaConf.create(
  25. {
  26. "boolean": True,
  27. "a": "red_pill",
  28. "b": "blue_pill",
  29. "result": "${cond:${boolean}, ${a}, ${b}}",
  30. }
  31. )
  32. assert conf["result"] == "red_pill"
  33. conf["boolean"] = False
  34. assert conf["result"] == "blue_pill"
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...