nexaroa 0.0.111__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.
- neuroshard/__init__.py +93 -0
- neuroshard/__main__.py +4 -0
- neuroshard/cli.py +466 -0
- neuroshard/core/__init__.py +92 -0
- neuroshard/core/consensus/verifier.py +252 -0
- neuroshard/core/crypto/__init__.py +20 -0
- neuroshard/core/crypto/ecdsa.py +392 -0
- neuroshard/core/economics/__init__.py +52 -0
- neuroshard/core/economics/constants.py +387 -0
- neuroshard/core/economics/ledger.py +2111 -0
- neuroshard/core/economics/market.py +975 -0
- neuroshard/core/economics/wallet.py +168 -0
- neuroshard/core/governance/__init__.py +74 -0
- neuroshard/core/governance/proposal.py +561 -0
- neuroshard/core/governance/registry.py +545 -0
- neuroshard/core/governance/versioning.py +332 -0
- neuroshard/core/governance/voting.py +453 -0
- neuroshard/core/model/__init__.py +30 -0
- neuroshard/core/model/dynamic.py +4186 -0
- neuroshard/core/model/llm.py +905 -0
- neuroshard/core/model/registry.py +164 -0
- neuroshard/core/model/scaler.py +387 -0
- neuroshard/core/model/tokenizer.py +568 -0
- neuroshard/core/network/__init__.py +56 -0
- neuroshard/core/network/connection_pool.py +72 -0
- neuroshard/core/network/dht.py +130 -0
- neuroshard/core/network/dht_plan.py +55 -0
- neuroshard/core/network/dht_proof_store.py +516 -0
- neuroshard/core/network/dht_protocol.py +261 -0
- neuroshard/core/network/dht_service.py +506 -0
- neuroshard/core/network/encrypted_channel.py +141 -0
- neuroshard/core/network/nat.py +201 -0
- neuroshard/core/network/nat_traversal.py +695 -0
- neuroshard/core/network/p2p.py +929 -0
- neuroshard/core/network/p2p_data.py +150 -0
- neuroshard/core/swarm/__init__.py +106 -0
- neuroshard/core/swarm/aggregation.py +729 -0
- neuroshard/core/swarm/buffers.py +643 -0
- neuroshard/core/swarm/checkpoint.py +709 -0
- neuroshard/core/swarm/compute.py +624 -0
- neuroshard/core/swarm/diloco.py +844 -0
- neuroshard/core/swarm/factory.py +1288 -0
- neuroshard/core/swarm/heartbeat.py +669 -0
- neuroshard/core/swarm/logger.py +487 -0
- neuroshard/core/swarm/router.py +658 -0
- neuroshard/core/swarm/service.py +640 -0
- neuroshard/core/training/__init__.py +29 -0
- neuroshard/core/training/checkpoint.py +600 -0
- neuroshard/core/training/distributed.py +1602 -0
- neuroshard/core/training/global_tracker.py +617 -0
- neuroshard/core/training/production.py +276 -0
- neuroshard/governance_cli.py +729 -0
- neuroshard/grpc_server.py +895 -0
- neuroshard/runner.py +3223 -0
- neuroshard/sdk/__init__.py +92 -0
- neuroshard/sdk/client.py +990 -0
- neuroshard/sdk/errors.py +101 -0
- neuroshard/sdk/types.py +282 -0
- neuroshard/tracker/__init__.py +0 -0
- neuroshard/tracker/server.py +864 -0
- neuroshard/ui/__init__.py +0 -0
- neuroshard/ui/app.py +102 -0
- neuroshard/ui/templates/index.html +1052 -0
- neuroshard/utils/__init__.py +0 -0
- neuroshard/utils/autostart.py +81 -0
- neuroshard/utils/hardware.py +121 -0
- neuroshard/utils/serialization.py +90 -0
- neuroshard/version.py +1 -0
- nexaroa-0.0.111.dist-info/METADATA +283 -0
- nexaroa-0.0.111.dist-info/RECORD +78 -0
- nexaroa-0.0.111.dist-info/WHEEL +5 -0
- nexaroa-0.0.111.dist-info/entry_points.txt +4 -0
- nexaroa-0.0.111.dist-info/licenses/LICENSE +190 -0
- nexaroa-0.0.111.dist-info/top_level.txt +2 -0
- protos/__init__.py +0 -0
- protos/neuroshard.proto +651 -0
- protos/neuroshard_pb2.py +160 -0
- protos/neuroshard_pb2_grpc.py +1298 -0
neuroshard/sdk/errors.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NeuroShard SDK Error Classes
|
|
3
|
+
|
|
4
|
+
Standard exception classes for SDK error handling.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class NeuroShardError(Exception):
|
|
11
|
+
"""Base exception for all NeuroShard SDK errors."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, message: str, code: Optional[str] = None, details: Optional[dict] = None):
|
|
14
|
+
super().__init__(message)
|
|
15
|
+
self.message = message
|
|
16
|
+
self.code = code or "UNKNOWN_ERROR"
|
|
17
|
+
self.details = details or {}
|
|
18
|
+
|
|
19
|
+
def __str__(self):
|
|
20
|
+
return f"[{self.code}] {self.message}"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AuthenticationError(NeuroShardError):
|
|
24
|
+
"""Raised when API token is invalid or missing."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, message: str = "Invalid or missing API token"):
|
|
27
|
+
super().__init__(message, code="UNAUTHORIZED")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class InsufficientBalanceError(NeuroShardError):
|
|
31
|
+
"""Raised when wallet balance is insufficient for an operation."""
|
|
32
|
+
|
|
33
|
+
def __init__(self, required: float, available: float, message: Optional[str] = None):
|
|
34
|
+
self.required = required
|
|
35
|
+
self.available = available
|
|
36
|
+
msg = message or f"Insufficient balance: need {required} NEURO, have {available}"
|
|
37
|
+
super().__init__(msg, code="INSUFFICIENT_BALANCE", details={
|
|
38
|
+
"required": required,
|
|
39
|
+
"available": available
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class RateLimitError(NeuroShardError):
|
|
44
|
+
"""Raised when rate limit is exceeded."""
|
|
45
|
+
|
|
46
|
+
def __init__(self, retry_after: int, message: Optional[str] = None):
|
|
47
|
+
self.retry_after = retry_after
|
|
48
|
+
msg = message or f"Rate limited, retry after {retry_after} seconds"
|
|
49
|
+
super().__init__(msg, code="RATE_LIMITED", details={
|
|
50
|
+
"retry_after": retry_after
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class NodeOfflineError(NeuroShardError):
|
|
55
|
+
"""Raised when the target node is offline or unreachable."""
|
|
56
|
+
|
|
57
|
+
def __init__(self, url: str, message: Optional[str] = None):
|
|
58
|
+
self.url = url
|
|
59
|
+
msg = message or f"Node is offline or unreachable: {url}"
|
|
60
|
+
super().__init__(msg, code="NODE_OFFLINE", details={
|
|
61
|
+
"url": url
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class InvalidRequestError(NeuroShardError):
|
|
66
|
+
"""Raised when the request is malformed or invalid."""
|
|
67
|
+
|
|
68
|
+
def __init__(self, message: str, field: Optional[str] = None):
|
|
69
|
+
self.field = field
|
|
70
|
+
details = {"field": field} if field else {}
|
|
71
|
+
super().__init__(message, code="INVALID_REQUEST", details=details)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class NotFoundError(NeuroShardError):
|
|
75
|
+
"""Raised when a requested resource is not found."""
|
|
76
|
+
|
|
77
|
+
def __init__(self, resource: str, identifier: Optional[str] = None):
|
|
78
|
+
self.resource = resource
|
|
79
|
+
self.identifier = identifier
|
|
80
|
+
msg = f"{resource} not found"
|
|
81
|
+
if identifier:
|
|
82
|
+
msg = f"{resource} '{identifier}' not found"
|
|
83
|
+
super().__init__(msg, code="NOT_FOUND", details={
|
|
84
|
+
"resource": resource,
|
|
85
|
+
"identifier": identifier
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class ForbiddenError(NeuroShardError):
|
|
90
|
+
"""Raised when the operation is forbidden."""
|
|
91
|
+
|
|
92
|
+
def __init__(self, message: str = "Operation forbidden"):
|
|
93
|
+
super().__init__(message, code="FORBIDDEN")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class InternalError(NeuroShardError):
|
|
97
|
+
"""Raised when an internal server error occurs."""
|
|
98
|
+
|
|
99
|
+
def __init__(self, message: str = "Internal server error"):
|
|
100
|
+
super().__init__(message, code="INTERNAL_ERROR")
|
|
101
|
+
|
neuroshard/sdk/types.py
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NeuroShard SDK Type Definitions
|
|
3
|
+
|
|
4
|
+
Data classes for API responses and structured data.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from typing import List, Optional, Dict, Any
|
|
9
|
+
from datetime import datetime, date
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# ============================================================================
|
|
13
|
+
# STATUS TYPES
|
|
14
|
+
# ============================================================================
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class TrainingStatus:
|
|
18
|
+
"""Training progress information."""
|
|
19
|
+
enabled: bool = False
|
|
20
|
+
epoch: int = 0
|
|
21
|
+
step: int = 0
|
|
22
|
+
loss: float = 0.0
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class ResourceStatus:
|
|
27
|
+
"""System resource usage."""
|
|
28
|
+
gpu_memory_used: int = 0
|
|
29
|
+
gpu_memory_total: int = 0
|
|
30
|
+
cpu_percent: float = 0.0
|
|
31
|
+
ram_used: int = 0
|
|
32
|
+
ram_total: int = 0
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class NodeStatus:
|
|
37
|
+
"""Complete node status information."""
|
|
38
|
+
node_id: str
|
|
39
|
+
version: str
|
|
40
|
+
uptime_seconds: int
|
|
41
|
+
status: str # "running", "syncing", "training", "error"
|
|
42
|
+
role: str # "driver", "worker", "validator", "full"
|
|
43
|
+
layers: List[int]
|
|
44
|
+
peer_count: int
|
|
45
|
+
training: TrainingStatus
|
|
46
|
+
resources: ResourceStatus
|
|
47
|
+
has_embedding: bool = False
|
|
48
|
+
has_lm_head: bool = False
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# ============================================================================
|
|
52
|
+
# METRICS TYPES
|
|
53
|
+
# ============================================================================
|
|
54
|
+
|
|
55
|
+
@dataclass
|
|
56
|
+
class InferenceMetrics:
|
|
57
|
+
"""Inference performance metrics."""
|
|
58
|
+
requests_total: int = 0
|
|
59
|
+
requests_per_minute: float = 0.0
|
|
60
|
+
avg_latency_ms: float = 0.0
|
|
61
|
+
p99_latency_ms: float = 0.0
|
|
62
|
+
tokens_generated: int = 0
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass
|
|
66
|
+
class TrainingMetrics:
|
|
67
|
+
"""Training performance metrics."""
|
|
68
|
+
steps_total: int = 0
|
|
69
|
+
steps_per_hour: float = 0.0
|
|
70
|
+
gradients_submitted: int = 0
|
|
71
|
+
gradients_accepted: int = 0
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@dataclass
|
|
75
|
+
class NetworkMetrics:
|
|
76
|
+
"""Network usage metrics."""
|
|
77
|
+
bytes_sent: int = 0
|
|
78
|
+
bytes_received: int = 0
|
|
79
|
+
active_connections: int = 0
|
|
80
|
+
rpc_calls: int = 0
|
|
81
|
+
peer_count: int = 0
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@dataclass
|
|
85
|
+
class RewardMetrics:
|
|
86
|
+
"""Reward earning metrics."""
|
|
87
|
+
earned_today: float = 0.0
|
|
88
|
+
earned_total: float = 0.0
|
|
89
|
+
pending: float = 0.0
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@dataclass
|
|
93
|
+
class Metrics:
|
|
94
|
+
"""Complete node metrics."""
|
|
95
|
+
timestamp: str
|
|
96
|
+
inference: InferenceMetrics
|
|
97
|
+
training: TrainingMetrics
|
|
98
|
+
network: NetworkMetrics
|
|
99
|
+
rewards: RewardMetrics
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# ============================================================================
|
|
103
|
+
# INFERENCE TYPES
|
|
104
|
+
# ============================================================================
|
|
105
|
+
|
|
106
|
+
@dataclass
|
|
107
|
+
class TokenUsage:
|
|
108
|
+
"""Token usage for an inference request."""
|
|
109
|
+
prompt_tokens: int = 0
|
|
110
|
+
completion_tokens: int = 0
|
|
111
|
+
total_tokens: int = 0
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dataclass
|
|
115
|
+
class Cost:
|
|
116
|
+
"""Cost information for an operation."""
|
|
117
|
+
amount: float = 0.0
|
|
118
|
+
currency: str = "NEURO"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@dataclass
|
|
122
|
+
class Timing:
|
|
123
|
+
"""Timing breakdown for an inference request."""
|
|
124
|
+
queue_ms: float = 0.0
|
|
125
|
+
inference_ms: float = 0.0
|
|
126
|
+
total_ms: float = 0.0
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@dataclass
|
|
130
|
+
class InferenceResponse:
|
|
131
|
+
"""Response from an inference request."""
|
|
132
|
+
id: str
|
|
133
|
+
text: str
|
|
134
|
+
tokens_generated: int
|
|
135
|
+
finish_reason: str # "stop", "length", "error"
|
|
136
|
+
usage: TokenUsage
|
|
137
|
+
cost: Cost
|
|
138
|
+
timing: Timing
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@dataclass
|
|
142
|
+
class InferenceChunk:
|
|
143
|
+
"""Single chunk from a streaming inference response."""
|
|
144
|
+
token: str
|
|
145
|
+
index: int
|
|
146
|
+
logprob: Optional[float] = None
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
# ============================================================================
|
|
150
|
+
# NETWORK TYPES
|
|
151
|
+
# ============================================================================
|
|
152
|
+
|
|
153
|
+
@dataclass
|
|
154
|
+
class PeerInfo:
|
|
155
|
+
"""Information about a connected peer."""
|
|
156
|
+
id: str
|
|
157
|
+
address: str
|
|
158
|
+
role: str # "driver", "worker", "validator"
|
|
159
|
+
layers: List[int]
|
|
160
|
+
latency_ms: float = 0.0
|
|
161
|
+
connected_since: Optional[str] = None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@dataclass
|
|
165
|
+
class LayerInfo:
|
|
166
|
+
"""Information about a model layer."""
|
|
167
|
+
index: int
|
|
168
|
+
type: str # "transformer", "embedding", "lm_head"
|
|
169
|
+
memory_mb: int = 0
|
|
170
|
+
status: str = "active" # "active", "loading", "error"
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
# ============================================================================
|
|
174
|
+
# WALLET TYPES
|
|
175
|
+
# ============================================================================
|
|
176
|
+
|
|
177
|
+
@dataclass
|
|
178
|
+
class Balance:
|
|
179
|
+
"""Wallet balance information."""
|
|
180
|
+
address: str
|
|
181
|
+
available: float = 0.0
|
|
182
|
+
staked: float = 0.0
|
|
183
|
+
pending: float = 0.0
|
|
184
|
+
total: float = 0.0
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
@dataclass
|
|
188
|
+
class Transaction:
|
|
189
|
+
"""A NEURO token transaction."""
|
|
190
|
+
id: str
|
|
191
|
+
from_address: str
|
|
192
|
+
to_address: str
|
|
193
|
+
amount: float
|
|
194
|
+
fee: float
|
|
195
|
+
status: str # "pending", "confirmed", "failed"
|
|
196
|
+
timestamp: datetime
|
|
197
|
+
type: str = "transfer" # "transfer", "reward", "stake", "unstake"
|
|
198
|
+
memo: Optional[str] = None
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
@dataclass
|
|
202
|
+
class StakeInfo:
|
|
203
|
+
"""Staking information."""
|
|
204
|
+
amount: float = 0.0
|
|
205
|
+
duration_days: int = 0
|
|
206
|
+
start_date: Optional[date] = None
|
|
207
|
+
unlock_date: Optional[date] = None
|
|
208
|
+
multiplier: float = 1.0
|
|
209
|
+
pending_unstake: float = 0.0
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
@dataclass
|
|
213
|
+
class StakeResult:
|
|
214
|
+
"""Result of a stake operation."""
|
|
215
|
+
amount: float
|
|
216
|
+
duration_days: int
|
|
217
|
+
start_date: date
|
|
218
|
+
unlock_date: date
|
|
219
|
+
multiplier: float
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@dataclass
|
|
223
|
+
class UnstakeResult:
|
|
224
|
+
"""Result of an unstake request."""
|
|
225
|
+
amount: float
|
|
226
|
+
cooldown_days: int
|
|
227
|
+
available_date: date
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
@dataclass
|
|
231
|
+
class DailyReward:
|
|
232
|
+
"""Daily reward breakdown."""
|
|
233
|
+
date: date
|
|
234
|
+
amount: float
|
|
235
|
+
proofs: int = 0
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@dataclass
|
|
239
|
+
class RewardSummary:
|
|
240
|
+
"""Summary of rewards."""
|
|
241
|
+
total: float = 0.0
|
|
242
|
+
by_day: List[DailyReward] = field(default_factory=list)
|
|
243
|
+
by_type: Dict[str, float] = field(default_factory=dict)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
# ============================================================================
|
|
247
|
+
# CONFIGURATION TYPES
|
|
248
|
+
# ============================================================================
|
|
249
|
+
|
|
250
|
+
@dataclass
|
|
251
|
+
class NodeConfig:
|
|
252
|
+
"""Node configuration."""
|
|
253
|
+
node_id: str
|
|
254
|
+
port: int
|
|
255
|
+
grpc_port: int
|
|
256
|
+
tracker_url: str
|
|
257
|
+
training: Dict[str, Any] = field(default_factory=dict)
|
|
258
|
+
resources: Dict[str, Any] = field(default_factory=dict)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
# ============================================================================
|
|
262
|
+
# PROOF TYPES
|
|
263
|
+
# ============================================================================
|
|
264
|
+
|
|
265
|
+
@dataclass
|
|
266
|
+
class ProofInfo:
|
|
267
|
+
"""Information about a PoNW proof."""
|
|
268
|
+
id: str
|
|
269
|
+
type: str # "forward", "training", "uptime"
|
|
270
|
+
layer: Optional[int] = None
|
|
271
|
+
timestamp: Optional[str] = None
|
|
272
|
+
verified: bool = False
|
|
273
|
+
reward: float = 0.0
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
@dataclass
|
|
277
|
+
class ProofStats:
|
|
278
|
+
"""Statistics about proofs."""
|
|
279
|
+
total_submitted: int = 0
|
|
280
|
+
total_verified: int = 0
|
|
281
|
+
total_reward: float = 0.0
|
|
282
|
+
|
|
File without changes
|