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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""NEXUS OS v2.1 β Production Hybrid Cloud+Local Inference with BEC Thermodynamic Control.
|
| 2 |
+
|
| 3 |
+
New in v2.1:
|
| 4 |
+
- Ollama telemetry extractor (embedding-space divergence for entropy proxy)
|
| 5 |
+
- ChimeraRouter v2.1 with integrated telemetry pipeline + cloud API adapters + fallback controller
|
| 6 |
+
- Production runner (run_production.py) β connects to real Ollama, Pinecone, Milvus
|
| 7 |
+
- EPR Detector (arXiv:2509.04492) β token-level entropy production rate
|
| 8 |
+
- Spilled Energy Detector (arXiv:2602.18671) β energy discrepancy hallucination signal
|
| 9 |
+
- Unified Thermodynamic Detector β fuses EPR + SpilledEnergy + CK-PLUG + TWAVE
|
| 10 |
+
- CombinedThermodynamicDetector β weighted ensemble with actionable recommendations
|
| 11 |
+
- Cloud API Adapters β DeepSeek, Qwen, Kimi, GLM, OpenAI, Claude
|
| 12 |
+
- Model Fallback Controller β auto-escalation: re-ground β backtrack β switch model β cloud
|
| 13 |
+
- Novel Composite Signals β Energy-Entropy Product (EEP), Phase Transition Index (PTI), NEWI
|
| 14 |
+
- Stochastic resonance optimal temperature computation per-request
|
| 15 |
+
- Post-hoc entropy estimation from completed responses
|
| 16 |
+
|
| 17 |
+
Core modules:
|
| 18 |
+
model_registry β 35+ real Ollama + cloud model profiles
|
| 19 |
+
sulphur_enhancer β Prompt quality optimization
|
| 20 |
+
ckplug_retriever β Token-level retrieval coupling (arXiv:2503.15888)
|
| 21 |
+
ckplug_presets β Epsilon presets for all 35+ models
|
| 22 |
+
twave_tracker β BEC Landau-Ginzburg thermodynamic tracking
|
| 23 |
+
epr_integration β Entropy Production Rate (arXiv:2509.04492)
|
| 24 |
+
epr_detector β Standalone EPR + WEPR detector
|
| 25 |
+
spilled_energy β Energy-based hallucination detection (arXiv:2602.18671)
|
| 26 |
+
unified_detector β Production unified detector (EPR + Spilled + CK-PLUG + TWAVE)
|
| 27 |
+
temperature_sweep_integration β Empirical T_c from Nemotron sweep
|
| 28 |
+
pinecone_client β Vector + Assistant retrieval (llama-text-embed-v2-index)
|
| 29 |
+
milvus_client β Zilliz Cloud retrieval (Free-01 / Serverless-01)
|
| 30 |
+
ernie_adapter β Browser-sourced manual callback (yiyan.baidu.com)
|
| 31 |
+
chimera_router β Hybrid orchestrator (QWAVE + TWAVE)
|
| 32 |
+
chimera_router_v2.1 β Telemetry-integrated production router + cloud + fallback
|
| 33 |
+
cloud_api_adapters β DeepSeek, Qwen, Kimi, GLM, OpenAI, Claude
|
| 34 |
+
gmr_scheduler β VRAM-aware model rotation
|
| 35 |
+
per_token_debug β Telemetry schema for token-level tracking
|
| 36 |
+
ollama_telemetry β Ollama stream + embedding divergence extractor
|
| 37 |
+
adpo_bec_training β ADPO-BEC training objective skeleton
|
| 38 |
+
trackio_integration β Experiment tracking, alerts, dashboard
|
| 39 |
+
run_production β Production runner with real credentials
|
| 40 |
+
demo_unified_detector β Interactive demo of all detection signals
|
| 41 |
+
cli β Command-line interface
|
| 42 |
+
|
| 43 |
+
Paper corpus (16 papers):
|
| 44 |
+
[1] Fast Byte Latent Transformer
|
| 45 |
+
[2] Cognitive Pivot Points / V-STAR / RVTD
|
| 46 |
+
[3] RLAR: Agentic Reward System
|
| 47 |
+
[4] Autoregressive DPO
|
| 48 |
+
[5] Unpacking DPO and PPO
|
| 49 |
+
[6] Disentangling Length from Quality in DPO
|
| 50 |
+
[7] Mechanistic Interpretability for AI Safety
|
| 51 |
+
[8] Critique-out-Loud Reward Models
|
| 52 |
+
[9] Understanding RLHF Effects on Generalisation
|
| 53 |
+
[10] Big Self-Supervised Models
|
| 54 |
+
[11] Discourse-Aware Attention for Summarization
|
| 55 |
+
[12] CK-PLUG (arXiv:2503.15888) β Confidence Gain
|
| 56 |
+
[13] SDE Self-Adversariality (arXiv:2501.16783) β Fokker-Planck validation
|
| 57 |
+
[14] EPR Hallucination Detection (arXiv:2509.04492) β Token-level entropy production
|
| 58 |
+
[15] Spilled Energy (arXiv:2602.18671) β Energy discrepancy in autoregressive EBMs
|
| 59 |
+
[16] PLDR-LLM Self-Organized Criticality (arXiv:2603.23539) β Order parameter at criticality
|
| 60 |
+
|
| 61 |
+
Usage (production):
|
| 62 |
+
export PINECONE_API_KEY="pcsk_J9DUW_..."
|
| 63 |
+
export OLLAMA_HOST="http://localhost:11434"
|
| 64 |
+
export DEEPSEEK_API_KEY="..."
|
| 65 |
+
export OPENAI_API_KEY="..."
|
| 66 |
+
export ANTHROPIC_API_KEY="..."
|
| 67 |
+
|
| 68 |
+
python -m nexus_os_v2.run_production \
|
| 69 |
+
--prompt "Explain quantum entanglement" \
|
| 70 |
+
--vram 16 \
|
| 71 |
+
--model deepseek-r1-8b \
|
| 72 |
+
--telemetry \
|
| 73 |
+
--use-pinecone \
|
| 74 |
+
--save-telemetry
|
| 75 |
+
|
| 76 |
+
Usage (unified detector demo):
|
| 77 |
+
python -m nexus_os_v2.demo_unified_detector --mode mock
|
| 78 |
+
|
| 79 |
+
Usage (benchmark):
|
| 80 |
+
python -m benchmarks.benchmark_real_models --vram 16 --auto-models --telemetry
|
| 81 |
+
|
| 82 |
+
Usage (calibrate):
|
| 83 |
+
python -m scripts.calibrate_detectors --model deepseek-r1-8b --iterations 3
|
| 84 |
+
|
| 85 |
+
Usage (basic):
|
| 86 |
+
from nexus_os_v2.chimera_router import ChimeraRouter, QWAVEBudget
|
| 87 |
+
router = ChimeraRouter()
|
| 88 |
+
result = router.route("Explain quantum computing")
|
| 89 |
+
print(result.response)
|
| 90 |
+
"""
|
| 91 |
+
__version__ = "2.1.0"
|
| 92 |
+
__author__ = "specimba"
|
| 93 |
+
|
| 94 |
+
from .model_registry import REGISTRY, SULPHUR, get, by_tier, by_cap, all_names, vram, Tier, Capability, ModelProfile
|
| 95 |
+
from .sulphur_enhancer import SulphurEnhancer, MockSulphurEnhancer, EnhancedPrompt
|
| 96 |
+
from .ckplug_retriever import CKPLUGCoupling, TokenModulation
|
| 97 |
+
from .ckplug_presets import get_ckplug_epsilon, get_all_presets, preset_summary
|
| 98 |
+
from .twave_tracker import TWAVETracker, TokenState, GenerationTrajectory, StochasticResonance
|
| 99 |
+
from .epr_integration import EPRCalculator, EPRAnalyzer, EPRTWWVEIntegration, TokenLogprob, quick_epr
|
| 100 |
+
from .epr_detector import EPRDetector, WEPRDetector, EPRReading, SequenceEPR
|
| 101 |
+
from .spilled_energy import SpilledEnergyDetector, SpilledEnergyReading, CombinedThermodynamicDetector
|
| 102 |
+
from .unified_detector import (
|
| 103 |
+
UnifiedThermodynamicDetector, FusionMode, Action,
|
| 104 |
+
DetectorReading, TokenVerdict, SequenceVerdict,
|
| 105 |
+
)
|
| 106 |
+
from .temperature_sweep_integration import TcCalibrator, EmpiricalTc, scale_Tc_for_family
|
| 107 |
+
from .pinecone_client import PineconeRetriever, MockPineconeRetriever, RetrievalResult
|
| 108 |
+
from .milvus_client import MilvusRetriever, MockMilvusRetriever, MilvusResult
|
| 109 |
+
from .ernie_adapter import ERNIEAdapter, MockERNIEAdapter, ERNIEEvidence
|
| 110 |
+
from .chimera_router import ChimeraRouter, QWAVEBudget, RouterResult, RoutingDecision
|
| 111 |
+
from .chimera_router_v2.1 import ChimeraRouterV2, ModelFallbackController
|
| 112 |
+
from .cloud_api_adapters import (
|
| 113 |
+
CloudAPIManager, BaseCloudAdapter, CloudResponse,
|
| 114 |
+
DeepSeekAdapter, QwenAdapter, KimiAdapter, GLMAdapter,
|
| 115 |
+
OpenAIAdapter, ClaudeAdapter,
|
| 116 |
+
)
|
| 117 |
+
from .gmr_scheduler import GMRScheduler, ModelSlot, LoadState
|
| 118 |
+
from .per_token_debug import PerTokenDebug, GenerationTelemetry
|
| 119 |
+
from .ollama_telemetry import (
|
| 120 |
+
OllamaTelemetryExtractor, OllamaStreamingClient,
|
| 121 |
+
TokenTelemetry, EmbeddingTrajectory, estimate_entropy_from_response,
|
| 122 |
+
)
|
| 123 |
+
from .adpo_bec_training import ADPOBEC, ADPOBECHyperparams, PreferencePair
|
| 124 |
+
from .trackio_integration import NEXUSTrackioMonitor, MockTrackioMonitor, TrackioConfig
|
| 125 |
+
|
| 126 |
+
__all__ = [
|
| 127 |
+
# Registry
|
| 128 |
+
"REGISTRY", "SULPHUR", "get", "by_tier", "by_cap", "all_names", "vram",
|
| 129 |
+
"Tier", "Capability", "ModelProfile",
|
| 130 |
+
# Enhancer
|
| 131 |
+
"SulphurEnhancer", "MockSulphurEnhancer", "EnhancedPrompt",
|
| 132 |
+
# CK-PLUG
|
| 133 |
+
"CKPLUGCoupling", "TokenModulation",
|
| 134 |
+
"get_ckplug_epsilon", "get_all_presets", "preset_summary",
|
| 135 |
+
# TWAVE
|
| 136 |
+
"TWAVETracker", "TokenState", "GenerationTrajectory", "StochasticResonance",
|
| 137 |
+
# EPR
|
| 138 |
+
"EPRCalculator", "EPRAnalyzer", "EPRTWWVEIntegration", "TokenLogprob", "quick_epr",
|
| 139 |
+
"EPRDetector", "WEPRDetector", "EPRReading", "SequenceEPR",
|
| 140 |
+
# Spilled Energy
|
| 141 |
+
"SpilledEnergyDetector", "SpilledEnergyReading", "CombinedThermodynamicDetector",
|
| 142 |
+
# Unified Detector
|
| 143 |
+
"UnifiedThermodynamicDetector", "FusionMode", "Action",
|
| 144 |
+
"DetectorReading", "TokenVerdict", "SequenceVerdict",
|
| 145 |
+
# Temperature Sweep
|
| 146 |
+
"TcCalibrator", "EmpiricalTc", "scale_Tc_for_family",
|
| 147 |
+
# Retrievers
|
| 148 |
+
"PineconeRetriever", "MockPineconeRetriever", "RetrievalResult",
|
| 149 |
+
"MilvusRetriever", "MockMilvusRetriever", "MilvusResult",
|
| 150 |
+
"ERNIEAdapter", "MockERNIEAdapter", "ERNIEEvidence",
|
| 151 |
+
# Routers
|
| 152 |
+
"ChimeraRouter", "ChimeraRouterV2", "ModelFallbackController",
|
| 153 |
+
"QWAVEBudget", "RouterResult", "RoutingDecision",
|
| 154 |
+
# Cloud APIs
|
| 155 |
+
"CloudAPIManager", "BaseCloudAdapter", "CloudResponse",
|
| 156 |
+
"DeepSeekAdapter", "QwenAdapter", "KimiAdapter", "GLMAdapter",
|
| 157 |
+
"OpenAIAdapter", "ClaudeAdapter",
|
| 158 |
+
# GMR
|
| 159 |
+
"GMRScheduler", "ModelSlot", "LoadState",
|
| 160 |
+
# Telemetry
|
| 161 |
+
"PerTokenDebug", "GenerationTelemetry",
|
| 162 |
+
"OllamaTelemetryExtractor", "OllamaStreamingClient",
|
| 163 |
+
"TokenTelemetry", "EmbeddingTrajectory", "estimate_entropy_from_response",
|
| 164 |
+
# Training
|
| 165 |
+
"ADPOBEC", "ADPOBECHyperparams", "PreferencePair",
|
| 166 |
+
# Monitoring
|
| 167 |
+
"NEXUSTrackioMonitor", "MockTrackioMonitor", "TrackioConfig",
|
| 168 |
+
]
|