model-runtime 0.5.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.
- model_runtime-0.5.0.dist-info/METADATA +618 -0
- model_runtime-0.5.0.dist-info/RECORD +36 -0
- model_runtime-0.5.0.dist-info/WHEEL +4 -0
- model_runtime-0.5.0.dist-info/entry_points.txt +2 -0
- model_runtime-0.5.0.dist-info/licenses/LICENSE +202 -0
- model_runtime-0.5.0.dist-info/licenses/NOTICE +6 -0
- saturn/__init__.py +28 -0
- saturn/adapters/__init__.py +63 -0
- saturn/adapters/_residency.py +196 -0
- saturn/adapters/decoder.py +1679 -0
- saturn/adapters/diffusion.py +438 -0
- saturn/adapters/flux1.py +661 -0
- saturn/adapters/flux2.py +630 -0
- saturn/adapters/mamba.py +620 -0
- saturn/adapters/qwen.py +637 -0
- saturn/causal.py +260 -0
- saturn/cli.py +382 -0
- saturn/contracts.py +175 -0
- saturn/core.py +1979 -0
- saturn/dependencies.py +61 -0
- saturn/interop/__init__.py +37 -0
- saturn/interop/circuit_tracer.py +1198 -0
- saturn/investigation.py +109 -0
- saturn/numerics.py +213 -0
- saturn/observers.py +289 -0
- saturn/paths.py +324 -0
- saturn/program.py +364 -0
- saturn/route.py +774 -0
- saturn/shared_store.py +257 -0
- saturn/store.py +835 -0
- saturn/symbols.py +398 -0
- saturn/training/__init__.py +61 -0
- saturn/training/_checkpoint.py +1618 -0
- saturn/trial.py +514 -0
- saturn/values.py +223 -0
- saturn/writers.py +82 -0
saturn/contracts.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""Framework-neutral execution positions, ports, and continuation contracts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from types import MappingProxyType
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from .values import canonical, clone, digest
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class ExecutionPoint:
|
|
15
|
+
family: str
|
|
16
|
+
logical_step: int
|
|
17
|
+
phase: str
|
|
18
|
+
operator: str = ""
|
|
19
|
+
index: int | None = None
|
|
20
|
+
edge: str = "before"
|
|
21
|
+
next_operation: str = ""
|
|
22
|
+
local_clock: int | None = None
|
|
23
|
+
|
|
24
|
+
def __post_init__(self):
|
|
25
|
+
if not self.family or not self.phase or self.edge not in {"before", "after"}:
|
|
26
|
+
raise ValueError("execution point requires family, phase and before/after edge")
|
|
27
|
+
for value in (self.logical_step, self.index, self.local_clock):
|
|
28
|
+
if value is not None and (type(value) is not int or value < 0):
|
|
29
|
+
raise ValueError("execution clocks and indices must be nonnegative integers")
|
|
30
|
+
|
|
31
|
+
def to_dict(self) -> dict[str, Any]:
|
|
32
|
+
return dict(vars(self))
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def fingerprint(self) -> str:
|
|
36
|
+
return digest(self.to_dict())
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class SlotSpec:
|
|
41
|
+
name: str
|
|
42
|
+
role: str = "carrier"
|
|
43
|
+
writable: bool = False
|
|
44
|
+
persistence: str = "authoritative"
|
|
45
|
+
producer: str = ""
|
|
46
|
+
consumer: str = ""
|
|
47
|
+
invalidates: tuple[str, ...] = ()
|
|
48
|
+
schema: Mapping[str, Any] = field(default_factory=dict)
|
|
49
|
+
|
|
50
|
+
def __post_init__(self):
|
|
51
|
+
if not self.name or self.persistence not in {"authoritative", "derived", "evidence"}:
|
|
52
|
+
raise ValueError("slot requires a name and declared persistence policy")
|
|
53
|
+
if len(set(self.invalidates)) != len(self.invalidates):
|
|
54
|
+
raise ValueError("duplicate slot invalidation")
|
|
55
|
+
canonical(dict(self.schema))
|
|
56
|
+
object.__setattr__(self, "schema", MappingProxyType(clone(dict(self.schema))))
|
|
57
|
+
|
|
58
|
+
def to_dict(self) -> dict[str, Any]:
|
|
59
|
+
return {
|
|
60
|
+
"name": self.name,
|
|
61
|
+
"role": self.role,
|
|
62
|
+
"writable": self.writable,
|
|
63
|
+
"persistence": self.persistence,
|
|
64
|
+
"producer": self.producer,
|
|
65
|
+
"consumer": self.consumer,
|
|
66
|
+
"invalidates": list(self.invalidates),
|
|
67
|
+
"schema": dict(self.schema),
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass(frozen=True)
|
|
72
|
+
class SurfaceManifest:
|
|
73
|
+
slots: tuple[SlotSpec, ...]
|
|
74
|
+
state_schema: str
|
|
75
|
+
consumer: str
|
|
76
|
+
horizon: str = "native-suffix"
|
|
77
|
+
|
|
78
|
+
def __post_init__(self):
|
|
79
|
+
names = [slot.name for slot in self.slots]
|
|
80
|
+
if not self.state_schema or not self.consumer or len(set(names)) != len(names):
|
|
81
|
+
raise ValueError("surface requires schema, consumer, and unique slots")
|
|
82
|
+
|
|
83
|
+
def to_dict(self) -> dict[str, Any]:
|
|
84
|
+
return {
|
|
85
|
+
"schema": "saturn-pub-surface-v1",
|
|
86
|
+
"state_schema": self.state_schema,
|
|
87
|
+
"consumer": self.consumer,
|
|
88
|
+
"horizon": self.horizon,
|
|
89
|
+
"slots": [slot.to_dict() for slot in self.slots],
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
def slot(self, name: str) -> SlotSpec:
|
|
93
|
+
for slot in self.slots:
|
|
94
|
+
if slot.name == name:
|
|
95
|
+
return slot
|
|
96
|
+
raise ValueError(f"undeclared state port: {name}")
|
|
97
|
+
|
|
98
|
+
def validate(self, state: Mapping[str, Any]) -> None:
|
|
99
|
+
if set(state) != {slot.name for slot in self.slots}:
|
|
100
|
+
raise ValueError("state does not match its declared closure")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@dataclass(frozen=True)
|
|
104
|
+
class TransitionSpec:
|
|
105
|
+
"""Adapter-declared native footprint, never an executable second graph."""
|
|
106
|
+
|
|
107
|
+
operation: str
|
|
108
|
+
reads: tuple[str, ...] = ()
|
|
109
|
+
writes: tuple[str, ...] = ()
|
|
110
|
+
invalidates: tuple[str, ...] = ()
|
|
111
|
+
consumer: str = "native-suffix"
|
|
112
|
+
footprint: str = "unknown"
|
|
113
|
+
|
|
114
|
+
def __post_init__(self):
|
|
115
|
+
if not self.operation or self.footprint not in {"unknown", "declared"}:
|
|
116
|
+
raise ValueError("transition requires an operation and footprint status")
|
|
117
|
+
for name in ("reads", "writes", "invalidates"):
|
|
118
|
+
object.__setattr__(self, name, tuple(getattr(self, name)))
|
|
119
|
+
for group in (self.reads, self.writes, self.invalidates):
|
|
120
|
+
if len(set(group)) != len(group) or any(not name for name in group):
|
|
121
|
+
raise ValueError("transition slots must be unique nonempty names")
|
|
122
|
+
|
|
123
|
+
def to_dict(self) -> dict[str, Any]:
|
|
124
|
+
return {
|
|
125
|
+
"operation": self.operation,
|
|
126
|
+
"reads": list(self.reads),
|
|
127
|
+
"writes": list(self.writes),
|
|
128
|
+
"invalidates": list(self.invalidates),
|
|
129
|
+
"consumer": self.consumer,
|
|
130
|
+
"footprint": self.footprint,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@dataclass(frozen=True)
|
|
135
|
+
class StateAddress:
|
|
136
|
+
"""A context-bound port and optional integer tensor/list coordinates."""
|
|
137
|
+
|
|
138
|
+
slot: str
|
|
139
|
+
selector: tuple[int, ...] = ()
|
|
140
|
+
role: str = ""
|
|
141
|
+
execution_point: str | None = None
|
|
142
|
+
state_schema: str | None = None
|
|
143
|
+
|
|
144
|
+
def __post_init__(self):
|
|
145
|
+
object.__setattr__(self, "selector", tuple(self.selector))
|
|
146
|
+
if not self.slot or any(type(index) is not int for index in self.selector):
|
|
147
|
+
raise ValueError("address requires a slot and integer selector")
|
|
148
|
+
|
|
149
|
+
def to_dict(self) -> dict[str, Any]:
|
|
150
|
+
return {
|
|
151
|
+
"slot": self.slot,
|
|
152
|
+
"selector": list(self.selector),
|
|
153
|
+
"role": self.role,
|
|
154
|
+
"execution_point": self.execution_point,
|
|
155
|
+
"state_schema": self.state_schema,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
@dataclass(frozen=True)
|
|
160
|
+
class NumericalContract:
|
|
161
|
+
mode: str = "same-program-exact"
|
|
162
|
+
program: str = "adapter-declared"
|
|
163
|
+
comparator: str = "typed-content-digest"
|
|
164
|
+
rtol: float = 0.0
|
|
165
|
+
atol: float = 0.0
|
|
166
|
+
|
|
167
|
+
def __post_init__(self):
|
|
168
|
+
if self.mode not in {"same-program-exact", "bounded-numeric", "behavior-observed"}:
|
|
169
|
+
raise ValueError("unknown numerical authority")
|
|
170
|
+
if self.rtol < 0 or self.atol < 0:
|
|
171
|
+
raise ValueError("numerical tolerances must be nonnegative")
|
|
172
|
+
canonical(self.to_dict())
|
|
173
|
+
|
|
174
|
+
def to_dict(self) -> dict[str, Any]:
|
|
175
|
+
return dict(vars(self))
|