-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudios.py
More file actions
executable file
·69 lines (53 loc) · 2.26 KB
/
Copy pathstudios.py
File metadata and controls
executable file
·69 lines (53 loc) · 2.26 KB
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
#!/usr/bin/env python3
"""Executable SDK examples for Lightning Studios."""
from __future__ import annotations
import argparse
from lightning_sdk import Machine, Studio, Teamspace
def _parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--teamspace", required=True, help="Teamspace name without owner.")
parser.add_argument("--org", help="Organization that owns the teamspace.")
parser.add_argument("--user", help="User that owns the teamspace.")
parser.add_argument("--studio", default="sdk-tutorial-studio", help="Studio name.")
parser.add_argument("--machine", default="CPU", help="Machine type.")
parser.add_argument("--train-file", default="train.py", help="Local file to upload and run.")
parser.add_argument("--run-tests", action="store_true", help="Run pytest and check the exit code.")
parser.add_argument("--detach-training", action="store_true", help="Start a longer training command.")
return parser
def main() -> None:
args = _parser().parse_args()
# sdk-studio-workflow-start
teamspace = Teamspace(args.teamspace, org=args.org, user=args.user)
studio = Studio(
name=args.studio,
teamspace=teamspace,
create_ok=True,
)
studio.start(machine=Machine.from_str(args.machine))
print(f"{studio.name} is {studio.status} on {studio.machine}")
output = studio.run("python --version")
print(output)
studio.upload_file(args.train_file, remote_path="train.py")
train_output = studio.run("python train.py --epochs 1")
print(train_output)
# sdk-studio-workflow-end
# sdk-studio-exit-code-start
if args.run_tests:
output, exit_code = studio.run_with_exit_code("python -m pytest -q")
print(output)
if exit_code != 0:
raise RuntimeError(f"Tests failed with exit code {exit_code}")
# sdk-studio-exit-code-end
# sdk-studio-detach-start
if args.detach_training:
output, exit_code = studio.run_and_detach(
"python train.py --epochs 10",
timeout=30,
check_interval=5,
)
print(output)
print(f"Initial exit code: {exit_code}")
# sdk-studio-detach-end
studio.stop()
if __name__ == "__main__":
main()