mplang-nightly 0.1.dev150__py3-none-any.whl → 0.1.dev151__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.
- mplang/kernels/context.py +10 -5
- mplang/kernels/{tee.py → mock_tee.py} +11 -2
- mplang/runtime/simulation.py +34 -30
- {mplang_nightly-0.1.dev150.dist-info → mplang_nightly-0.1.dev151.dist-info}/METADATA +1 -1
- {mplang_nightly-0.1.dev150.dist-info → mplang_nightly-0.1.dev151.dist-info}/RECORD +8 -8
- {mplang_nightly-0.1.dev150.dist-info → mplang_nightly-0.1.dev151.dist-info}/WHEEL +0 -0
- {mplang_nightly-0.1.dev150.dist-info → mplang_nightly-0.1.dev151.dist-info}/entry_points.txt +0 -0
- {mplang_nightly-0.1.dev150.dist-info → mplang_nightly-0.1.dev151.dist-info}/licenses/LICENSE +0 -0
mplang/kernels/context.py
CHANGED
@@ -37,11 +37,11 @@ def _ensure_impl_imported() -> None:
|
|
37
37
|
return
|
38
38
|
from mplang.kernels import builtin as _impl_builtin # noqa: F401
|
39
39
|
from mplang.kernels import crypto as _impl_crypto # noqa: F401
|
40
|
+
from mplang.kernels import mock_tee as _impl_tee # noqa: F401
|
40
41
|
from mplang.kernels import phe as _impl_phe # noqa: F401
|
41
42
|
from mplang.kernels import spu as _impl_spu # noqa: F401
|
42
43
|
from mplang.kernels import sql_duckdb as _impl_sql_duckdb # noqa: F401
|
43
44
|
from mplang.kernels import stablehlo as _impl_stablehlo # noqa: F401
|
44
|
-
from mplang.kernels import tee as _impl_tee # noqa: F401
|
45
45
|
|
46
46
|
_IMPL_IMPORTED = True
|
47
47
|
|
@@ -91,8 +91,8 @@ _DEFAULT_BINDINGS: dict[str, str] = {
|
|
91
91
|
# generic SQL op; backend-specific kernel id for duckdb
|
92
92
|
"sql.run": "duckdb.run_sql",
|
93
93
|
# tee
|
94
|
-
"tee.quote": "
|
95
|
-
"tee.attest": "
|
94
|
+
# "tee.quote": "mock_tee.quote",
|
95
|
+
# "tee.attest": "mock_tee.attest",
|
96
96
|
}
|
97
97
|
|
98
98
|
|
@@ -102,6 +102,10 @@ _DEFAULT_BINDINGS: dict[str, str] = {
|
|
102
102
|
class RuntimeContext:
|
103
103
|
"""Per-runtime execution context with isolated op->kernel bindings.
|
104
104
|
|
105
|
+
This object owns ONLY static dispatch metadata ("op bindings") and mutable
|
106
|
+
per-rank kernel side state/cache/stats. It does NOT store per-evaluation
|
107
|
+
variable bindings (those are provided to the evaluator at evaluation time).
|
108
|
+
|
105
109
|
Parameters
|
106
110
|
----------
|
107
111
|
rank : int
|
@@ -110,9 +114,10 @@ class RuntimeContext:
|
|
110
114
|
Total number of participants.
|
111
115
|
initial_bindings : Mapping[str, str] | None, optional
|
112
116
|
Optional partial overrides applied on top of the default binding table
|
113
|
-
during construction (override semantics, not replace).
|
117
|
+
during construction (override semantics, not replace). These map
|
118
|
+
op_type -> kernel_id and form a *template* for dispatch. After
|
114
119
|
initialization, all (re)binding must go through ``bind_op`` /
|
115
|
-
``rebind_op
|
120
|
+
``rebind_op`` on this context (scoped to THIS runtime only).
|
116
121
|
state / cache / stats : dict, optional
|
117
122
|
Mutable pockets reused across kernel invocations. If omitted, new
|
118
123
|
dictionaries are created.
|
@@ -15,6 +15,7 @@
|
|
15
15
|
from __future__ import annotations
|
16
16
|
|
17
17
|
import os
|
18
|
+
import warnings
|
18
19
|
|
19
20
|
import numpy as np
|
20
21
|
from numpy.typing import NDArray
|
@@ -43,16 +44,24 @@ def _quote_from_pk(pk: np.ndarray) -> NDArray[np.uint8]:
|
|
43
44
|
return out
|
44
45
|
|
45
46
|
|
46
|
-
@kernel_def("
|
47
|
+
@kernel_def("mock_tee.quote")
|
47
48
|
def _tee_quote(pfunc: PFunction, pk: object) -> NDArray[np.uint8]:
|
49
|
+
warnings.warn(
|
50
|
+
"Insecure mock TEE kernel 'mock_tee.quote' in use. NOT secure; for local testing only.",
|
51
|
+
stacklevel=3,
|
52
|
+
)
|
48
53
|
pk = np.asarray(pk, dtype=np.uint8)
|
49
54
|
# rng access ensures deterministic seeding per rank even if unused now
|
50
55
|
_rng()
|
51
56
|
return _quote_from_pk(pk)
|
52
57
|
|
53
58
|
|
54
|
-
@kernel_def("
|
59
|
+
@kernel_def("mock_tee.attest")
|
55
60
|
def _tee_attest(pfunc: PFunction, quote: object) -> NDArray[np.uint8]:
|
61
|
+
warnings.warn(
|
62
|
+
"Insecure mock TEE kernel 'mock_tee.attest' in use. NOT secure; for local testing only.",
|
63
|
+
stacklevel=3,
|
64
|
+
)
|
56
65
|
quote = np.asarray(quote, dtype=np.uint8)
|
57
66
|
if quote.size != 33:
|
58
67
|
raise ValueError("mock quote must be 33 bytes (1 header + 32 pk)")
|
mplang/runtime/simulation.py
CHANGED
@@ -34,10 +34,6 @@ from mplang.core.mpir import Reader, Writer
|
|
34
34
|
from mplang.core.mpobject import MPObject
|
35
35
|
from mplang.core.mptype import MPType, TensorLike
|
36
36
|
from mplang.core.pfunc import PFunction # for spu.seed_env kernel seeding
|
37
|
-
|
38
|
-
# New explicit binding model: we only need RuntimeContext which ensures
|
39
|
-
# bindings via bind_all_ops() on creation; per-module side-effect imports
|
40
|
-
# are no longer required here.
|
41
37
|
from mplang.kernels.context import RuntimeContext
|
42
38
|
from mplang.runtime.link_comm import LinkCommunicator
|
43
39
|
from mplang.utils.spu_utils import parse_field, parse_protocol
|
@@ -90,14 +86,20 @@ class Simulator(InterpContext):
|
|
90
86
|
cluster_spec: ClusterSpec,
|
91
87
|
*,
|
92
88
|
trace_ranks: list[int] | None = None,
|
89
|
+
op_bindings: dict[str, str] | None = None,
|
93
90
|
) -> None:
|
94
91
|
"""Initialize a simulator with the given cluster specification.
|
95
92
|
|
96
93
|
Args:
|
97
94
|
cluster_spec: The cluster specification defining the simulation environment.
|
98
95
|
trace_ranks: List of ranks to trace execution for debugging.
|
96
|
+
op_bindings: Optional op->kernel binding template applied to all
|
97
|
+
RuntimeContexts. These are static dispatch overrides (merged
|
98
|
+
with project defaults) and are orthogonal to the per-evaluate
|
99
|
+
variable ``bindings`` dict passed into ``evaluate``.
|
99
100
|
"""
|
100
101
|
super().__init__(cluster_spec)
|
102
|
+
self._op_bindings_template = op_bindings or {}
|
101
103
|
self._trace_ranks = trace_ranks or []
|
102
104
|
|
103
105
|
spu_devices = cluster_spec.get_devices_by_kind("SPU")
|
@@ -141,20 +143,18 @@ class Simulator(InterpContext):
|
|
141
143
|
self._spu_world = spu_mask.num_parties()
|
142
144
|
self._spu_mask = spu_mask
|
143
145
|
|
144
|
-
#
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
self._comms[rank],
|
154
|
-
runtime,
|
155
|
-
None,
|
146
|
+
# Persistent per-rank RuntimeContext instances (reused across evaluates).
|
147
|
+
# We no longer pre-create evaluators since each evaluate has different env bindings.
|
148
|
+
self._runtimes: list[RuntimeContext] = [
|
149
|
+
RuntimeContext(
|
150
|
+
rank=rank,
|
151
|
+
world_size=self.world_size(),
|
152
|
+
# Static op bindings template cloned into each runtime. These are kernel
|
153
|
+
# dispatch mappings, not per-evaluate variable bindings.
|
154
|
+
initial_bindings=self._op_bindings_template,
|
156
155
|
)
|
157
|
-
self.
|
156
|
+
for rank in range(self.world_size())
|
157
|
+
]
|
158
158
|
|
159
159
|
@classmethod
|
160
160
|
def simple(
|
@@ -215,10 +215,10 @@ class Simulator(InterpContext):
|
|
215
215
|
for rank in range(self.world_size())
|
216
216
|
]
|
217
217
|
|
218
|
-
# Build per-rank evaluators with the per-party environment
|
218
|
+
# Build per-rank evaluators with the per-party environment (runtime reused)
|
219
219
|
pts_evaluators: list[IEvaluator] = []
|
220
220
|
for rank in range(self.world_size()):
|
221
|
-
runtime =
|
221
|
+
runtime = self._runtimes[rank]
|
222
222
|
ev = create_evaluator(
|
223
223
|
rank,
|
224
224
|
pts_env[rank],
|
@@ -226,17 +226,21 @@ class Simulator(InterpContext):
|
|
226
226
|
runtime,
|
227
227
|
None,
|
228
228
|
)
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
229
|
+
# Seed SPU once per runtime (idempotent logical requirement)
|
230
|
+
# Use setdefault to both retrieve and create metadata dict in one step.
|
231
|
+
spu_meta = runtime.state.setdefault("_spu", {})
|
232
|
+
if not spu_meta.get("inited", False):
|
233
|
+
link_ctx = self._spu_link_ctxs[rank]
|
234
|
+
seed_fn = PFunction(
|
235
|
+
fn_type="spu.seed_env",
|
236
|
+
ins_info=(),
|
237
|
+
outs_info=(),
|
238
|
+
config=self._spu_runtime_cfg,
|
239
|
+
world=self._spu_world,
|
240
|
+
link=link_ctx,
|
241
|
+
)
|
242
|
+
ev.runtime.run_kernel(seed_fn, []) # type: ignore[arg-type]
|
243
|
+
spu_meta["inited"] = True
|
240
244
|
pts_evaluators.append(ev)
|
241
245
|
|
242
246
|
# Collect evaluation results from all parties
|
@@ -29,13 +29,13 @@ mplang/core/expr/walk.py,sha256=lXkGJEEuvKGDqQihbxXPxfz2RfR1Q1zYUlt11iooQW0,1188
|
|
29
29
|
mplang/kernels/__init__.py,sha256=2WE4cmW96Xkzyq2yRRYNww4kZ5o6u6NbPV0BxqZG698,581
|
30
30
|
mplang/kernels/base.py,sha256=eizxj16sWkUvBvXWS0Zl-S9uuqalJmNUzB1xLhBg8S8,4920
|
31
31
|
mplang/kernels/builtin.py,sha256=nSuM79cn7M6M27A6Y8ycilXT_qAlB1ktkwkRX6dv_VQ,7052
|
32
|
-
mplang/kernels/context.py,sha256=
|
32
|
+
mplang/kernels/context.py,sha256=EiqsYq9Cw4Z_2lLvRNc8xNsu5EHkG_738QKFJ3Wf0zE,11329
|
33
33
|
mplang/kernels/crypto.py,sha256=TWixli1uRQ_7OjA49qQXUXa2ldHDEwaCMXXPSHdAPi8,3812
|
34
|
+
mplang/kernels/mock_tee.py,sha256=ifVqb03FgQ5EDK8r14PMpZKMMaSeqMDorcpGLiy00mM,2233
|
34
35
|
mplang/kernels/phe.py,sha256=8-_1IFPOaGECGj9mbYja8XoqbMYnYqfpDNVyMJd8J1Y,65247
|
35
36
|
mplang/kernels/spu.py,sha256=Kkg1ZQbmklXl7YkIeBfxqs3o4wX7ygBE8hXLpx90L9Y,9307
|
36
37
|
mplang/kernels/sql_duckdb.py,sha256=C2XdNLoE2Apma-Fs7OYzDzkBAXAVuShuROxhCWCHDG4,1502
|
37
38
|
mplang/kernels/stablehlo.py,sha256=jDsu-lIHRAm94FcUcxZgK02c6BhFJpbO8cf2hP2DFgk,2937
|
38
|
-
mplang/kernels/tee.py,sha256=v4_njXjb7cGQuE-D50V5byp2JDQJ79SwzyKSHUElbI0,1918
|
39
39
|
mplang/ops/__init__.py,sha256=dpe7WWiYapOFzJeGoKFYBr5mnd6P5SdOyvdYaM2Nhm0,1408
|
40
40
|
mplang/ops/base.py,sha256=rGtfBejcDh9mTRxOdJK5VUlG5vYiVJSir8X72X0Huvc,18264
|
41
41
|
mplang/ops/builtin.py,sha256=D7T8rRF9g05VIw9T72lsncF5cDQqaT37eapBieRKvRI,9363
|
@@ -60,7 +60,7 @@ mplang/runtime/http_api.md,sha256=-re1DhEqMplAkv_wnqEU-PSs8tTzf4-Ml0Gq0f3Go6s,48
|
|
60
60
|
mplang/runtime/link_comm.py,sha256=uNqTCGZVwWeuHAb7yXXQf0DUsMXLa8leHCkrcZdzYMU,4559
|
61
61
|
mplang/runtime/resource.py,sha256=xNke4UpNDjsjWcr09oXWNBXsMfSZFOwsKD7FWdCVPbc,11688
|
62
62
|
mplang/runtime/server.py,sha256=LQ5uJi95tYrKmgHwZaxUQi-aiqwSsT3W4z7pZ9dQaUQ,14716
|
63
|
-
mplang/runtime/simulation.py,sha256=
|
63
|
+
mplang/runtime/simulation.py,sha256=_cmUsYL58mvc6msHZ2fDjFAEHHLdJ-TRzJV8BxOP_WA,11473
|
64
64
|
mplang/simp/__init__.py,sha256=xNXnA8-jZAANa2A1W39b3lYO7D02zdCXl0TpivkTGS4,11579
|
65
65
|
mplang/simp/mpi.py,sha256=Wv_Q16TQ3rdLam6OzqXiefIGSMmagGkso09ycyOkHEs,4774
|
66
66
|
mplang/simp/random.py,sha256=7PVgWNL1j7Sf3MqT5PRiWplUu-0dyhF3Ub566iqX86M,3898
|
@@ -70,8 +70,8 @@ mplang/utils/crypto.py,sha256=rvPomBFtznRHc3RPi6Aip9lsU8zW2oxBqGv1K3vn7Rs,1052
|
|
70
70
|
mplang/utils/func_utils.py,sha256=vCJcZmu0bEbqhOQKdpttV2_MBllIcPSN0b8U4WjNGGo,5164
|
71
71
|
mplang/utils/spu_utils.py,sha256=S3L9RBkBe2AvSuMSQQ12cBY5Y1NPthubvErSX_7nj1A,4158
|
72
72
|
mplang/utils/table_utils.py,sha256=aC-IZOKkSmFkpr3NZchLM0Wt0GOn-rg_xHBHREWBwAU,2202
|
73
|
-
mplang_nightly-0.1.
|
74
|
-
mplang_nightly-0.1.
|
75
|
-
mplang_nightly-0.1.
|
76
|
-
mplang_nightly-0.1.
|
77
|
-
mplang_nightly-0.1.
|
73
|
+
mplang_nightly-0.1.dev151.dist-info/METADATA,sha256=sCQECTJOQoKyr3XXAf8Kma7lrB5KEt6toJbQA9a5nEA,16547
|
74
|
+
mplang_nightly-0.1.dev151.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
75
|
+
mplang_nightly-0.1.dev151.dist-info/entry_points.txt,sha256=mG1oJT-GAjQR834a62_QIWb7litzWPPyVnwFqm-rWuY,55
|
76
|
+
mplang_nightly-0.1.dev151.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
77
|
+
mplang_nightly-0.1.dev151.dist-info/RECORD,,
|
File without changes
|
{mplang_nightly-0.1.dev150.dist-info → mplang_nightly-0.1.dev151.dist-info}/entry_points.txt
RENAMED
File without changes
|
{mplang_nightly-0.1.dev150.dist-info → mplang_nightly-0.1.dev151.dist-info}/licenses/LICENSE
RENAMED
File without changes
|