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.
Files changed (78) hide show
  1. neuroshard/__init__.py +93 -0
  2. neuroshard/__main__.py +4 -0
  3. neuroshard/cli.py +466 -0
  4. neuroshard/core/__init__.py +92 -0
  5. neuroshard/core/consensus/verifier.py +252 -0
  6. neuroshard/core/crypto/__init__.py +20 -0
  7. neuroshard/core/crypto/ecdsa.py +392 -0
  8. neuroshard/core/economics/__init__.py +52 -0
  9. neuroshard/core/economics/constants.py +387 -0
  10. neuroshard/core/economics/ledger.py +2111 -0
  11. neuroshard/core/economics/market.py +975 -0
  12. neuroshard/core/economics/wallet.py +168 -0
  13. neuroshard/core/governance/__init__.py +74 -0
  14. neuroshard/core/governance/proposal.py +561 -0
  15. neuroshard/core/governance/registry.py +545 -0
  16. neuroshard/core/governance/versioning.py +332 -0
  17. neuroshard/core/governance/voting.py +453 -0
  18. neuroshard/core/model/__init__.py +30 -0
  19. neuroshard/core/model/dynamic.py +4186 -0
  20. neuroshard/core/model/llm.py +905 -0
  21. neuroshard/core/model/registry.py +164 -0
  22. neuroshard/core/model/scaler.py +387 -0
  23. neuroshard/core/model/tokenizer.py +568 -0
  24. neuroshard/core/network/__init__.py +56 -0
  25. neuroshard/core/network/connection_pool.py +72 -0
  26. neuroshard/core/network/dht.py +130 -0
  27. neuroshard/core/network/dht_plan.py +55 -0
  28. neuroshard/core/network/dht_proof_store.py +516 -0
  29. neuroshard/core/network/dht_protocol.py +261 -0
  30. neuroshard/core/network/dht_service.py +506 -0
  31. neuroshard/core/network/encrypted_channel.py +141 -0
  32. neuroshard/core/network/nat.py +201 -0
  33. neuroshard/core/network/nat_traversal.py +695 -0
  34. neuroshard/core/network/p2p.py +929 -0
  35. neuroshard/core/network/p2p_data.py +150 -0
  36. neuroshard/core/swarm/__init__.py +106 -0
  37. neuroshard/core/swarm/aggregation.py +729 -0
  38. neuroshard/core/swarm/buffers.py +643 -0
  39. neuroshard/core/swarm/checkpoint.py +709 -0
  40. neuroshard/core/swarm/compute.py +624 -0
  41. neuroshard/core/swarm/diloco.py +844 -0
  42. neuroshard/core/swarm/factory.py +1288 -0
  43. neuroshard/core/swarm/heartbeat.py +669 -0
  44. neuroshard/core/swarm/logger.py +487 -0
  45. neuroshard/core/swarm/router.py +658 -0
  46. neuroshard/core/swarm/service.py +640 -0
  47. neuroshard/core/training/__init__.py +29 -0
  48. neuroshard/core/training/checkpoint.py +600 -0
  49. neuroshard/core/training/distributed.py +1602 -0
  50. neuroshard/core/training/global_tracker.py +617 -0
  51. neuroshard/core/training/production.py +276 -0
  52. neuroshard/governance_cli.py +729 -0
  53. neuroshard/grpc_server.py +895 -0
  54. neuroshard/runner.py +3223 -0
  55. neuroshard/sdk/__init__.py +92 -0
  56. neuroshard/sdk/client.py +990 -0
  57. neuroshard/sdk/errors.py +101 -0
  58. neuroshard/sdk/types.py +282 -0
  59. neuroshard/tracker/__init__.py +0 -0
  60. neuroshard/tracker/server.py +864 -0
  61. neuroshard/ui/__init__.py +0 -0
  62. neuroshard/ui/app.py +102 -0
  63. neuroshard/ui/templates/index.html +1052 -0
  64. neuroshard/utils/__init__.py +0 -0
  65. neuroshard/utils/autostart.py +81 -0
  66. neuroshard/utils/hardware.py +121 -0
  67. neuroshard/utils/serialization.py +90 -0
  68. neuroshard/version.py +1 -0
  69. nexaroa-0.0.111.dist-info/METADATA +283 -0
  70. nexaroa-0.0.111.dist-info/RECORD +78 -0
  71. nexaroa-0.0.111.dist-info/WHEEL +5 -0
  72. nexaroa-0.0.111.dist-info/entry_points.txt +4 -0
  73. nexaroa-0.0.111.dist-info/licenses/LICENSE +190 -0
  74. nexaroa-0.0.111.dist-info/top_level.txt +2 -0
  75. protos/__init__.py +0 -0
  76. protos/neuroshard.proto +651 -0
  77. protos/neuroshard_pb2.py +160 -0
  78. protos/neuroshard_pb2_grpc.py +1298 -0
