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

test_headless.py 3.4 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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  1. from .utils import runner
  2. import os
  3. import sh
  4. import glob
  5. import json
  6. import time
  7. import signal
  8. train_py = open(os.path.join(os.path.dirname(
  9. __file__), "fixtures/train.py")).read()
  10. def test_dry_run(runner):
  11. with runner.isolated_filesystem():
  12. with open("train.py", "w") as f:
  13. f.write(train_py)
  14. os.environ["WANDB_MODE"] = "dryrun"
  15. os.environ["WANDB_TEST"] = "true"
  16. try:
  17. res = sh.python("train.py")
  18. print("RUN", res)
  19. run_dir = glob.glob("wandb/dry*")[0]
  20. meta = json.loads(open(run_dir + "/wandb-metadata.json").read())
  21. assert meta["state"] == "finished"
  22. assert meta["program"] == "train.py"
  23. assert meta["exitcode"] == 0
  24. assert os.path.exists(run_dir + "/output.log")
  25. assert "loss:" in open(run_dir + "/output.log").read()
  26. assert os.path.exists(run_dir + "/wandb-history.jsonl")
  27. assert os.path.exists(run_dir + "/wandb-events.jsonl")
  28. assert os.path.exists(run_dir + "/wandb-summary.json")
  29. finally:
  30. del os.environ["WANDB_MODE"]
  31. del os.environ["WANDB_TEST"]
  32. def test_dry_run_custom_dir(runner):
  33. with runner.isolated_filesystem():
  34. os.environ["WANDB_DIR"] = "/tmp"
  35. os.environ["WANDB_MODE"] = "dryrun"
  36. os.environ["WANDB_TEST"] = "true"
  37. try:
  38. with open("train.py", "w") as f:
  39. f.write(train_py)
  40. res = sh.python("train.py")
  41. print(res)
  42. run_dir = glob.glob("/tmp/wandb/dry*")[0]
  43. assert os.path.exists(run_dir + "/output.log")
  44. finally: # avoid stepping on other tests, even if this one fails
  45. del os.environ["WANDB_DIR"]
  46. del os.environ["WANDB_MODE"]
  47. del os.environ["WANDB_TEST"]
  48. # TODO: this isn't working
  49. sh.rm("-rf", "/tmp/wandb")
  50. def test_dry_run_exc(runner):
  51. with runner.isolated_filesystem():
  52. with open("train.py", "w") as f:
  53. f.write(train_py.replace("#raise", "raise"))
  54. os.environ["WANDB_MODE"] = "dryrun"
  55. os.environ["WANDB_TEST"] = "true"
  56. try:
  57. try:
  58. res = sh.python("train.py")
  59. except sh.ErrorReturnCode as e:
  60. res = e.stdout
  61. print(res)
  62. run_dir = glob.glob("wandb/dry*")[0]
  63. meta = json.loads(open(run_dir + "/wandb-metadata.json").read())
  64. assert meta["state"] == "failed"
  65. assert meta["exitcode"] == 1
  66. finally:
  67. del os.environ["WANDB_MODE"]
  68. del os.environ["WANDB_TEST"]
  69. def test_dry_run_kill(runner):
  70. with runner.isolated_filesystem():
  71. with open("train.py", "w") as f:
  72. f.write(train_py.replace("#os.kill", "os.kill"))
  73. os.environ["WANDB_MODE"] = "dryrun"
  74. os.environ["WANDB_TEST"] = "true"
  75. try:
  76. res = sh.python("train.py", _bg=True)
  77. try:
  78. res.wait()
  79. print(res)
  80. except sh.ErrorReturnCode:
  81. pass
  82. dirs = glob.glob("wandb/dry*")
  83. print(dirs)
  84. run_dir = dirs[0]
  85. meta = json.loads(open(run_dir + "/wandb-metadata.json").read())
  86. assert meta["state"] == "killed"
  87. assert meta["exitcode"] == 255
  88. finally:
  89. del os.environ["WANDB_MODE"]
  90. del os.environ["WANDB_TEST"]
  91. # TODO: test server communication
Tip!

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

Comments

Loading...