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/dependencies.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Exact dirty closure and local memoization for declared acyclic dependencies."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable, Mapping
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from .values import clone, describe, digest
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class Cell:
|
|
14
|
+
name: str
|
|
15
|
+
reads: tuple[str, ...]
|
|
16
|
+
implementation: Callable[[Mapping[str, Any]], Any]
|
|
17
|
+
version: str
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class DependencyGraph:
|
|
21
|
+
"""Topological cells; feedback is represented by a new trajectory step.
|
|
22
|
+
|
|
23
|
+
The cache is instance-local and version-bound. The native consumer always runs.
|
|
24
|
+
This is a transparent reference partial evaluator, not a universal neural compiler.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, cells: tuple[Cell, ...]):
|
|
28
|
+
names = [cell.name for cell in cells]
|
|
29
|
+
if len(set(names)) != len(names):
|
|
30
|
+
raise ValueError("cell names must be unique")
|
|
31
|
+
for index, cell in enumerate(cells):
|
|
32
|
+
if not cell.version or any(x in names[index:] for x in cell.reads):
|
|
33
|
+
raise ValueError("cells must be versioned and topologically ordered")
|
|
34
|
+
self.cells = cells
|
|
35
|
+
self._cache: dict[str, Any] = {}
|
|
36
|
+
|
|
37
|
+
def dirty(self, changed: set[str]) -> set[str]:
|
|
38
|
+
dirty = set(changed)
|
|
39
|
+
for cell in self.cells:
|
|
40
|
+
if dirty.intersection(cell.reads):
|
|
41
|
+
dirty.add(cell.name)
|
|
42
|
+
return dirty
|
|
43
|
+
|
|
44
|
+
def run(
|
|
45
|
+
self, inputs: Mapping[str, Any], consumer: Callable[[Mapping[str, Any]], Any]
|
|
46
|
+
) -> tuple[Any, dict[str, Any]]:
|
|
47
|
+
if set(inputs).intersection(cell.name for cell in self.cells):
|
|
48
|
+
raise ValueError("inputs cannot shadow computed cells")
|
|
49
|
+
values = clone(dict(inputs))
|
|
50
|
+
reused, executed = [], []
|
|
51
|
+
for cell in self.cells:
|
|
52
|
+
reads = {name: clone(values[name]) for name in cell.reads}
|
|
53
|
+
key = digest({"name": cell.name, "version": cell.version, "reads": describe(reads)})
|
|
54
|
+
if key in self._cache:
|
|
55
|
+
reused.append(cell.name)
|
|
56
|
+
else:
|
|
57
|
+
self._cache[key] = clone(cell.implementation(reads))
|
|
58
|
+
executed.append(cell.name)
|
|
59
|
+
values[cell.name] = clone(self._cache[key])
|
|
60
|
+
output = consumer(clone(values))
|
|
61
|
+
return output, {"executed": executed, "reused": reused, "consumer_executed": True}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Interop with external mechanistic-interpretability tooling.
|
|
2
|
+
|
|
3
|
+
Saturn does not reimplement these tools; it works next to them. The SAELens /
|
|
4
|
+
TransformerLens division of labor lives in ``examples/interop_saelens.py`` and
|
|
5
|
+
``docs/interop.md``. The flagship integration with Anthropic / Decode Research's
|
|
6
|
+
``circuit-tracer`` lives in :mod:`saturn.interop.circuit_tracer`: it arbitrates each
|
|
7
|
+
attribution-graph edge against the native consumer. Importing this package does not import
|
|
8
|
+
torch or ``circuit_tracer``; both load on demand.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from .circuit_tracer import (
|
|
14
|
+
EdgeRow,
|
|
15
|
+
EdgeVerdictTable,
|
|
16
|
+
SyntheticAttributionGraph,
|
|
17
|
+
build_synthetic_graph,
|
|
18
|
+
classify_graph_vs_native,
|
|
19
|
+
default_edge_rule,
|
|
20
|
+
native_edge_test,
|
|
21
|
+
native_group_intervention,
|
|
22
|
+
select_edges,
|
|
23
|
+
verify_edge_bundle,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"native_edge_test",
|
|
28
|
+
"native_group_intervention",
|
|
29
|
+
"classify_graph_vs_native",
|
|
30
|
+
"verify_edge_bundle",
|
|
31
|
+
"select_edges",
|
|
32
|
+
"default_edge_rule",
|
|
33
|
+
"EdgeRow",
|
|
34
|
+
"EdgeVerdictTable",
|
|
35
|
+
"SyntheticAttributionGraph",
|
|
36
|
+
"build_synthetic_graph",
|
|
37
|
+
]
|