@@ -0,0 +1,332 @@
1
+ """
2
+ Protocol Versioning - Compatibility Management
3
+
4
+ Nodes must be able to determine if they're compatible with the network.
5
+ This module tracks protocol versions and upgrade requirements.
6
+
7
+ Version Format: MAJOR.MINOR.PATCH
8
+ - MAJOR: Breaking changes (hard fork, must upgrade)
9
+ - MINOR: New features (backward compatible)
10
+ - PATCH: Bug fixes (fully compatible)
11
+ """
12
+
13
+ import json
14
+ import logging
15
+ from dataclasses import dataclass, field
16
+ from typing import Dict, List, Optional, Tuple, Set
17
+ from enum import Enum
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+
22
+ class CompatibilityLevel(Enum):
23
+ """How compatible two versions are."""
24
+ IDENTICAL = "identical" # Same version
25
+ COMPATIBLE = "compatible" # Can communicate
26
+ UPGRADE_RECOMMENDED = "upgrade" # Works but should upgrade
27
+ INCOMPATIBLE = "incompatible" # Cannot communicate
28
+
29
+
30
+ @dataclass
31
+ class ProtocolVersion:
32
+ """
33
+ Protocol version with feature flags.
34
+
35
+ The version determines what features/parameters a node supports.
36
+ Feature flags allow granular compatibility checking.
37
+ """
38
+ major: int = 1
39
+ minor: int = 0
40
+ patch: int = 0
41
+
42
+ # Feature flags (what this version supports)
43
+ features: Set[str] = field(default_factory=set)
44
+
45
+ # Active NEPs at this version
46
+ active_neps: List[str] = field(default_factory=list)
47
+
48
+ @property
49
+ def version_string(self) -> str:
50
+ return f"{self.major}.{self.minor}.{self.patch}"
51
+
52
+ def __str__(self) -> str:
53
+ return self.version_string
54
+
55
+ def __hash__(self):
56
+ return hash(self.version_string)
57
+
58
+ def __eq__(self, other):
59
+ if isinstance(other, ProtocolVersion):
60
+ return (
61
+ self.major == other.major and
62
+ self.minor == other.minor and
63
+ self.patch == other.patch
64
+ )
65
+ return False
66
+
67
+ def __lt__(self, other):
68
+ if isinstance(other, ProtocolVersion):
69
+ return (self.major, self.minor, self.patch) < (other.major, other.minor, other.patch)
70
+ return NotImplemented
71
+
72
+ def __le__(self, other):
73
+ return self == other or self < other
74
+
75
+ def to_dict(self) -> Dict:
76
+ return {
77
+ "major": self.major,
78
+ "minor": self.minor,
79
+ "patch": self.patch,
80
+ "features": list(self.features),
81
+ "active_neps": self.active_neps,
82
+ }
83
+
84
+ @classmethod
85
+ def from_dict(cls, data: Dict) -> 'ProtocolVersion':
86
+ return cls(
87
+ major=data.get("major", 1),
88
+ minor=data.get("minor", 0),
89
+ patch=data.get("patch", 0),
90
+ features=set(data.get("features", [])),
91
+ active_neps=data.get("active_neps", []),
92
+ )
93
+
94
+ @classmethod
95
+ def from_string(cls, version_str: str) -> 'ProtocolVersion':
96
+ """Parse version string like '1.2.3'."""
97
+ parts = version_str.split(".")
98
+ return cls(
99
+ major=int(parts[0]) if len(parts) > 0 else 1,
100
+ minor=int(parts[1]) if len(parts) > 1 else 0,
101
+ patch=int(parts[2]) if len(parts) > 2 else 0,
102
+ )
103
+
104
+ def check_compatibility(self, other: 'ProtocolVersion') -> CompatibilityLevel:
105
+ """
106
+ Check compatibility between this version and another.
107
+ """
108
+ if self == other:
109
+ return CompatibilityLevel.IDENTICAL
110
+
111
+ # Major version mismatch = incompatible
112
+ if self.major != other.major:
113
+ return CompatibilityLevel.INCOMPATIBLE
114
+
115
+ # Minor version difference = compatible but upgrade recommended
116
+ if self.minor != other.minor:
117
+ return CompatibilityLevel.UPGRADE_RECOMMENDED
118
+
119
+ # Patch difference = fully compatible
120
+ return CompatibilityLevel.COMPATIBLE
121
+
122
+ def supports_feature(self, feature: str) -> bool:
123
+ """Check if this version supports a feature."""
124
+ return feature in self.features
125
+
126
+
127
+ # =============================================================================
128
+ # CURRENT PROTOCOL VERSION
129
+ # =============================================================================
130
+
131
+ # This is the current protocol version
132
+ # Updated when NEPs are activated
133
+ CURRENT_VERSION = ProtocolVersion(
134
+ major=1,
135
+ minor=0,
136
+ patch=0,
137
+ features={
138
+ "diloco", # DiLoCo training
139
+ "dynamic_layers", # Dynamic layer assignment
140
+ "ponw", # Proof of Neural Work
141
+ "gossip_proofs", # Gossip-based proof sharing
142
+ "ecdsa_signatures", # ECDSA cryptographic signatures
143
+ "inference_market", # Dynamic inference pricing
144
+ "robust_aggregation", # Byzantine-tolerant gradient aggregation
145
+ },
146
+ active_neps=[], # No NEPs activated yet
147
+ )
148
+
149
+
150
+ # =============================================================================
151
+ # UPCOMING FEATURES (from potential NEPs)
152
+ # =============================================================================
153
+
154
+ FEATURE_REGISTRY = {
155
+ "mtp": {
156
+ "name": "Multi-Token Prediction",
157
+ "description": "Predict multiple future tokens for faster training",
158
+ "min_version": ProtocolVersion(1, 1, 0),
159
+ "required_nep": "NEP-001",
160
+ },
161
+ "mla": {
162
+ "name": "Multi-Head Latent Attention",
163
+ "description": "Compressed KV cache for 20x memory reduction",
164
+ "min_version": ProtocolVersion(2, 0, 0), # Breaking change
165
+ "required_nep": "NEP-002",
166
+ },
167
+ "aux_free_moe": {
168
+ "name": "Auxiliary-Loss-Free MoE Balancing",
169
+ "description": "Dynamic bias for expert load balancing",
170
+ "min_version": ProtocolVersion(1, 1, 0),
171
+ "required_nep": "NEP-003",
172
+ },
173
+ "fp8_training": {
174
+ "name": "FP8 Mixed Precision Training",
175
+ "description": "8-bit floating point for faster training",
176
+ "min_version": ProtocolVersion(1, 2, 0),
177
+ "required_nep": "NEP-004",
178
+ },
179
+ "dualpipe": {
180
+ "name": "DualPipe Parallelism",
181
+ "description": "Overlap compute and communication",
182
+ "min_version": ProtocolVersion(1, 1, 0),
183
+ "required_nep": "NEP-005",
184
+ },
185
+ }
186
+
187
+
188
+ # =============================================================================
189
+ # VERSION MANAGER
190
+ # =============================================================================
191
+
192
+ class VersionManager:
193
+ """
194
+ Manages protocol versions and feature activation.
195
+
196
+ Responsibilities:
197
+ - Track current version
198
+ - Activate features from NEPs
199
+ - Check compatibility with peers
200
+ - Enforce version requirements
201
+ """
202
+
203
+ def __init__(
204
+ self,
205
+ current_version: ProtocolVersion = None,
206
+ nep_registry=None,
207
+ ):
208
+ self.version = current_version or CURRENT_VERSION
209
+ self.nep_registry = nep_registry
210
+
211
+ # Version history
212
+ self.version_history: List[Tuple[ProtocolVersion, float]] = []
213
+
214
+ def get_current_version(self) -> ProtocolVersion:
215
+ """Get the current protocol version."""
216
+ return self.version
217
+
218
+ def activate_nep(self, nep_id: str) -> Tuple[bool, str]:
219
+ """
220
+ Activate a NEP and update version accordingly.
221
+
222
+ This is called when an approved NEP reaches its activation block.
223
+ """
224
+ if not self.nep_registry:
225
+ return False, "No NEP registry configured"
226
+
227
+ nep = self.nep_registry.get_proposal(nep_id)
228
+ if not nep:
229
+ return False, f"NEP {nep_id} not found"
230
+
231
+ from .proposal import NEPStatus
232
+ if nep.status != NEPStatus.SCHEDULED:
233
+ return False, f"NEP {nep_id} not scheduled (status: {nep.status.value})"
234
+
235
+ # Parse target version from upgrade path
236
+ target_version = ProtocolVersion.from_string(nep.upgrade_path.target_version)
237
+
238
+ # Update version
239
+ old_version = self.version
240
+ self.version = target_version
241
+
242
+ # Add features from NEP
243
+ for change in nep.parameter_changes:
244
+ if change.parameter.startswith("feature_"):
245
+ feature_name = change.parameter[8:] # Remove "feature_" prefix
246
+ self.version.features.add(feature_name)
247
+
248
+ # Track in version history
249
+ import time
250
+ self.version_history.append((old_version, time.time()))
251
+
252
+ # Update NEP status
253
+ self.nep_registry.update_status(nep_id, NEPStatus.ACTIVE)
254
+
255
+ logger.info(
256
+ f"Activated {nep_id}: {old_version} → {self.version} "
257
+ f"(features: {self.version.features})"
258
+ )
259
+
260
+ return True, f"Activated {nep_id}, now at version {self.version}"
261
+
262
+ def check_peer_compatibility(
263
+ self,
264
+ peer_version: ProtocolVersion,
265
+ ) -> Tuple[CompatibilityLevel, str]:
266
+ """
267
+ Check if we can communicate with a peer.
268
+
269
+ Returns: (compatibility_level, message)
270
+ """
271
+ level = self.version.check_compatibility(peer_version)
272
+
273
+ messages = {
274
+ CompatibilityLevel.IDENTICAL: "Identical version",
275
+ CompatibilityLevel.COMPATIBLE: "Compatible versions",
276
+ CompatibilityLevel.UPGRADE_RECOMMENDED: (
277
+ f"Upgrade recommended: you have {self.version}, "
278
+ f"peer has {peer_version}"
279
+ ),
280
+ CompatibilityLevel.INCOMPATIBLE: (
281
+ f"Incompatible versions: you have {self.version}, "
282
+ f"peer has {peer_version}. Major version mismatch."
283
+ ),
284
+ }
285
+
286
+ return level, messages[level]
287
+
288
+ def can_participate_in_training(self) -> Tuple[bool, str]:
289
+ """
290
+ Check if we meet minimum requirements for training.
291
+ """
292
+ required_features = {"diloco", "ponw", "robust_aggregation"}
293
+ missing = required_features - self.version.features
294
+
295
+ if missing:
296
+ return False, f"Missing required features: {missing}"
297
+
298
+ return True, "Ready for training"
299
+
300
+ def can_participate_in_inference(self) -> Tuple[bool, str]:
301
+ """
302
+ Check if we meet minimum requirements for inference.
303
+ """
304
+ required_features = {"ponw", "inference_market"}
305
+ missing = required_features - self.version.features
306
+
307
+ if missing:
308
+ return False, f"Missing required features: {missing}"
309
+
310
+ return True, "Ready for inference"
311
+
312
+
313
+ # =============================================================================
314
+ # MODULE-LEVEL FUNCTIONS
315
+ # =============================================================================
316
+
317
+ def get_current_version() -> ProtocolVersion:
318
+ """Get the current protocol version."""
319
+ return CURRENT_VERSION
320
+
321
+
322
+ def is_compatible(
323
+ local_version: ProtocolVersion,
324
+ peer_version: ProtocolVersion,
325
+ ) -> bool:
326
+ """Check if two versions can communicate."""
327
+ level = local_version.check_compatibility(peer_version)
328
+ return level in [
329
+ CompatibilityLevel.IDENTICAL,
330
+ CompatibilityLevel.COMPATIBLE,
331
+ CompatibilityLevel.UPGRADE_RECOMMENDED,
332
+ ]