mplang-nightly 0.1.dev269__py3-none-any.whl → 0.1.dev270__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/__init__.py +391 -17
- mplang/{v2/backends → backends}/__init__.py +9 -7
- mplang/{v2/backends → backends}/bfv_impl.py +6 -6
- mplang/{v2/backends → backends}/crypto_impl.py +6 -6
- mplang/{v2/backends → backends}/field_impl.py +5 -5
- mplang/{v2/backends → backends}/func_impl.py +4 -4
- mplang/{v2/backends → backends}/phe_impl.py +3 -3
- mplang/{v2/backends → backends}/simp_design.md +1 -1
- mplang/{v2/backends → backends}/simp_driver/__init__.py +5 -5
- mplang/{v2/backends → backends}/simp_driver/http.py +8 -8
- mplang/{v2/backends → backends}/simp_driver/mem.py +9 -9
- mplang/{v2/backends → backends}/simp_driver/ops.py +4 -4
- mplang/{v2/backends → backends}/simp_driver/state.py +2 -2
- mplang/{v2/backends → backends}/simp_driver/values.py +2 -2
- mplang/{v2/backends → backends}/simp_worker/__init__.py +3 -3
- mplang/{v2/backends → backends}/simp_worker/http.py +10 -10
- mplang/{v2/backends → backends}/simp_worker/mem.py +1 -1
- mplang/{v2/backends → backends}/simp_worker/ops.py +5 -5
- mplang/{v2/backends → backends}/simp_worker/state.py +2 -4
- mplang/{v2/backends → backends}/spu_impl.py +8 -8
- mplang/{v2/backends → backends}/spu_state.py +4 -4
- mplang/{v2/backends → backends}/store_impl.py +3 -3
- mplang/{v2/backends → backends}/table_impl.py +8 -8
- mplang/{v2/backends → backends}/tee_impl.py +6 -6
- mplang/{v2/backends → backends}/tensor_impl.py +6 -6
- mplang/{v2/cli.py → cli.py} +9 -9
- mplang/{v2/cli_guide.md → cli_guide.md} +12 -12
- mplang/{v2/dialects → dialects}/__init__.py +5 -5
- mplang/{v2/dialects → dialects}/bfv.py +6 -6
- mplang/{v2/dialects → dialects}/crypto.py +5 -5
- mplang/{v2/dialects → dialects}/dtypes.py +2 -2
- mplang/{v2/dialects → dialects}/field.py +3 -3
- mplang/{v2/dialects → dialects}/func.py +2 -2
- mplang/{v2/dialects → dialects}/phe.py +6 -6
- mplang/{v2/dialects → dialects}/simp.py +6 -6
- mplang/{v2/dialects → dialects}/spu.py +7 -7
- mplang/{v2/dialects → dialects}/store.py +2 -2
- mplang/{v2/dialects → dialects}/table.py +3 -3
- mplang/{v2/dialects → dialects}/tee.py +6 -6
- mplang/{v2/dialects → dialects}/tensor.py +5 -5
- mplang/{v2/edsl → edsl}/__init__.py +3 -3
- mplang/{v2/edsl → edsl}/context.py +6 -6
- mplang/{v2/edsl → edsl}/graph.py +5 -5
- mplang/{v2/edsl → edsl}/jit.py +2 -2
- mplang/{v2/edsl → edsl}/object.py +1 -1
- mplang/{v2/edsl → edsl}/primitive.py +5 -5
- mplang/{v2/edsl → edsl}/printer.py +1 -1
- mplang/{v2/edsl → edsl}/serde.py +1 -1
- mplang/{v2/edsl → edsl}/tracer.py +7 -7
- mplang/{v2/edsl → edsl}/typing.py +1 -1
- mplang/{v2/kernels → kernels}/ldpc.cpp +13 -13
- mplang/{v2/kernels → kernels}/okvs.cpp +4 -4
- mplang/{v2/kernels → kernels}/okvs_opt.cpp +31 -31
- mplang/{v2/kernels → kernels}/py_kernels.py +1 -1
- mplang/{v2/libs → libs}/collective.py +5 -5
- mplang/{v2/libs → libs}/device/__init__.py +1 -1
- mplang/{v2/libs → libs}/device/api.py +12 -12
- mplang/{v2/libs → libs}/ml/__init__.py +1 -1
- mplang/{v2/libs → libs}/ml/sgb.py +4 -4
- mplang/{v2/libs → libs}/mpc/__init__.py +3 -3
- mplang/{v2/libs → libs}/mpc/_utils.py +2 -2
- mplang/{v2/libs → libs}/mpc/analytics/aggregation.py +1 -1
- mplang/{v2/libs → libs}/mpc/analytics/groupby.py +2 -2
- mplang/{v2/libs → libs}/mpc/analytics/permutation.py +3 -3
- mplang/{v2/libs → libs}/mpc/ot/base.py +3 -3
- mplang/{v2/libs → libs}/mpc/ot/extension.py +2 -2
- mplang/{v2/libs → libs}/mpc/ot/silent.py +4 -4
- mplang/{v2/libs → libs}/mpc/psi/cuckoo.py +3 -3
- mplang/{v2/libs → libs}/mpc/psi/okvs.py +1 -1
- mplang/{v2/libs → libs}/mpc/psi/okvs_gct.py +3 -3
- mplang/{v2/libs → libs}/mpc/psi/oprf.py +3 -3
- mplang/{v2/libs → libs}/mpc/psi/rr22.py +7 -7
- mplang/{v2/libs → libs}/mpc/psi/unbalanced.py +4 -4
- mplang/{v2/libs → libs}/mpc/vole/gilboa.py +3 -3
- mplang/{v2/libs → libs}/mpc/vole/ldpc.py +2 -2
- mplang/{v2/libs → libs}/mpc/vole/silver.py +6 -6
- mplang/{v2/runtime → runtime}/interpreter.py +11 -11
- mplang/{v2/runtime → runtime}/value.py +2 -2
- mplang/{v1/runtime → utils}/__init__.py +18 -15
- mplang/{v1/utils → utils}/func_utils.py +1 -1
- {mplang_nightly-0.1.dev269.dist-info → mplang_nightly-0.1.dev270.dist-info}/METADATA +2 -2
- mplang_nightly-0.1.dev270.dist-info/RECORD +102 -0
- mplang/v1/__init__.py +0 -157
- mplang/v1/_device.py +0 -602
- mplang/v1/analysis/__init__.py +0 -37
- mplang/v1/analysis/diagram.py +0 -567
- mplang/v1/core/__init__.py +0 -157
- mplang/v1/core/cluster.py +0 -343
- mplang/v1/core/comm.py +0 -281
- mplang/v1/core/context_mgr.py +0 -50
- mplang/v1/core/dtypes.py +0 -335
- mplang/v1/core/expr/__init__.py +0 -80
- mplang/v1/core/expr/ast.py +0 -542
- mplang/v1/core/expr/evaluator.py +0 -581
- mplang/v1/core/expr/printer.py +0 -285
- mplang/v1/core/expr/transformer.py +0 -141
- mplang/v1/core/expr/utils.py +0 -78
- mplang/v1/core/expr/visitor.py +0 -85
- mplang/v1/core/expr/walk.py +0 -387
- mplang/v1/core/interp.py +0 -160
- mplang/v1/core/mask.py +0 -325
- mplang/v1/core/mpir.py +0 -965
- mplang/v1/core/mpobject.py +0 -117
- mplang/v1/core/mptype.py +0 -407
- mplang/v1/core/pfunc.py +0 -130
- mplang/v1/core/primitive.py +0 -877
- mplang/v1/core/table.py +0 -218
- mplang/v1/core/tensor.py +0 -75
- mplang/v1/core/tracer.py +0 -383
- mplang/v1/host.py +0 -130
- mplang/v1/kernels/__init__.py +0 -41
- mplang/v1/kernels/base.py +0 -125
- mplang/v1/kernels/basic.py +0 -240
- mplang/v1/kernels/context.py +0 -369
- mplang/v1/kernels/crypto.py +0 -122
- mplang/v1/kernels/fhe.py +0 -858
- mplang/v1/kernels/mock_tee.py +0 -72
- mplang/v1/kernels/phe.py +0 -1864
- mplang/v1/kernels/spu.py +0 -341
- mplang/v1/kernels/sql_duckdb.py +0 -44
- mplang/v1/kernels/stablehlo.py +0 -90
- mplang/v1/kernels/value.py +0 -626
- mplang/v1/ops/__init__.py +0 -35
- mplang/v1/ops/base.py +0 -424
- mplang/v1/ops/basic.py +0 -294
- mplang/v1/ops/crypto.py +0 -262
- mplang/v1/ops/fhe.py +0 -272
- mplang/v1/ops/jax_cc.py +0 -147
- mplang/v1/ops/nnx_cc.py +0 -168
- mplang/v1/ops/phe.py +0 -216
- mplang/v1/ops/spu.py +0 -151
- mplang/v1/ops/sql_cc.py +0 -303
- mplang/v1/ops/tee.py +0 -36
- mplang/v1/protos/v1alpha1/mpir_pb2.py +0 -63
- mplang/v1/protos/v1alpha1/mpir_pb2.pyi +0 -557
- mplang/v1/protos/v1alpha1/value_pb2.py +0 -34
- mplang/v1/protos/v1alpha1/value_pb2.pyi +0 -169
- mplang/v1/runtime/channel.py +0 -230
- mplang/v1/runtime/cli.py +0 -451
- mplang/v1/runtime/client.py +0 -456
- mplang/v1/runtime/communicator.py +0 -131
- mplang/v1/runtime/data_providers.py +0 -303
- mplang/v1/runtime/driver.py +0 -324
- mplang/v1/runtime/exceptions.py +0 -27
- mplang/v1/runtime/http_api.md +0 -56
- mplang/v1/runtime/link_comm.py +0 -196
- mplang/v1/runtime/server.py +0 -501
- mplang/v1/runtime/session.py +0 -270
- mplang/v1/runtime/simulation.py +0 -324
- mplang/v1/simp/__init__.py +0 -13
- mplang/v1/simp/api.py +0 -353
- mplang/v1/simp/mpi.py +0 -131
- mplang/v1/simp/party.py +0 -225
- mplang/v1/simp/random.py +0 -120
- mplang/v1/simp/smpc.py +0 -238
- mplang/v1/utils/__init__.py +0 -13
- mplang/v1/utils/crypto.py +0 -32
- mplang/v1/utils/spu_utils.py +0 -130
- mplang/v1/utils/table_utils.py +0 -185
- mplang/v2/__init__.py +0 -424
- mplang_nightly-0.1.dev269.dist-info/RECORD +0 -180
- /mplang/{v2/backends → backends}/channel.py +0 -0
- /mplang/{v2/edsl → edsl}/README.md +0 -0
- /mplang/{v2/edsl → edsl}/registry.py +0 -0
- /mplang/{v2/kernels → kernels}/Makefile +0 -0
- /mplang/{v2/kernels → kernels}/__init__.py +0 -0
- /mplang/{v2/kernels → kernels}/gf128.cpp +0 -0
- /mplang/{v2/libs → libs}/device/cluster.py +0 -0
- /mplang/{v2/libs → libs}/mpc/analytics/__init__.py +0 -0
- /mplang/{v2/libs → libs}/mpc/analytics/groupby.md +0 -0
- /mplang/{v2/libs → libs}/mpc/common/constants.py +0 -0
- /mplang/{v2/libs → libs}/mpc/ot/__init__.py +0 -0
- /mplang/{v2/libs → libs}/mpc/psi/__init__.py +0 -0
- /mplang/{v2/libs → libs}/mpc/vole/__init__.py +0 -0
- /mplang/{v2/runtime → runtime}/__init__.py +0 -0
- /mplang/{v2/runtime → runtime}/dialect_state.py +0 -0
- /mplang/{v2/runtime → runtime}/object_store.py +0 -0
- {mplang_nightly-0.1.dev269.dist-info → mplang_nightly-0.1.dev270.dist-info}/WHEEL +0 -0
- {mplang_nightly-0.1.dev269.dist-info → mplang_nightly-0.1.dev270.dist-info}/entry_points.txt +0 -0
- {mplang_nightly-0.1.dev269.dist-info → mplang_nightly-0.1.dev270.dist-info}/licenses/LICENSE +0 -0
mplang/v1/runtime/http_api.md
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# MPLang HTTP Runtime API v1
|
|
2
|
-
|
|
3
|
-
This document specifies the RESTful API for the MPLang HTTP runtime server.
|
|
4
|
-
|
|
5
|
-
## Design Rationale
|
|
6
|
-
|
|
7
|
-
The API follows a resource-oriented design to manage sessions, computations, and symbols for distributed multi-party computation.
|
|
8
|
-
|
|
9
|
-
### Client-Generated IDs and Idempotent Creation
|
|
10
|
-
|
|
11
|
-
A key design choice is the use of `PUT` for resource creation (e.g., `PUT /api/v1/sessions/{session_id}`). This is because identifiers for resources like `sessions` and `computations` are generated by the client (the `Driver`), not the server.
|
|
12
|
-
|
|
13
|
-
This approach ensures that a resource ID is consistent across all participating parties in a distributed computation. Since the client defines the resource's unique URI, the creation operation is naturally **idempotent**. A `PUT` request will create the resource if it doesn't exist or do nothing if it already exists, which simplifies error recovery and retry logic for the client.
|
|
14
|
-
|
|
15
|
-
### Update Strategy: PUT vs. PATCH
|
|
16
|
-
|
|
17
|
-
The use of `PUT` for creation also implies its role in updates. According to HTTP semantics, `PUT` performs a **full replacement** of a resource. This is suitable for our current needs, as resources like `Session` and `Computation` configurations are largely immutable once created.
|
|
18
|
-
|
|
19
|
-
If a future requirement arises for **partial updates** (e.g., modifying a single attribute of a resource without sending the entire object), the standard approach is to introduce the `PATCH` method. For example:
|
|
20
|
-
|
|
21
|
-
`PATCH /api/v1/sessions/{session_id}`
|
|
22
|
-
|
|
23
|
-
This `PATCH` endpoint could accept a body with only the fields to be changed. It can coexist with the `PUT` endpoint without conflict. This design is therefore robust and extensible, allowing for partial updates to be added later without altering the existing API contract.
|
|
24
|
-
|
|
25
|
-
### Actions
|
|
26
|
-
|
|
27
|
-
Non-CRUD operations, such as triggering the execution of a computation, are modeled as "actions." These are invoked using `POST` on a resource, with a special action suffix (e.g., `POST /.../{resource_id}:action`). This clearly separates state changes from triggering processes.
|
|
28
|
-
|
|
29
|
-
However, for simplicity in the current implementation, some operations like computation creation and execution are combined into a single `PUT` request.
|
|
30
|
-
|
|
31
|
-
## API Endpoints (Control Plane)
|
|
32
|
-
|
|
33
|
-
The base path for all endpoints is `/api/v1`.
|
|
34
|
-
|
|
35
|
-
| Method | Path | Description |
|
|
36
|
-
| :----- | :--------------------------------------------------------- | :----------------------------------------------------------- |
|
|
37
|
-
| `GET` | `/health` | Checks if the server is running and healthy. |
|
|
38
|
-
| `PUT` | `/sessions/{session_id}` | Creates or updates a session with a client-provided ID. |
|
|
39
|
-
| `GET` | `/sessions` | Lists all sessions on the node. |
|
|
40
|
-
| `GET` | `/sessions/{session_id}` | Retrieves details for a specific session. |
|
|
41
|
-
| `DELETE` | /sessions/{session_id} | Deletes a session and all its associated resources. |
|
|
42
|
-
| `PUT` | `/sessions/{session_id}/computations/{computation_id}` | Creates and executes a computation with a client-provided ID. |
|
|
43
|
-
| `GET` | `/sessions/{session_id}/computations` | Lists all computations within a session. |
|
|
44
|
-
| `DELETE`| `/sessions/{session_id}/computations/{computation_id}` | Deletes a specific computation. |
|
|
45
|
-
| `PUT` | `/sessions/{session_id}/symbols/{symbol_name}` | Uploads or updates data for a symbol (e.g., an input). |
|
|
46
|
-
| `GET` | `/sessions/{session_id}/symbols/{symbol_name}` | Retrieves the value of a symbol (e.g., an output). |
|
|
47
|
-
| `GET` | `/sessions/{session_id}/symbols` | Lists all symbols within a session. |
|
|
48
|
-
| `DELETE`| `/sessions/{session_id}/symbols/{symbol_name}` | Deletes a specific symbol. |
|
|
49
|
-
|
|
50
|
-
## Low-Level Communication API (Data Plane)
|
|
51
|
-
|
|
52
|
-
This API operates at a different abstraction level from the control plane and is used for direct, point-to-point data exchange during computation execution. It is not versioned under `/api/v1` and is consumed internally by the `Communicator`.
|
|
53
|
-
|
|
54
|
-
| Method | Path | Description |
|
|
55
|
-
| :----- | :--------------------------------------------- | :----------------------------------------------------------- |
|
|
56
|
-
| `PUT` | `/sessions/{session_name}/comm/{key}/from/{from_rank}` | Receives a data payload from a peer and passes it to the communicator. |
|
mplang/v1/runtime/link_comm.py
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 Ant Group Co., Ltd.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
import logging
|
|
18
|
-
from typing import TYPE_CHECKING
|
|
19
|
-
|
|
20
|
-
import spu.libspu as libspu
|
|
21
|
-
|
|
22
|
-
if TYPE_CHECKING:
|
|
23
|
-
from mplang.v1.core.comm import CommunicatorBase
|
|
24
|
-
from mplang.v1.core.mask import Mask
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class LinkCommunicator:
|
|
28
|
-
"""Minimal wrapper for libspu link context.
|
|
29
|
-
|
|
30
|
-
Supports three modes:
|
|
31
|
-
1. BRPC: Production mode with separate BRPC ports (legacy)
|
|
32
|
-
2. Mem: In-memory links for testing (legacy)
|
|
33
|
-
3. Channels: Reuse MPLang communicator via IChannel bridge (NEW)
|
|
34
|
-
|
|
35
|
-
The mode is selected based on constructor arguments:
|
|
36
|
-
- If `comm` is provided: Channels mode (NEW)
|
|
37
|
-
- Elif `mem_link` is True: Mem mode
|
|
38
|
-
- Else: BRPC mode
|
|
39
|
-
"""
|
|
40
|
-
|
|
41
|
-
def __init__(
|
|
42
|
-
self,
|
|
43
|
-
rank: int,
|
|
44
|
-
addrs: list[str] | None = None,
|
|
45
|
-
*,
|
|
46
|
-
mem_link: bool = False,
|
|
47
|
-
comm: CommunicatorBase | None = None,
|
|
48
|
-
spu_mask: Mask | None = None,
|
|
49
|
-
):
|
|
50
|
-
"""Initialize link communicator for SPU.
|
|
51
|
-
|
|
52
|
-
Args:
|
|
53
|
-
rank: Global rank of this party
|
|
54
|
-
addrs: List of addresses for all SPU parties (required for BRPC/Mem mode)
|
|
55
|
-
mem_link: If True, use in-memory link (Mem mode)
|
|
56
|
-
comm: MPLang communicator to reuse (Channels mode, NEW)
|
|
57
|
-
spu_mask: SPU parties mask (required for Channels mode)
|
|
58
|
-
|
|
59
|
-
Raises:
|
|
60
|
-
ValueError: If arguments are invalid for the selected mode
|
|
61
|
-
"""
|
|
62
|
-
self._rank = rank
|
|
63
|
-
|
|
64
|
-
# Select initialization mode based on arguments
|
|
65
|
-
if comm is not None:
|
|
66
|
-
self._init_channels_mode(rank, comm, spu_mask)
|
|
67
|
-
elif mem_link:
|
|
68
|
-
self._init_mem_mode(rank, addrs)
|
|
69
|
-
else:
|
|
70
|
-
self._init_brpc_mode(rank, addrs)
|
|
71
|
-
|
|
72
|
-
def _init_channels_mode(
|
|
73
|
-
self, rank: int, comm: CommunicatorBase, spu_mask: Mask | None
|
|
74
|
-
) -> None:
|
|
75
|
-
"""Initialize Channels mode (reuse MPLang communicator).
|
|
76
|
-
|
|
77
|
-
Args:
|
|
78
|
-
rank: Global rank of this party
|
|
79
|
-
comm: MPLang communicator to reuse
|
|
80
|
-
spu_mask: SPU parties mask
|
|
81
|
-
|
|
82
|
-
Raises:
|
|
83
|
-
ValueError: If spu_mask is None or rank not in mask
|
|
84
|
-
"""
|
|
85
|
-
if spu_mask is None:
|
|
86
|
-
raise ValueError("spu_mask required when using comm")
|
|
87
|
-
if rank not in spu_mask:
|
|
88
|
-
raise ValueError(f"rank {rank} not in spu_mask {spu_mask}")
|
|
89
|
-
|
|
90
|
-
# Lazy import to avoid circular dependency
|
|
91
|
-
from mplang.v1.runtime.channel import BaseChannel
|
|
92
|
-
|
|
93
|
-
# Create channels to ALL SPU parties (including self)
|
|
94
|
-
# libspu expects world_size channels, with self channel being None
|
|
95
|
-
channels = []
|
|
96
|
-
rel_rank = spu_mask.global_to_relative_rank(rank)
|
|
97
|
-
|
|
98
|
-
for _, peer_rank in enumerate(spu_mask):
|
|
99
|
-
if peer_rank == rank:
|
|
100
|
-
# For self, use None (won't be accessed by SPU)
|
|
101
|
-
channel = None
|
|
102
|
-
else:
|
|
103
|
-
channel = BaseChannel(comm, rank, peer_rank)
|
|
104
|
-
channels.append(channel)
|
|
105
|
-
|
|
106
|
-
# Create link context with custom channels
|
|
107
|
-
desc = libspu.link.Desc() # type: ignore
|
|
108
|
-
desc.recv_timeout_ms = 100 * 1000 # 100 seconds
|
|
109
|
-
|
|
110
|
-
# Add party info to desc (required for world_size inference)
|
|
111
|
-
for idx, peer_rank in enumerate(spu_mask):
|
|
112
|
-
desc.add_party(f"P{idx}", f"dummy_{peer_rank}")
|
|
113
|
-
|
|
114
|
-
self.lctx = libspu.link.create_with_channels(desc, rel_rank, channels)
|
|
115
|
-
self._world_size = spu_mask.num_parties()
|
|
116
|
-
|
|
117
|
-
logging.info(
|
|
118
|
-
f"LinkCommunicator initialized with BaseChannel: "
|
|
119
|
-
f"rank={rank}, rel_rank={rel_rank}, spu_mask={spu_mask}, "
|
|
120
|
-
f"world_size={self._world_size}"
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
def _init_mem_mode(self, rank: int, addrs: list[str] | None) -> None:
|
|
124
|
-
"""Initialize Mem mode (in-memory links for testing).
|
|
125
|
-
|
|
126
|
-
Args:
|
|
127
|
-
rank: Global rank of this party
|
|
128
|
-
addrs: List of addresses for all SPU parties
|
|
129
|
-
|
|
130
|
-
Raises:
|
|
131
|
-
ValueError: If addrs is None
|
|
132
|
-
"""
|
|
133
|
-
if addrs is None:
|
|
134
|
-
raise ValueError("addrs required for Mem mode")
|
|
135
|
-
|
|
136
|
-
self._world_size = len(addrs)
|
|
137
|
-
|
|
138
|
-
desc = libspu.link.Desc() # type: ignore
|
|
139
|
-
desc.recv_timeout_ms = 100 * 1000 # 100 seconds
|
|
140
|
-
desc.http_max_payload_size = 32 * 1024 * 1024 # 32M
|
|
141
|
-
for rank_idx, addr in enumerate(addrs):
|
|
142
|
-
desc.add_party(f"P{rank_idx}", addr)
|
|
143
|
-
|
|
144
|
-
self.lctx = libspu.link.create_mem(desc, self._rank)
|
|
145
|
-
logging.info(
|
|
146
|
-
f"LinkCommunicator initialized with Mem: "
|
|
147
|
-
f"rank={self._rank}, world_size={self._world_size}, addrs={addrs}"
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
def _init_brpc_mode(self, rank: int, addrs: list[str] | None) -> None:
|
|
151
|
-
"""Initialize BRPC mode (production mode with separate BRPC ports).
|
|
152
|
-
|
|
153
|
-
Args:
|
|
154
|
-
rank: Global rank of this party
|
|
155
|
-
addrs: List of addresses for all SPU parties
|
|
156
|
-
|
|
157
|
-
Raises:
|
|
158
|
-
ValueError: If addrs is None
|
|
159
|
-
"""
|
|
160
|
-
if addrs is None:
|
|
161
|
-
raise ValueError("addrs required for BRPC mode")
|
|
162
|
-
|
|
163
|
-
self._world_size = len(addrs)
|
|
164
|
-
|
|
165
|
-
desc = libspu.link.Desc() # type: ignore
|
|
166
|
-
desc.recv_timeout_ms = 100 * 1000 # 100 seconds
|
|
167
|
-
desc.http_max_payload_size = 32 * 1024 * 1024 # 32M
|
|
168
|
-
for rank_idx, addr in enumerate(addrs):
|
|
169
|
-
desc.add_party(f"P{rank_idx}", addr)
|
|
170
|
-
|
|
171
|
-
self.lctx = libspu.link.create_brpc(desc, self._rank)
|
|
172
|
-
logging.info(
|
|
173
|
-
f"LinkCommunicator initialized with BRPC: "
|
|
174
|
-
f"rank={self._rank}, world_size={self._world_size}, addrs={addrs}"
|
|
175
|
-
)
|
|
176
|
-
|
|
177
|
-
@property
|
|
178
|
-
def rank(self) -> int:
|
|
179
|
-
"""Get rank from underlying link context."""
|
|
180
|
-
return self.lctx.rank # type: ignore[no-any-return]
|
|
181
|
-
|
|
182
|
-
@property
|
|
183
|
-
def world_size(self) -> int:
|
|
184
|
-
"""Get world size from underlying link context."""
|
|
185
|
-
return self.lctx.world_size # type: ignore[no-any-return]
|
|
186
|
-
|
|
187
|
-
def get_lctx(self) -> libspu.link.Context:
|
|
188
|
-
"""Get the underlying libspu link context.
|
|
189
|
-
|
|
190
|
-
This is the primary interface - SPU runtime uses this context directly.
|
|
191
|
-
All communication and serialization is handled by libspu internally.
|
|
192
|
-
|
|
193
|
-
Returns:
|
|
194
|
-
The underlying libspu.link.Context instance.
|
|
195
|
-
"""
|
|
196
|
-
return self.lctx
|