mangosta 0.1.0a1__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.
- mangosta-0.1.0a1/.github/workflows/publish.yml +35 -0
- mangosta-0.1.0a1/.gitignore +49 -0
- mangosta-0.1.0a1/LICENSE +21 -0
- mangosta-0.1.0a1/PKG-INFO +304 -0
- mangosta-0.1.0a1/README.md +279 -0
- mangosta-0.1.0a1/examples/cnn_checkpoint_resume.py +191 -0
- mangosta-0.1.0a1/examples/lifecycle_demo.py +198 -0
- mangosta-0.1.0a1/examples/multitask_onnx_export.py +142 -0
- mangosta-0.1.0a1/pyproject.toml +75 -0
- mangosta-0.1.0a1/skills/mangosta/SKILL.md +175 -0
- mangosta-0.1.0a1/src/mangosta/__init__.py +77 -0
- mangosta-0.1.0a1/src/mangosta/artifacts/__init__.py +23 -0
- mangosta-0.1.0a1/src/mangosta/artifacts/bundle.py +184 -0
- mangosta-0.1.0a1/src/mangosta/artifacts/loader.py +223 -0
- mangosta-0.1.0a1/src/mangosta/cli/__init__.py +17 -0
- mangosta-0.1.0a1/src/mangosta/cli/main.py +229 -0
- mangosta-0.1.0a1/src/mangosta/core/__init__.py +23 -0
- mangosta-0.1.0a1/src/mangosta/core/registry.py +188 -0
- mangosta-0.1.0a1/src/mangosta/core/schema.py +307 -0
- mangosta-0.1.0a1/src/mangosta/exceptions.py +43 -0
- mangosta-0.1.0a1/src/mangosta/export/__init__.py +9 -0
- mangosta-0.1.0a1/src/mangosta/export/onnx.py +227 -0
- mangosta-0.1.0a1/src/mangosta/tracking/__init__.py +17 -0
- mangosta-0.1.0a1/src/mangosta/tracking/report.py +320 -0
- mangosta-0.1.0a1/src/mangosta/tracking/tracker.py +231 -0
- mangosta-0.1.0a1/tests/__init__.py +1 -0
- mangosta-0.1.0a1/tests/conftest.py +64 -0
- mangosta-0.1.0a1/tests/test_bundle.py +92 -0
- mangosta-0.1.0a1/tests/test_cli.py +53 -0
- mangosta-0.1.0a1/tests/test_exporter.py +122 -0
- mangosta-0.1.0a1/tests/test_loader.py +136 -0
- mangosta-0.1.0a1/tests/test_registry.py +114 -0
- mangosta-0.1.0a1/tests/test_report.py +57 -0
- mangosta-0.1.0a1/tests/test_schema.py +122 -0
- mangosta-0.1.0a1/tests/test_tracker.py +102 -0
- mangosta-0.1.0a1/uv.lock +1190 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build-and-publish:
|
|
10
|
+
name: Build distribution and publish to PyPI
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment:
|
|
13
|
+
name: pypi
|
|
14
|
+
url: https://pypi.org/p/mangosta
|
|
15
|
+
permissions:
|
|
16
|
+
id-token: write
|
|
17
|
+
contents: read
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout repository
|
|
21
|
+
uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- name: Install uv
|
|
24
|
+
uses: astral-sh/setup-uv@v3
|
|
25
|
+
with:
|
|
26
|
+
version: "latest"
|
|
27
|
+
|
|
28
|
+
- name: Set up Python
|
|
29
|
+
run: uv python install 3.12
|
|
30
|
+
|
|
31
|
+
- name: Build distributions
|
|
32
|
+
run: uv build
|
|
33
|
+
|
|
34
|
+
- name: Publish to PyPI
|
|
35
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Python & Virtual Environments
|
|
2
|
+
.venv/
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
*$py.class
|
|
6
|
+
*.so
|
|
7
|
+
.Python
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
build/
|
|
11
|
+
develop-eggs/
|
|
12
|
+
dist/
|
|
13
|
+
downloads/
|
|
14
|
+
eggs/
|
|
15
|
+
.eggs/
|
|
16
|
+
lib/
|
|
17
|
+
lib64/
|
|
18
|
+
parts/
|
|
19
|
+
sdist/
|
|
20
|
+
var/
|
|
21
|
+
wheels/
|
|
22
|
+
share/python-wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
MANIFEST
|
|
27
|
+
|
|
28
|
+
# Testing & Coverage
|
|
29
|
+
.pytest_cache/
|
|
30
|
+
.coverage
|
|
31
|
+
.coverage.*
|
|
32
|
+
htmlcov/
|
|
33
|
+
|
|
34
|
+
# Demo artifacts & local runs
|
|
35
|
+
demo_artifacts/
|
|
36
|
+
experiments/
|
|
37
|
+
*.bundle
|
|
38
|
+
*.bundle.tmp*
|
|
39
|
+
report.html
|
|
40
|
+
|
|
41
|
+
# Local agent development & planning files
|
|
42
|
+
.agents/
|
|
43
|
+
tasks/
|
|
44
|
+
SPEC.md
|
|
45
|
+
|
|
46
|
+
# Screenshot & local media
|
|
47
|
+
*.png
|
|
48
|
+
*.jpg
|
|
49
|
+
*.jpeg
|
mangosta-0.1.0a1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yeriel Paz Ureta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mangosta
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Lightweight MLOps and model lifecycle management for PyTorch
|
|
5
|
+
Author: Mangosta Developers
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: checkpointing,mlops,model-registry,pytorch,tracking
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: packaging>=23.0
|
|
20
|
+
Requires-Dist: pyyaml>=6.0
|
|
21
|
+
Requires-Dist: torch>=2.0.0
|
|
22
|
+
Provides-Extra: onnx
|
|
23
|
+
Requires-Dist: onnx>=1.14.0; extra == 'onnx'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# mangosta
|
|
27
|
+
|
|
28
|
+
**Lightweight MLOps and Model Lifecycle Management for PyTorch.**
|
|
29
|
+
|
|
30
|
+
> *"Simple by default, strict on demand"* - Functional in three lines of code for rapid experimentation, yet robust enough for production pipelines and autonomous AI agents through formal contracts, deterministic fault tolerance, and immutable architecture versioning.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Overview
|
|
35
|
+
|
|
36
|
+
Modern MLOps frameworks frequently impose heavy operational complexity: daemon background services, external databases, cloud platform dependencies, and brittle networking setups.
|
|
37
|
+
|
|
38
|
+
`mangosta` is engineered to provide local-first, serverless model lifecycle primitives directly within Python and standard file systems. It eliminates infrastructure overhead while delivering strict guarantees regarding reproducibility, tensor contracts, and crash-consistent persistence.
|
|
39
|
+
|
|
40
|
+
### Architectural Principles
|
|
41
|
+
|
|
42
|
+
- **Zero Service Dependencies**: No background daemons, web servers, or remote databases. All operations use direct, atomic file system calls (JSONL, standard ZIP archives, and optional SQLite).
|
|
43
|
+
- **Strict Immutability**: Architectures registered in `ModelRegistry` cannot be silently overwritten, preventing silent behavioral divergence between training runs.
|
|
44
|
+
- **Contract-Driven Inference**: Non-invasive tensor signature inference captures shapes (including dynamic batch dimensions) and data types, enforcing runtime verification before execution.
|
|
45
|
+
- **Deterministic Fault Tolerance**: Checkpoints capture complete training state including optimizer parameters, learning rate schedulers, gradient scalers, and pseudo-random number generator (RNG) states across Python, PyTorch (CPU and CUDA), and NumPy.
|
|
46
|
+
- **Decoupled Production Export**: Development artifacts (`.bundle`) remain optimized for training continuity and auditability, while standalone production formats (such as ONNX) are cleanly exported with full user control over dynamic axes, precision, and output restructuring.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Comparison with Existing Tools
|
|
51
|
+
|
|
52
|
+
| Capability | mangosta | MLflow | Weights & Biases | ClearML |
|
|
53
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
54
|
+
| **Infrastructure Overhead** | None (Local files only) | Local/Remote server | Cloud daemon / SaaS | Server / Agent daemon |
|
|
55
|
+
| **External Services Required** | Zero | Web server + DB | API backend | Server stack + DB |
|
|
56
|
+
| **Persistence Mechanism** | Atomic JSONL & ZIP | SQLite / File store | Cloud storage | MongoDB / MinIO |
|
|
57
|
+
| **Fault-Tolerant RNG Restoration** | Native (CPU, CUDA, NumPy, Py) | Manual | Manual | Manual |
|
|
58
|
+
| **Tensor Contract Validation** | Native (Pre-inference) | Signature schema | Logged schema only | Logged schema only |
|
|
59
|
+
| **Packaging Architecture** | Modular (KISS & SOLID) | Monolithic package | Monolithic client | Complex SDK |
|
|
60
|
+
| **Offline Operation** | 100% Offline | Partial | Requires offline mode | Requires local server |
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
Install using `uv` (recommended):
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
uv add mangosta
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or using standard `pip`:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install mangosta
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Optional Dependencies
|
|
79
|
+
|
|
80
|
+
For ONNX graph verification using `onnx.checker`:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
uv add "mangosta[onnx]"
|
|
84
|
+
# or
|
|
85
|
+
pip install "mangosta[onnx]"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Quickstart
|
|
91
|
+
|
|
92
|
+
### 1. Atomic Local Tracking
|
|
93
|
+
|
|
94
|
+
Track hyperparameters and step-level metrics with atomic disk flushing:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from mangosta import quick_track
|
|
98
|
+
|
|
99
|
+
with quick_track(experiment="vision", run_name="baseline_resnet") as run:
|
|
100
|
+
run.log_params({"learning_rate": 1e-3, "batch_size": 32, "weight_decay": 1e-4})
|
|
101
|
+
run.set_dataset("data/processed_images.parquet")
|
|
102
|
+
|
|
103
|
+
for epoch in range(10):
|
|
104
|
+
# Training iteration ...
|
|
105
|
+
run.log_metric("train_loss", 0.342, step=epoch)
|
|
106
|
+
run.log_metric("val_accuracy", 0.912, step=epoch)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 2. Architecture Registration
|
|
110
|
+
|
|
111
|
+
Register neural network architectures under a family name and semantic version:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
import torch
|
|
115
|
+
import torch.nn as nn
|
|
116
|
+
from mangosta import register_model
|
|
117
|
+
|
|
118
|
+
@register_model(family="classifier", version="1.0.0")
|
|
119
|
+
class ConvClassifier(nn.Module):
|
|
120
|
+
def __init__(self, in_channels: int = 3, num_classes: int = 10) -> None:
|
|
121
|
+
super().__init__()
|
|
122
|
+
self.encoder = nn.Sequential(
|
|
123
|
+
nn.Conv2d(in_channels, 16, kernel_size=3, padding=1),
|
|
124
|
+
nn.ReLU(),
|
|
125
|
+
nn.AdaptiveAvgPool2d((1, 1)),
|
|
126
|
+
)
|
|
127
|
+
self.head = nn.Linear(16, num_classes)
|
|
128
|
+
|
|
129
|
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
130
|
+
return self.head(self.encoder(x).flatten(1))
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 3. Checkpointing and Fault-Tolerant Resumption
|
|
134
|
+
|
|
135
|
+
Save complete training state including optimizer, scheduler, and all random generator states:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from mangosta import save_bundle, resume_training, ModelRegistry
|
|
139
|
+
|
|
140
|
+
# Save crash-consistent checkpoint
|
|
141
|
+
save_bundle(
|
|
142
|
+
output_path="checkpoints/epoch_5.bundle",
|
|
143
|
+
model=model,
|
|
144
|
+
family="classifier",
|
|
145
|
+
version="1.0.0",
|
|
146
|
+
init_args={"in_channels": 3, "num_classes": 10},
|
|
147
|
+
sample_input=torch.randn(1, 3, 32, 32),
|
|
148
|
+
is_checkpoint=True,
|
|
149
|
+
optimizer=optimizer,
|
|
150
|
+
scheduler=scheduler,
|
|
151
|
+
epoch=5,
|
|
152
|
+
step=1250,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
# Resume deterministically following an interruption
|
|
156
|
+
fresh_model = ModelRegistry.build("classifier", version="1.0.0", in_channels=3, num_classes=10)
|
|
157
|
+
fresh_optimizer = torch.optim.Adam(fresh_model.parameters(), lr=1e-3)
|
|
158
|
+
fresh_scheduler = torch.optim.lr_scheduler.StepLR(fresh_optimizer, step_size=5)
|
|
159
|
+
|
|
160
|
+
state = resume_training(
|
|
161
|
+
bundle_path="checkpoints/epoch_5.bundle",
|
|
162
|
+
model=fresh_model,
|
|
163
|
+
optimizer=fresh_optimizer,
|
|
164
|
+
scheduler=fresh_scheduler,
|
|
165
|
+
restore_rng=True,
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
start_epoch = state.epoch + 1
|
|
169
|
+
start_step = state.step
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 4. Decoupled Production Inference
|
|
173
|
+
|
|
174
|
+
Load models dynamically without importing the underlying model class in your serving scripts:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
import torch
|
|
178
|
+
from mangosta import load_bundle
|
|
179
|
+
|
|
180
|
+
# Reconstructs architecture via registry and mounts weights
|
|
181
|
+
bundle = load_bundle("artifacts/model_final.bundle")
|
|
182
|
+
|
|
183
|
+
# Inference with automated input signature validation
|
|
184
|
+
input_tensor = torch.randn(4, 3, 32, 32)
|
|
185
|
+
predictions = bundle.predict(input_tensor)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### 5. Standalone ONNX Export
|
|
189
|
+
|
|
190
|
+
Export directly to standard ONNX with automatic dictionary-to-tuple output unrolling and float16 precision:
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
from mangosta import export_onnx
|
|
194
|
+
|
|
195
|
+
export_onnx(
|
|
196
|
+
model_or_bundle="artifacts/model_final.bundle",
|
|
197
|
+
output_path="exports/model.onnx",
|
|
198
|
+
sample_input_shape=(1, 3, 512, 512),
|
|
199
|
+
output_mapping=["semantic_mask", "radius_map", "gradient_map"],
|
|
200
|
+
input_names=["input0"],
|
|
201
|
+
output_names=["output0", "output1", "output2"],
|
|
202
|
+
dynamic_axes={
|
|
203
|
+
"input0": {0: "batch", 2: "height", 3: "width"},
|
|
204
|
+
"output0": {0: "batch", 2: "height", 3: "width"},
|
|
205
|
+
"output1": {0: "batch", 2: "height", 3: "width"},
|
|
206
|
+
"output2": {0: "batch", 2: "height", 3: "width"},
|
|
207
|
+
},
|
|
208
|
+
float16=True,
|
|
209
|
+
opset_version=18,
|
|
210
|
+
verify=True,
|
|
211
|
+
)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Command Line Interface (CLI)
|
|
217
|
+
|
|
218
|
+
`mangosta` provides a zero-daemon CLI utility:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Inspect internal bundle contents, tensor signatures, and metadata
|
|
222
|
+
mangosta inspect checkpoints/epoch_5.bundle
|
|
223
|
+
|
|
224
|
+
# Generate a self-contained, offline interactive HTML report
|
|
225
|
+
mangosta report experiments/vision/baseline_resnet -o report.html
|
|
226
|
+
mangosta report checkpoints/epoch_5.bundle -o report.html
|
|
227
|
+
|
|
228
|
+
# Launch an ephemeral browser viewer (terminates cleanly with Ctrl+C)
|
|
229
|
+
mangosta view ./experiments --port 8501
|
|
230
|
+
|
|
231
|
+
# Export a bundle directly to ONNX from the terminal
|
|
232
|
+
mangosta export-onnx checkpoints/epoch_5.bundle -o model.onnx --fp16 --input-shape 1 3 32 32 -m models.classifier
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Package Architecture
|
|
238
|
+
|
|
239
|
+
The library follows Single Responsibility (SRP) and Open-Closed (OCP) design principles:
|
|
240
|
+
|
|
241
|
+
```text
|
|
242
|
+
src/mangosta/
|
|
243
|
+
|-- __init__.py # Unified high-level public API
|
|
244
|
+
|-- exceptions.py # Domain-specific exception hierarchy
|
|
245
|
+
|-- core/ # Architecture registry and tensor contracts
|
|
246
|
+
| |-- registry.py # ModelRegistry, @register_model, dynamic SemVer resolution
|
|
247
|
+
| `-- schema.py # TensorSpec, ModelSchema, infer_schema
|
|
248
|
+
|-- artifacts/ # Persistence, atomic packaging, and loading
|
|
249
|
+
| |-- bundle.py # Atomic ZIP creation, RNG serialization, checkpointing
|
|
250
|
+
| `-- loader.py # Decoupled reconstruction, LoadedBundle, resume_training
|
|
251
|
+
|-- tracking/ # Experiment tracking and lineage
|
|
252
|
+
| |-- tracker.py # RunTracker, quick_track, SHA-256 dataset fingerprinting
|
|
253
|
+
| `-- report.py # Offline interactive HTML report generator
|
|
254
|
+
|-- export/ # Standalone production exports
|
|
255
|
+
| `-- onnx.py # ONNX exporter, dictionary unrolling, precision handling
|
|
256
|
+
`-- cli/ # Command-line interface
|
|
257
|
+
`-- main.py # CLI entrypoints (inspect, report, view, export-onnx)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## AI Agent Integration (Gemini / Antigravity Skill)
|
|
263
|
+
|
|
264
|
+
`mangosta` provides a production-grade Agent Skill designed for LLMs (Google Gemini, Antigravity CLI, Claude, OpenAI). The skill equips AI coding agents with the exact runbooks, API contracts, and defensive patterns needed to manage models autonomously without hallucinating commands or corrupting checkpoint states.
|
|
265
|
+
|
|
266
|
+
### Installing the Skill in Your Project
|
|
267
|
+
|
|
268
|
+
To make your local AI agent an expert in `mangosta`, copy the public skill specification to your workspace customization folder:
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
mkdir -p .agents/skills/mangosta
|
|
272
|
+
cp skills/mangosta/SKILL.md .agents/skills/mangosta/SKILL.md
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Once installed, AI coding agents automatically discover the skill via its standard YAML frontmatter:
|
|
276
|
+
- **Scope**: Automated model registration, contract validation, checkpoint recovery, and ONNX exports.
|
|
277
|
+
- **Location in repository**: [`skills/mangosta/SKILL.md`](file:///home/yeriel/Workspace/mangosta/skills/mangosta/SKILL.md)
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Development
|
|
282
|
+
|
|
283
|
+
Run tests and verification suites locally:
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
# Sync virtual environment
|
|
287
|
+
uv sync
|
|
288
|
+
|
|
289
|
+
# Run automated tests with coverage
|
|
290
|
+
uv run pytest -v --cov=mangosta
|
|
291
|
+
|
|
292
|
+
# Run linter and formatting checks
|
|
293
|
+
uv run ruff check src tests examples
|
|
294
|
+
uv run ruff format --check src tests examples
|
|
295
|
+
|
|
296
|
+
# Build package distributions (sdist and wheel)
|
|
297
|
+
uv build
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## License
|
|
303
|
+
|
|
304
|
+
MIT License.
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# mangosta
|
|
2
|
+
|
|
3
|
+
**Lightweight MLOps and Model Lifecycle Management for PyTorch.**
|
|
4
|
+
|
|
5
|
+
> *"Simple by default, strict on demand"* - Functional in three lines of code for rapid experimentation, yet robust enough for production pipelines and autonomous AI agents through formal contracts, deterministic fault tolerance, and immutable architecture versioning.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Modern MLOps frameworks frequently impose heavy operational complexity: daemon background services, external databases, cloud platform dependencies, and brittle networking setups.
|
|
12
|
+
|
|
13
|
+
`mangosta` is engineered to provide local-first, serverless model lifecycle primitives directly within Python and standard file systems. It eliminates infrastructure overhead while delivering strict guarantees regarding reproducibility, tensor contracts, and crash-consistent persistence.
|
|
14
|
+
|
|
15
|
+
### Architectural Principles
|
|
16
|
+
|
|
17
|
+
- **Zero Service Dependencies**: No background daemons, web servers, or remote databases. All operations use direct, atomic file system calls (JSONL, standard ZIP archives, and optional SQLite).
|
|
18
|
+
- **Strict Immutability**: Architectures registered in `ModelRegistry` cannot be silently overwritten, preventing silent behavioral divergence between training runs.
|
|
19
|
+
- **Contract-Driven Inference**: Non-invasive tensor signature inference captures shapes (including dynamic batch dimensions) and data types, enforcing runtime verification before execution.
|
|
20
|
+
- **Deterministic Fault Tolerance**: Checkpoints capture complete training state including optimizer parameters, learning rate schedulers, gradient scalers, and pseudo-random number generator (RNG) states across Python, PyTorch (CPU and CUDA), and NumPy.
|
|
21
|
+
- **Decoupled Production Export**: Development artifacts (`.bundle`) remain optimized for training continuity and auditability, while standalone production formats (such as ONNX) are cleanly exported with full user control over dynamic axes, precision, and output restructuring.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Comparison with Existing Tools
|
|
26
|
+
|
|
27
|
+
| Capability | mangosta | MLflow | Weights & Biases | ClearML |
|
|
28
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
29
|
+
| **Infrastructure Overhead** | None (Local files only) | Local/Remote server | Cloud daemon / SaaS | Server / Agent daemon |
|
|
30
|
+
| **External Services Required** | Zero | Web server + DB | API backend | Server stack + DB |
|
|
31
|
+
| **Persistence Mechanism** | Atomic JSONL & ZIP | SQLite / File store | Cloud storage | MongoDB / MinIO |
|
|
32
|
+
| **Fault-Tolerant RNG Restoration** | Native (CPU, CUDA, NumPy, Py) | Manual | Manual | Manual |
|
|
33
|
+
| **Tensor Contract Validation** | Native (Pre-inference) | Signature schema | Logged schema only | Logged schema only |
|
|
34
|
+
| **Packaging Architecture** | Modular (KISS & SOLID) | Monolithic package | Monolithic client | Complex SDK |
|
|
35
|
+
| **Offline Operation** | 100% Offline | Partial | Requires offline mode | Requires local server |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
Install using `uv` (recommended):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
uv add mangosta
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or using standard `pip`:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install mangosta
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Optional Dependencies
|
|
54
|
+
|
|
55
|
+
For ONNX graph verification using `onnx.checker`:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
uv add "mangosta[onnx]"
|
|
59
|
+
# or
|
|
60
|
+
pip install "mangosta[onnx]"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Quickstart
|
|
66
|
+
|
|
67
|
+
### 1. Atomic Local Tracking
|
|
68
|
+
|
|
69
|
+
Track hyperparameters and step-level metrics with atomic disk flushing:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from mangosta import quick_track
|
|
73
|
+
|
|
74
|
+
with quick_track(experiment="vision", run_name="baseline_resnet") as run:
|
|
75
|
+
run.log_params({"learning_rate": 1e-3, "batch_size": 32, "weight_decay": 1e-4})
|
|
76
|
+
run.set_dataset("data/processed_images.parquet")
|
|
77
|
+
|
|
78
|
+
for epoch in range(10):
|
|
79
|
+
# Training iteration ...
|
|
80
|
+
run.log_metric("train_loss", 0.342, step=epoch)
|
|
81
|
+
run.log_metric("val_accuracy", 0.912, step=epoch)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 2. Architecture Registration
|
|
85
|
+
|
|
86
|
+
Register neural network architectures under a family name and semantic version:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import torch
|
|
90
|
+
import torch.nn as nn
|
|
91
|
+
from mangosta import register_model
|
|
92
|
+
|
|
93
|
+
@register_model(family="classifier", version="1.0.0")
|
|
94
|
+
class ConvClassifier(nn.Module):
|
|
95
|
+
def __init__(self, in_channels: int = 3, num_classes: int = 10) -> None:
|
|
96
|
+
super().__init__()
|
|
97
|
+
self.encoder = nn.Sequential(
|
|
98
|
+
nn.Conv2d(in_channels, 16, kernel_size=3, padding=1),
|
|
99
|
+
nn.ReLU(),
|
|
100
|
+
nn.AdaptiveAvgPool2d((1, 1)),
|
|
101
|
+
)
|
|
102
|
+
self.head = nn.Linear(16, num_classes)
|
|
103
|
+
|
|
104
|
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
105
|
+
return self.head(self.encoder(x).flatten(1))
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 3. Checkpointing and Fault-Tolerant Resumption
|
|
109
|
+
|
|
110
|
+
Save complete training state including optimizer, scheduler, and all random generator states:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from mangosta import save_bundle, resume_training, ModelRegistry
|
|
114
|
+
|
|
115
|
+
# Save crash-consistent checkpoint
|
|
116
|
+
save_bundle(
|
|
117
|
+
output_path="checkpoints/epoch_5.bundle",
|
|
118
|
+
model=model,
|
|
119
|
+
family="classifier",
|
|
120
|
+
version="1.0.0",
|
|
121
|
+
init_args={"in_channels": 3, "num_classes": 10},
|
|
122
|
+
sample_input=torch.randn(1, 3, 32, 32),
|
|
123
|
+
is_checkpoint=True,
|
|
124
|
+
optimizer=optimizer,
|
|
125
|
+
scheduler=scheduler,
|
|
126
|
+
epoch=5,
|
|
127
|
+
step=1250,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
# Resume deterministically following an interruption
|
|
131
|
+
fresh_model = ModelRegistry.build("classifier", version="1.0.0", in_channels=3, num_classes=10)
|
|
132
|
+
fresh_optimizer = torch.optim.Adam(fresh_model.parameters(), lr=1e-3)
|
|
133
|
+
fresh_scheduler = torch.optim.lr_scheduler.StepLR(fresh_optimizer, step_size=5)
|
|
134
|
+
|
|
135
|
+
state = resume_training(
|
|
136
|
+
bundle_path="checkpoints/epoch_5.bundle",
|
|
137
|
+
model=fresh_model,
|
|
138
|
+
optimizer=fresh_optimizer,
|
|
139
|
+
scheduler=fresh_scheduler,
|
|
140
|
+
restore_rng=True,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
start_epoch = state.epoch + 1
|
|
144
|
+
start_step = state.step
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 4. Decoupled Production Inference
|
|
148
|
+
|
|
149
|
+
Load models dynamically without importing the underlying model class in your serving scripts:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
import torch
|
|
153
|
+
from mangosta import load_bundle
|
|
154
|
+
|
|
155
|
+
# Reconstructs architecture via registry and mounts weights
|
|
156
|
+
bundle = load_bundle("artifacts/model_final.bundle")
|
|
157
|
+
|
|
158
|
+
# Inference with automated input signature validation
|
|
159
|
+
input_tensor = torch.randn(4, 3, 32, 32)
|
|
160
|
+
predictions = bundle.predict(input_tensor)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 5. Standalone ONNX Export
|
|
164
|
+
|
|
165
|
+
Export directly to standard ONNX with automatic dictionary-to-tuple output unrolling and float16 precision:
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from mangosta import export_onnx
|
|
169
|
+
|
|
170
|
+
export_onnx(
|
|
171
|
+
model_or_bundle="artifacts/model_final.bundle",
|
|
172
|
+
output_path="exports/model.onnx",
|
|
173
|
+
sample_input_shape=(1, 3, 512, 512),
|
|
174
|
+
output_mapping=["semantic_mask", "radius_map", "gradient_map"],
|
|
175
|
+
input_names=["input0"],
|
|
176
|
+
output_names=["output0", "output1", "output2"],
|
|
177
|
+
dynamic_axes={
|
|
178
|
+
"input0": {0: "batch", 2: "height", 3: "width"},
|
|
179
|
+
"output0": {0: "batch", 2: "height", 3: "width"},
|
|
180
|
+
"output1": {0: "batch", 2: "height", 3: "width"},
|
|
181
|
+
"output2": {0: "batch", 2: "height", 3: "width"},
|
|
182
|
+
},
|
|
183
|
+
float16=True,
|
|
184
|
+
opset_version=18,
|
|
185
|
+
verify=True,
|
|
186
|
+
)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Command Line Interface (CLI)
|
|
192
|
+
|
|
193
|
+
`mangosta` provides a zero-daemon CLI utility:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Inspect internal bundle contents, tensor signatures, and metadata
|
|
197
|
+
mangosta inspect checkpoints/epoch_5.bundle
|
|
198
|
+
|
|
199
|
+
# Generate a self-contained, offline interactive HTML report
|
|
200
|
+
mangosta report experiments/vision/baseline_resnet -o report.html
|
|
201
|
+
mangosta report checkpoints/epoch_5.bundle -o report.html
|
|
202
|
+
|
|
203
|
+
# Launch an ephemeral browser viewer (terminates cleanly with Ctrl+C)
|
|
204
|
+
mangosta view ./experiments --port 8501
|
|
205
|
+
|
|
206
|
+
# Export a bundle directly to ONNX from the terminal
|
|
207
|
+
mangosta export-onnx checkpoints/epoch_5.bundle -o model.onnx --fp16 --input-shape 1 3 32 32 -m models.classifier
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Package Architecture
|
|
213
|
+
|
|
214
|
+
The library follows Single Responsibility (SRP) and Open-Closed (OCP) design principles:
|
|
215
|
+
|
|
216
|
+
```text
|
|
217
|
+
src/mangosta/
|
|
218
|
+
|-- __init__.py # Unified high-level public API
|
|
219
|
+
|-- exceptions.py # Domain-specific exception hierarchy
|
|
220
|
+
|-- core/ # Architecture registry and tensor contracts
|
|
221
|
+
| |-- registry.py # ModelRegistry, @register_model, dynamic SemVer resolution
|
|
222
|
+
| `-- schema.py # TensorSpec, ModelSchema, infer_schema
|
|
223
|
+
|-- artifacts/ # Persistence, atomic packaging, and loading
|
|
224
|
+
| |-- bundle.py # Atomic ZIP creation, RNG serialization, checkpointing
|
|
225
|
+
| `-- loader.py # Decoupled reconstruction, LoadedBundle, resume_training
|
|
226
|
+
|-- tracking/ # Experiment tracking and lineage
|
|
227
|
+
| |-- tracker.py # RunTracker, quick_track, SHA-256 dataset fingerprinting
|
|
228
|
+
| `-- report.py # Offline interactive HTML report generator
|
|
229
|
+
|-- export/ # Standalone production exports
|
|
230
|
+
| `-- onnx.py # ONNX exporter, dictionary unrolling, precision handling
|
|
231
|
+
`-- cli/ # Command-line interface
|
|
232
|
+
`-- main.py # CLI entrypoints (inspect, report, view, export-onnx)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## AI Agent Integration (Gemini / Antigravity Skill)
|
|
238
|
+
|
|
239
|
+
`mangosta` provides a production-grade Agent Skill designed for LLMs (Google Gemini, Antigravity CLI, Claude, OpenAI). The skill equips AI coding agents with the exact runbooks, API contracts, and defensive patterns needed to manage models autonomously without hallucinating commands or corrupting checkpoint states.
|
|
240
|
+
|
|
241
|
+
### Installing the Skill in Your Project
|
|
242
|
+
|
|
243
|
+
To make your local AI agent an expert in `mangosta`, copy the public skill specification to your workspace customization folder:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
mkdir -p .agents/skills/mangosta
|
|
247
|
+
cp skills/mangosta/SKILL.md .agents/skills/mangosta/SKILL.md
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Once installed, AI coding agents automatically discover the skill via its standard YAML frontmatter:
|
|
251
|
+
- **Scope**: Automated model registration, contract validation, checkpoint recovery, and ONNX exports.
|
|
252
|
+
- **Location in repository**: [`skills/mangosta/SKILL.md`](file:///home/yeriel/Workspace/mangosta/skills/mangosta/SKILL.md)
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Development
|
|
257
|
+
|
|
258
|
+
Run tests and verification suites locally:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# Sync virtual environment
|
|
262
|
+
uv sync
|
|
263
|
+
|
|
264
|
+
# Run automated tests with coverage
|
|
265
|
+
uv run pytest -v --cov=mangosta
|
|
266
|
+
|
|
267
|
+
# Run linter and formatting checks
|
|
268
|
+
uv run ruff check src tests examples
|
|
269
|
+
uv run ruff format --check src tests examples
|
|
270
|
+
|
|
271
|
+
# Build package distributions (sdist and wheel)
|
|
272
|
+
uv build
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## License
|
|
278
|
+
|
|
279
|
+
MIT License.
|