alphared 0.1.0__tar.gz

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.
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: alphared
3
+ Version: 0.1.0
4
+ Summary: A lightweight SDK for logging ML experiments to AlphaRed.
5
+ Author: AlphaRed Team
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.7
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: requests
12
+ Requires-Dist: psutil
13
+ Provides-Extra: gpu
14
+ Requires-Dist: pynvml; extra == "gpu"
15
+ Dynamic: author
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: provides-extra
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ # AlphaRed SDK
25
+
26
+ A lightweight, professional SDK for logging machine learning experiments to the AlphaRed platform.
27
+
28
+ ## Features
29
+ - 🚀 **Real-time Metrics**: Log loss, accuracy, and custom metrics in the background.
30
+ - 📊 **Auto-Telemetry**: Automatically track CPU, RAM, and Disk metrics.
31
+ - ⚡ **Non-blocking**: Multi-threaded logging ensures your training script speed isn't affected.
32
+
33
+ ## Installation
34
+ ```bash
35
+ pip install alphared
36
+ ```
37
+
38
+ ## Quick Start
39
+ ```python
40
+ import alphared
41
+
42
+ # Initialize the project
43
+ alphared.init(project="my-mnist-project")
44
+
45
+ # Your training loop
46
+ for epoch in range(10):
47
+ # ... training logic ...
48
+ alphared.log({"epoch": epoch, "loss": 0.5, "accuracy": 0.85})
49
+
50
+ # Finalize the run
51
+ alphared.finish()
52
+ ```
@@ -0,0 +1,29 @@
1
+ # AlphaRed SDK
2
+
3
+ A lightweight, professional SDK for logging machine learning experiments to the AlphaRed platform.
4
+
5
+ ## Features
6
+ - 🚀 **Real-time Metrics**: Log loss, accuracy, and custom metrics in the background.
7
+ - 📊 **Auto-Telemetry**: Automatically track CPU, RAM, and Disk metrics.
8
+ - ⚡ **Non-blocking**: Multi-threaded logging ensures your training script speed isn't affected.
9
+
10
+ ## Installation
11
+ ```bash
12
+ pip install alphared
13
+ ```
14
+
15
+ ## Quick Start
16
+ ```python
17
+ import alphared
18
+
19
+ # Initialize the project
20
+ alphared.init(project="my-mnist-project")
21
+
22
+ # Your training loop
23
+ for epoch in range(10):
24
+ # ... training logic ...
25
+ alphared.log({"epoch": epoch, "loss": 0.5, "accuracy": 0.85})
26
+
27
+ # Finalize the run
28
+ alphared.finish()
29
+ ```
@@ -0,0 +1,32 @@
1
+ from .session import RunSession
2
+
3
+ _global_run = None
4
+
5
+ def init(project=None, name=None, api_key=None, host="http://localhost:8000"):
6
+ """
7
+ Initializes a new experiment run with AlphaRed.
8
+
9
+ Args:
10
+ project (str): Name of the project.
11
+ name (str): Optional name for this specific run.
12
+ api_key (str): Your AlphaRed API Key.
13
+ host (str): The backend host URL.
14
+ """
15
+ global _global_run
16
+ _global_run = RunSession(project=project, name=name, api_key=api_key, host=host)
17
+ _global_run.start()
18
+ return _global_run
19
+
20
+ def log(metrics: dict):
21
+ """Logs metrics to the active global run."""
22
+ if _global_run is None:
23
+ print("⚠️ [AlphaRed] Warning: You must call alphared.init() before logging. Metric ignored.")
24
+ return
25
+ _global_run.log(metrics)
26
+
27
+ def finish():
28
+ """Finalizes the active run."""
29
+ global _global_run
30
+ if _global_run:
31
+ _global_run.finish()
32
+ _global_run = None
@@ -0,0 +1,100 @@
1
+ import threading
2
+ import time
3
+ import requests
4
+ import queue
5
+ import uuid
6
+ from .utils.system_telemetry import get_system_metrics
7
+
8
+ class RunSession:
9
+ def __init__(self, project, name=None, api_key=None, host="http://localhost:8000"):
10
+ self.project = project
11
+ self.name = name or f"run-{uuid.uuid4().hex[:6]}"
12
+ self.api_key = api_key
13
+ self.host = host.rstrip('/')
14
+ self.run_id = None
15
+ self.running = False
16
+ self._queue = queue.Queue()
17
+ self._thread = None
18
+ self._telemetry_thread = None
19
+
20
+ def start(self):
21
+ """Initializes the run on the backend and starts background threads."""
22
+ try:
23
+ response = requests.post(
24
+ f"{self.host}/api/sdk/init",
25
+ json={
26
+ "project": self.project,
27
+ "name": self.name,
28
+ "api_key": self.api_key
29
+ },
30
+ timeout=5
31
+ )
32
+ if response.status_code == 200:
33
+ data = response.json()
34
+ self.run_id = data.get("run_id")
35
+ self.running = True
36
+
37
+ # Start background log consumer
38
+ self._thread = threading.Thread(target=self._worker, daemon=True)
39
+ self._thread.start()
40
+
41
+ # Start background telemetry
42
+ self._telemetry_thread = threading.Thread(target=self._telemetry_worker, daemon=True)
43
+ self._telemetry_thread.start()
44
+
45
+ print(f"🚀 [AlphaRed] Run initialized: {self.run_id}")
46
+ print(f"📊 [AlphaRed] View dashboard at: {self.host}/runs/{self.run_id}")
47
+ else:
48
+ print(f"❌ [AlphaRed] Failed to initialize run: {response.text}")
49
+ except Exception as e:
50
+ print(f"❌ [AlphaRed] Error connecting to backend: {e}")
51
+
52
+ def log(self, metrics):
53
+ """Adds metrics to the processing queue."""
54
+ if not self.running:
55
+ return
56
+ self._queue.put({"type": "metrics", "data": metrics, "timestamp": time.time()})
57
+
58
+ def finish(self):
59
+ """Stops the session and flushes pending data."""
60
+ self.running = False
61
+ if self._thread:
62
+ self._thread.join(timeout=2)
63
+ print(f"✨ [AlphaRed] Run {self.run_id} completed.")
64
+
65
+ def _worker(self):
66
+ """Consumes metrics from the queue and sends them to the backend."""
67
+ while self.running or not self._queue.empty():
68
+ try:
69
+ item = self._queue.get(timeout=1)
70
+ self._send_payload(item)
71
+ self._queue.task_done()
72
+ except queue.Empty:
73
+ continue
74
+ except Exception as e:
75
+ print(f"⚠️ [AlphaRed] Log error: {e}")
76
+
77
+ def _telemetry_worker(self):
78
+ """Gathers system telemetry (CPU, GPU) every 5 seconds."""
79
+ while self.running:
80
+ try:
81
+ metrics = get_system_metrics()
82
+ self._send_payload({"type": "telemetry", "data": metrics, "timestamp": time.time()})
83
+ time.sleep(5)
84
+ except Exception as e:
85
+ print(f"⚠️ [AlphaRed] Telemetry error: {e}")
86
+ time.sleep(10)
87
+
88
+ def _send_payload(self, payload):
89
+ """Sends data to the backend."""
90
+ if not self.run_id:
91
+ return
92
+ try:
93
+ requests.post(
94
+ f"{self.host}/api/sdk/runs/{self.run_id}/log",
95
+ json=payload,
96
+ headers={"X-API-KEY": self.api_key} if self.api_key else {},
97
+ timeout=5
98
+ )
99
+ except Exception:
100
+ pass # Silent failure to not interrupt user training
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: alphared
3
+ Version: 0.1.0
4
+ Summary: A lightweight SDK for logging ML experiments to AlphaRed.
5
+ Author: AlphaRed Team
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.7
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: requests
12
+ Requires-Dist: psutil
13
+ Provides-Extra: gpu
14
+ Requires-Dist: pynvml; extra == "gpu"
15
+ Dynamic: author
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: provides-extra
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ # AlphaRed SDK
25
+
26
+ A lightweight, professional SDK for logging machine learning experiments to the AlphaRed platform.
27
+
28
+ ## Features
29
+ - 🚀 **Real-time Metrics**: Log loss, accuracy, and custom metrics in the background.
30
+ - 📊 **Auto-Telemetry**: Automatically track CPU, RAM, and Disk metrics.
31
+ - ⚡ **Non-blocking**: Multi-threaded logging ensures your training script speed isn't affected.
32
+
33
+ ## Installation
34
+ ```bash
35
+ pip install alphared
36
+ ```
37
+
38
+ ## Quick Start
39
+ ```python
40
+ import alphared
41
+
42
+ # Initialize the project
43
+ alphared.init(project="my-mnist-project")
44
+
45
+ # Your training loop
46
+ for epoch in range(10):
47
+ # ... training logic ...
48
+ alphared.log({"epoch": epoch, "loss": 0.5, "accuracy": 0.85})
49
+
50
+ # Finalize the run
51
+ alphared.finish()
52
+ ```
@@ -0,0 +1,9 @@
1
+ README.md
2
+ setup.py
3
+ alphared/__init__.py
4
+ alphared/session.py
5
+ alphared.egg-info/PKG-INFO
6
+ alphared.egg-info/SOURCES.txt
7
+ alphared.egg-info/dependency_links.txt
8
+ alphared.egg-info/requires.txt
9
+ alphared.egg-info/top_level.txt
@@ -0,0 +1,5 @@
1
+ requests
2
+ psutil
3
+
4
+ [gpu]
5
+ pynvml
@@ -0,0 +1 @@
1
+ alphared
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,29 @@
1
+ from setuptools import setup, find_packages
2
+ import os
3
+
4
+ # Read the README for the long description
5
+ with open(os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf-8") as f:
6
+ long_description = f.read()
7
+
8
+ setup(
9
+ name="alphared",
10
+ version="0.1.0",
11
+ packages=find_packages(),
12
+ install_requires=[
13
+ "requests",
14
+ "psutil",
15
+ ],
16
+ extras_require={
17
+ "gpu": ["pynvml"],
18
+ },
19
+ author="AlphaRed Team",
20
+ description="A lightweight SDK for logging ML experiments to AlphaRed.",
21
+ long_description=long_description,
22
+ long_description_content_type="text/markdown",
23
+ classifiers=[
24
+ "Programming Language :: Python :: 3",
25
+ "License :: OSI Approved :: MIT License",
26
+ "Operating System :: OS Independent",
27
+ ],
28
+ python_requires='>=3.7',
29
+ )