chimera-ml 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.
Files changed (59) hide show
  1. chimera_ml-0.1.0/LICENSE +21 -0
  2. chimera_ml-0.1.0/PKG-INFO +410 -0
  3. chimera_ml-0.1.0/README.md +383 -0
  4. chimera_ml-0.1.0/pyproject.toml +66 -0
  5. chimera_ml-0.1.0/src/chimera_ml/__init__.py +11 -0
  6. chimera_ml-0.1.0/src/chimera_ml/callbacks/__init__.py +19 -0
  7. chimera_ml-0.1.0/src/chimera_ml/callbacks/_utils.py +64 -0
  8. chimera_ml-0.1.0/src/chimera_ml/callbacks/base.py +50 -0
  9. chimera_ml-0.1.0/src/chimera_ml/callbacks/checkpoint_callback.py +112 -0
  10. chimera_ml-0.1.0/src/chimera_ml/callbacks/collect_predictions_callback.py +181 -0
  11. chimera_ml-0.1.0/src/chimera_ml/callbacks/early_stopping_callback.py +93 -0
  12. chimera_ml-0.1.0/src/chimera_ml/callbacks/plot_confusion_matrix_callback.py +257 -0
  13. chimera_ml-0.1.0/src/chimera_ml/callbacks/snapshot_callback.py +58 -0
  14. chimera_ml-0.1.0/src/chimera_ml/callbacks/telegram_notifier_callback.py +237 -0
  15. chimera_ml-0.1.0/src/chimera_ml/cli.py +444 -0
  16. chimera_ml-0.1.0/src/chimera_ml/core/__init__.py +29 -0
  17. chimera_ml-0.1.0/src/chimera_ml/core/batch.py +58 -0
  18. chimera_ml-0.1.0/src/chimera_ml/core/registry.py +53 -0
  19. chimera_ml-0.1.0/src/chimera_ml/core/types.py +13 -0
  20. chimera_ml-0.1.0/src/chimera_ml/data/__init__.py +11 -0
  21. chimera_ml-0.1.0/src/chimera_ml/data/datamodule.py +85 -0
  22. chimera_ml-0.1.0/src/chimera_ml/data/loader_utils.py +53 -0
  23. chimera_ml-0.1.0/src/chimera_ml/data/masking_collate.py +241 -0
  24. chimera_ml-0.1.0/src/chimera_ml/logging/__init__.py +5 -0
  25. chimera_ml-0.1.0/src/chimera_ml/logging/base.py +38 -0
  26. chimera_ml-0.1.0/src/chimera_ml/logging/console_file_logger.py +109 -0
  27. chimera_ml-0.1.0/src/chimera_ml/logging/mlflow_logger.py +98 -0
  28. chimera_ml-0.1.0/src/chimera_ml/logging/utils.py +57 -0
  29. chimera_ml-0.1.0/src/chimera_ml/losses/__init__.py +16 -0
  30. chimera_ml-0.1.0/src/chimera_ml/losses/base.py +12 -0
  31. chimera_ml-0.1.0/src/chimera_ml/losses/ccc.py +86 -0
  32. chimera_ml-0.1.0/src/chimera_ml/losses/classification.py +22 -0
  33. chimera_ml-0.1.0/src/chimera_ml/losses/focal.py +71 -0
  34. chimera_ml-0.1.0/src/chimera_ml/losses/multilabel.py +22 -0
  35. chimera_ml-0.1.0/src/chimera_ml/losses/regression.py +37 -0
  36. chimera_ml-0.1.0/src/chimera_ml/metrics/__init__.py +26 -0
  37. chimera_ml-0.1.0/src/chimera_ml/metrics/_utils.py +35 -0
  38. chimera_ml-0.1.0/src/chimera_ml/metrics/base.py +20 -0
  39. chimera_ml-0.1.0/src/chimera_ml/metrics/confusion_matrix_metric.py +59 -0
  40. chimera_ml-0.1.0/src/chimera_ml/metrics/prf_metric.py +116 -0
  41. chimera_ml-0.1.0/src/chimera_ml/metrics/regression_metric.py +178 -0
  42. chimera_ml-0.1.0/src/chimera_ml/models/__init__.py +13 -0
  43. chimera_ml-0.1.0/src/chimera_ml/models/base.py +14 -0
  44. chimera_ml-0.1.0/src/chimera_ml/models/fusion.py +126 -0
  45. chimera_ml-0.1.0/src/chimera_ml/models/gated_prediction_fusion.py +98 -0
  46. chimera_ml-0.1.0/src/chimera_ml/models/gating.py +109 -0
  47. chimera_ml-0.1.0/src/chimera_ml/plugins.py +41 -0
  48. chimera_ml-0.1.0/src/chimera_ml/training/__init__.py +9 -0
  49. chimera_ml-0.1.0/src/chimera_ml/training/builders.py +198 -0
  50. chimera_ml-0.1.0/src/chimera_ml/training/cached_split_outputs.py +39 -0
  51. chimera_ml-0.1.0/src/chimera_ml/training/config.py +86 -0
  52. chimera_ml-0.1.0/src/chimera_ml/training/mixed_loader_utils.py +126 -0
  53. chimera_ml-0.1.0/src/chimera_ml/training/optimizers.py +48 -0
  54. chimera_ml-0.1.0/src/chimera_ml/training/schedulers.py +33 -0
  55. chimera_ml-0.1.0/src/chimera_ml/training/trainer.py +643 -0
  56. chimera_ml-0.1.0/src/chimera_ml/utils/__init__.py +1 -0
  57. chimera_ml-0.1.0/src/chimera_ml/utils/entrypoints.py +45 -0
  58. chimera_ml-0.1.0/src/chimera_ml/utils/seed.py +29 -0
  59. chimera_ml-0.1.0/src/chimera_ml/utils/utils.py +33 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Maxim Markitantov
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,410 @@
1
+ Metadata-Version: 2.4
2
+ Name: chimera-ml
3
+ Version: 0.1.0
4
+ Summary: Chimera ML (Cross-modal Hierarchical Merging of Embeddings and Representations) - a lightweight training framework for configurable uni-modal and multi-modal experiments.
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Keywords: machine-learning,pytorch,multimodal,training,deep-learning
8
+ Author: Maxim Markitantov
9
+ Author-email: m.markitantov@yandex.ru
10
+ Requires-Python: >=3.12,<3.13
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Classifier: Typing :: Typed
17
+ Requires-Dist: matplotlib (>=3.8,<4.0)
18
+ Requires-Dist: mlflow (>=2.12,<3.0)
19
+ Requires-Dist: numpy (>=1.26,<3.0)
20
+ Requires-Dist: pyyaml (>=6.0.1,<7.0)
21
+ Requires-Dist: requests (>=2.31,<3.0)
22
+ Requires-Dist: torch (>=2.2,<3.0)
23
+ Requires-Dist: tqdm (>=4.66,<5.0)
24
+ Requires-Dist: typer (>=0.12,<1.0)
25
+ Description-Content-Type: text/markdown
26
+
27
+ # Chimera ML
28
+
29
+ `Chimera ML (Cross-modal Hierarchical Merging of Embeddings and Representations)` is a lightweight framework for training and evaluating configurable uni-modal and multi-modal models.
30
+
31
+ The core idea is simple:
32
+
33
+ - the library provides runtime infrastructure (trainer, logging, callbacks, registry builders),
34
+ - task-specific components (datamodules, models, losses, metrics, callbacks) live in external plugin packages,
35
+ - experiments are driven by YAML configs and CLI commands.
36
+
37
+ ## Requirements
38
+
39
+ - Python `>=3.12,<3.13`
40
+ - PyTorch `>=2.2,<3.0`
41
+
42
+ ## Installation
43
+
44
+ Install from PyPI:
45
+
46
+ ```bash
47
+ pip install chimera-ml
48
+ ```
49
+
50
+ or:
51
+
52
+ ```bash
53
+ poetry add chimera-ml
54
+ ```
55
+
56
+ By default, the package includes MLflow, matplotlib, and requests dependencies.
57
+
58
+ Install from source (development):
59
+
60
+ ```bash
61
+ poetry install --with dev
62
+ ```
63
+
64
+ CLI entry points:
65
+
66
+ ```bash
67
+ chimera-ml --help
68
+ chimera_ml --help
69
+ ```
70
+
71
+ Both names are available; docs use `chimera-ml`.
72
+
73
+ ## Quick Start
74
+
75
+ 1. Install `chimera-ml`.
76
+ 2. Install your task plugin package (example below).
77
+ 3. Run train/eval with YAML config.
78
+
79
+ Example plugin from this repo:
80
+
81
+ ```bash
82
+ pip install -e examples/va_estimation
83
+ chimera-ml validate-config --config-path examples/va_estimation/configs/multimodal_train.yaml
84
+ chimera-ml train --config-path examples/va_estimation/configs/multimodal_train.yaml
85
+ chimera-ml eval --config-path examples/va_estimation/configs/multimodal_test.yaml --checkpoint-path path/to/last.pt
86
+ ```
87
+
88
+ ## CLI
89
+
90
+ Main commands:
91
+
92
+ ```bash
93
+ chimera-ml validate-config --config-path <config.yaml>
94
+ chimera-ml doctor
95
+ chimera-ml train --config-path <config.yaml>
96
+ chimera-ml eval --config-path <config.yaml> --checkpoint-path <ckpt.pt> [--with-features]
97
+ chimera-ml registry list [--type models|losses|metrics|optimizers|schedulers|callbacks|collates|loggers|datamodules]
98
+ chimera-ml plugins list [--group chimera_ml.plugins]
99
+ ```
100
+
101
+ `validate-config`:
102
+
103
+ - checks config structure and required sections without starting training.
104
+
105
+ `doctor`:
106
+
107
+ - prints quick environment diagnostics (Python, torch, CUDA, MLflow, registry/plugin counts).
108
+
109
+ `train`:
110
+
111
+ - requires `experiment_info.params.experiment_name`,
112
+ - generates `run_name` via `generate_run_name(...)`,
113
+ - patches `checkpoint_callback` and `snapshot_callback` params with experiment/run data,
114
+ - builds all components from registries and runs `Trainer.fit(...)`.
115
+
116
+ `eval`:
117
+
118
+ - builds datamodule/model/loss/metrics/callbacks from the same config style,
119
+ - optionally loads checkpoint (`model_state_dict` or raw state dict),
120
+ - evaluates over merged `train`/`val`/`test` loader splits when available.
121
+
122
+ `registry list`:
123
+
124
+ - prints currently registered keys (including keys loaded from plugins).
125
+
126
+ `plugins list`:
127
+
128
+ - prints discovered Python entry points for plugin group `chimera_ml.plugins`.
129
+
130
+ ## YAML Config Model
131
+
132
+ Top-level sections used by runtime:
133
+
134
+ - `seed`
135
+ - `experiment_info` (required for `train`)
136
+ - `data`
137
+ - `model`
138
+ - `train`
139
+ - `loss`
140
+ - `optimizer`
141
+ - `scheduler` (optional)
142
+ - `metrics` (list)
143
+ - `logging` (list)
144
+ - `callbacks` (list)
145
+
146
+ Minimal skeleton:
147
+
148
+ ```yaml
149
+ seed: 0
150
+
151
+ experiment_info:
152
+ params:
153
+ experiment_name: "my_experiment"
154
+ include_time: true
155
+ datetime_format: "%Y-%m-%d_%H-%M"
156
+ timezone: "UTC"
157
+
158
+ data:
159
+ name: "my_datamodule"
160
+ params: {}
161
+
162
+ model:
163
+ name: "my_model"
164
+ params: {}
165
+
166
+ train:
167
+ params:
168
+ epochs: 10
169
+ device: "cuda"
170
+ mixed_precision: true
171
+ use_scheduler: true
172
+ scheduler_step_per_epoch: true
173
+ scheduler_monitor: "val/loss"
174
+
175
+ loss:
176
+ name: "mse_loss"
177
+ params: {}
178
+
179
+ optimizer:
180
+ name: "adamw_optimizer"
181
+ params:
182
+ lr: 1e-3
183
+
184
+ scheduler:
185
+ name: "steplr_scheduler"
186
+ params:
187
+ step_size: 10
188
+ gamma: 0.5
189
+
190
+ metrics:
191
+ - name: "mae_metric"
192
+ params: {}
193
+
194
+ logging:
195
+ - name: "console_file_logger"
196
+ params:
197
+ log_path: "logs"
198
+ - name: "mlflow_logger"
199
+ params:
200
+ tracking_uri: "sqlite:///logs/mlflow.db"
201
+
202
+ callbacks:
203
+ - name: "checkpoint_callback"
204
+ params:
205
+ monitor: "val/loss"
206
+ mode: "min"
207
+ ```
208
+
209
+ ## TrainConfig Parameters
210
+
211
+ `train.params` is mapped to `TrainConfig`:
212
+
213
+ - `epochs` (default `10`)
214
+ - `grad_clip_norm` (default `null`)
215
+ - `mixed_precision` (default `false`)
216
+ - `log_every_steps` (default `50`)
217
+ - `device` (default `"cuda"`)
218
+ - `train_loader_mode`: `single | round_robin | weighted` (default `single`)
219
+ - `train_stop_on`: `min | max` (default `min`)
220
+ - `train_loader_weights` (optional mapping for weighted mode)
221
+ - `use_scheduler` (default `false`)
222
+ - `scheduler_step_per_epoch` (default `true`)
223
+ - `scheduler_monitor` (optional metric key)
224
+ - `collect_cache` (default `true`)
225
+
226
+ ## Data Contract
227
+
228
+ The trainer expects `Batch` objects:
229
+
230
+ ```python
231
+ Batch(
232
+ inputs={"modality": tensor, ...},
233
+ targets=tensor_or_none,
234
+ masks={"sequence_mask": ..., "audio_mask": ..., ...} or None,
235
+ meta={"sample_meta": [...], ...} or None,
236
+ )
237
+ ```
238
+
239
+ Built-in `MaskingCollate` (`masking_collate`) supports variable-length multimodal inputs and creates:
240
+
241
+ - padded modality tensors,
242
+ - `sequence_mask`,
243
+ - per-modality masks like `{modality}_mask`,
244
+ - optional legacy `meta["masks"]`.
245
+
246
+ ## Plugin System
247
+
248
+ On `import chimera_ml`, the library calls `register_all()`:
249
+
250
+ - loads built-in modules that register built-in components,
251
+ - loads external entry points from group `chimera_ml.plugins`,
252
+ - executes callable entry points once per process.
253
+
254
+ Plugin declaration (recommended, PEP 621 style):
255
+
256
+ ```toml
257
+ [project.entry-points."chimera_ml.plugins"]
258
+ my_project = "my_project.chimera_plugin:register"
259
+ ```
260
+
261
+ Typical `register()` function:
262
+
263
+ ```python
264
+ def register():
265
+ import my_project.data
266
+ import my_project.models
267
+ import my_project.losses
268
+ import my_project.metrics
269
+ import my_project.callbacks
270
+ ```
271
+
272
+ Import side effects execute registry decorators.
273
+
274
+ ## Built-In Registry Keys
275
+
276
+ Datamodules are intentionally project-specific. Built-in `DATAMODULES` is empty by default.
277
+
278
+ `MODELS`:
279
+
280
+ - `feature_fusion_model`
281
+ - `prediction_fusion_model`
282
+ - `gated_fusion_model`
283
+ - `gated_prediction_fusion_model`
284
+
285
+ `LOSSES`:
286
+
287
+ - `mse_loss`
288
+ - `mae_loss`
289
+ - `cross_entropy_loss`
290
+ - `focal_loss`
291
+ - `bce_with_logits_loss`
292
+ - `ccc_loss`
293
+
294
+ `METRICS`:
295
+
296
+ - `mae_metric`
297
+ - `mse_metric`
298
+ - `rmse_metric`
299
+ - `r2_metric`
300
+ - `prf_macro_metric`
301
+ - `prf_micro_metric`
302
+ - `prf_weighted_metric`
303
+ - `confusion_matrix_metric`
304
+
305
+ `OPTIMIZERS`:
306
+
307
+ - `adamw_optimizer`
308
+ - `adam_optimizer`
309
+ - `sgd_optimizer`
310
+
311
+ `SCHEDULERS`:
312
+
313
+ - `steplr_scheduler`
314
+ - `cosineannealinglr_scheduler`
315
+ - `reduceonplateau_scheduler`
316
+
317
+ `CALLBACKS`:
318
+
319
+ - `checkpoint_callback`
320
+ - `collect_predictions_callback`
321
+ - `early_stopping_callback`
322
+ - `snapshot_callback`
323
+ - `telegram_notifier_callback`
324
+
325
+ `LOGGERS`:
326
+
327
+ - `console_file_logger`
328
+ - `mlflow_logger`
329
+
330
+ `COLLATES`:
331
+
332
+ - `masking_collate`
333
+
334
+ ## Training and Evaluation Behavior
335
+
336
+ - Mixed precision uses `torch.amp.autocast` and `GradScaler` on CUDA.
337
+ - Training supports one or many train loaders.
338
+ - Multi-loader scheduling modes:
339
+ - `single`: first loader only.
340
+ - `round_robin`: cycle loaders.
341
+ - `weighted`: stochastic sampling with loader weights.
342
+ - Validation/test loaders are normalized to stable split keys (`normalize_loaders`).
343
+ - Metrics are stateful (`reset -> update -> compute`).
344
+ - Optional prediction cache (`CachedSplitOutputs`) stores CPU preds/targets/features for callbacks.
345
+
346
+ ## Logging and Artifacts
347
+
348
+ `console_file_logger`:
349
+
350
+ - logs to console + file under `<log_path>/<experiment_name>/<run_name>/`.
351
+
352
+ `mlflow_logger`:
353
+
354
+ - logs params/metrics,
355
+ - supports file/text/bytes artifact logging,
356
+ - logs config artifact when `config_path` is provided.
357
+
358
+ `plot_confusion_matrix_callback`:
359
+
360
+ - builds confusion matrix figures from cached predictions,
361
+ - logs PNG artifacts to MLflow per split (`figures/<split>/...`).
362
+
363
+ `telegram_notifier_callback`:
364
+
365
+ - sends final run status to Telegram via Bot API.
366
+
367
+ ## Callback Lifecycle
368
+
369
+ Callbacks follow:
370
+
371
+ - `on_fit_start`
372
+ - `on_epoch_start`
373
+ - `on_batch_end`
374
+ - `on_epoch_end`
375
+ - `on_fit_end`
376
+
377
+ Highlights:
378
+
379
+ - `checkpoint_callback`: monitor-based top-k and `last.pt`.
380
+ - `early_stopping_callback`: monitor, mode, patience, min_delta.
381
+ - `snapshot_callback`: code/config snapshots (`code.zip`, config copy).
382
+ - `collect_predictions_callback`: CSV prediction artifacts to MLflow.
383
+ - `plot_confusion_matrix_callback`: confusion matrix PNG artifacts to MLflow.
384
+ - `telegram_notifier_callback`: final Telegram notification via env vars.
385
+
386
+ ## Repository Example
387
+
388
+ `examples/va_estimation` is a full plugin package using entry points and task-specific components. Use it as a template for new projects.
389
+
390
+ ## Development
391
+
392
+ Quality checks:
393
+
394
+ ```bash
395
+ poetry run ruff check src tests
396
+ poetry run pytest
397
+ ```
398
+
399
+ See `CONTRIBUTING.md` for contribution details.
400
+
401
+ ## Publishing
402
+
403
+ PyPI publishing is automated via GitHub Actions workflow:
404
+
405
+ - `.github/workflows/publish.yml` (triggered by GitHub Release `published`).
406
+
407
+ Release checklist:
408
+
409
+ - see `RELEASING.md`.
410
+