kryo 0.2.0__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.
kryo/__init__.py ADDED
@@ -0,0 +1,69 @@
1
+ """Kryo Python SDK for checkpoint signaling.
2
+
3
+ Usage:
4
+ import kryo
5
+
6
+ model = load_model()
7
+ model.to("cuda")
8
+ kryo.checkpoint() # Freeze here
9
+
10
+ result = model(input) # Runs after restore
11
+ """
12
+
13
+ import os
14
+ import signal
15
+ import time
16
+ from importlib.metadata import version
17
+
18
+ __version__ = version("kryo")
19
+ __all__ = ["checkpoint"]
20
+
21
+ _checkpointed = False
22
+ _CLI_PID_ENV = "KRYO_CLI_PID"
23
+
24
+
25
+ def checkpoint() -> None:
26
+ """Mark the checkpoint location and wait for restore.
27
+
28
+ Call this after setup is complete. The process will:
29
+ 1. Send SIGUSR1 to the kryo CLI to signal "ready"
30
+ 2. Block until SIGUSR2 is received (after restore)
31
+ 3. Continue execution
32
+
33
+ This function is idempotent - subsequent calls are no-ops.
34
+ """
35
+ global _checkpointed
36
+ if _checkpointed:
37
+ return
38
+
39
+ # Older Kryo CLI versions do not provide KRYO_CLI_PID. Falling back to the
40
+ # parent preserves direct-launch compatibility; wrapper support requires
41
+ # the new CLI protocol.
42
+ cli_pid_value = os.environ.get(_CLI_PID_ENV, str(os.getppid()))
43
+
44
+ try:
45
+ cli_pid = int(cli_pid_value)
46
+ except ValueError as error:
47
+ raise RuntimeError(f"invalid {_CLI_PID_ENV}: {cli_pid_value!r}") from error
48
+
49
+ if cli_pid <= 0:
50
+ raise RuntimeError(f"invalid {_CLI_PID_ENV}: {cli_pid_value!r}")
51
+
52
+ restored = False
53
+
54
+ def wake(*_: object) -> None:
55
+ nonlocal restored
56
+ restored = True
57
+
58
+ # Install a process-wide disposition before notifying the CLI. The flag
59
+ # remembers an early wake-up without taking a lock in the handler.
60
+ previous_handler = signal.signal(signal.SIGUSR2, wake)
61
+ try:
62
+ os.kill(cli_pid, signal.SIGUSR1)
63
+ _checkpointed = True
64
+ # Poll so the main thread regularly runs pending Python signal
65
+ # handlers even if SIGUSR2 was delivered to another thread.
66
+ while not restored:
67
+ time.sleep(0.1)
68
+ finally:
69
+ signal.signal(signal.SIGUSR2, previous_handler)
kryo/py.typed ADDED
File without changes
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: kryo
3
+ Version: 0.2.0
4
+ Summary: Sub-second cold starts for GPU inference
5
+ Project-URL: Homepage, https://github.com/akhileshsharma99/kryo
6
+ Project-URL: Repository, https://github.com/akhileshsharma99/kryo
7
+ Project-URL: Issues, https://github.com/akhileshsharma99/kryo/issues
8
+ Project-URL: Changelog, https://github.com/akhileshsharma99/kryo/blob/main/CHANGELOG.md
9
+ Author-email: Akhilesh Sharma <sharmaninenine@gmail.com>
10
+ License-Expression: MIT
11
+ Keywords: checkpoint,cold-start,criu,gpu,inference
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+
25
+ # Kryo Python SDK
26
+
27
+ Python helper for [Kryo](https://github.com/akhileshsharma99/kryo) checkpoint signaling.
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ pip install kryo
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ```python
38
+ import kryo
39
+
40
+ # Setup (runs once, gets checkpointed)
41
+ model = load_model()
42
+ model.to("cuda")
43
+
44
+ kryo.checkpoint() # Freeze here
45
+
46
+ # Inference (runs after restore)
47
+ result = model(input)
48
+ ```
49
+
50
+ Then use the Kryo CLI:
51
+
52
+ ```bash
53
+ # Create snapshot
54
+ kryo snapshot create --name mymodel -- python app.py
55
+
56
+ # Restore and run
57
+ kryo run --snapshot mymodel
58
+ ```
59
+
60
+ ## Requirements
61
+
62
+ - Linux (CRIU is Linux-only)
63
+ - Kryo CLI installed
64
+ - NVIDIA driver 550+ (for GPU checkpointing)
@@ -0,0 +1,5 @@
1
+ kryo/__init__.py,sha256=wMJw5u374L7Xfk7hzUfYvIoWFyira8wVeZuCOtIO1_s,1972
2
+ kryo/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ kryo-0.2.0.dist-info/METADATA,sha256=V6To28UTFbmZJqnMRMWUtY4z0wnxlZazLOY8jtoWfZ8,1717
4
+ kryo-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ kryo-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any