configmixin
An ultra lightweight configuration management library for machine learning inspired by the Hugging Face 🤗 diffusers library. Add automatic configuration handling to any class with a simple mixin pattern. Please refer to the documentation for more details.
Features
- 🔗 Mixin Pattern: Add config management to models, trainers, or any class
- 💾 Save/Load: Automatic JSON serialization with customizable serialization logic
- ⚡ Decorator Support:
@register_to_configfor automatic parameter registration - 🎯 Selective Exclusion: Control which parameters are saved to config
Installation
From PyPI:
pip install just-config-mixin
If you are interested in the experimental (i.e., unstable and undertested) version, you can install it from GitHub:
pip install git+https://github.com/Guest400123064/configmixin.git
Core Use Cases
1. PyTorch Model with Configuration
import torch.nn as nn
from configmixin import ConfigMixin, register_to_config
class TransformerModel(nn.Module, ConfigMixin):
config_name = "model_config.json"
@register_to_config
def __init__(
self,
vocab_size: int = 30000,
hidden_size: int = 768,
num_layers: int = 12,
dropout: float = 0.1
):
super().__init__()
self.vocab_size = vocab_size
self.hidden_size = hidden_size
self.num_layers = num_layers
self.dropout = dropout
# Build model layers
self.embedding = nn.Embedding(vocab_size, hidden_size)
self.layers = nn.ModuleList([
nn.TransformerEncoderLayer(hidden_size, 8, batch_first=True)
for _ in range(num_layers)
])
model = TransformerModel(hidden_size=1024, num_layers=24)
print(model.config)
2. Configuration Save/Load
# Save configuration
model.save_config("./checkpoints/experiment_1")
# Load model with exact same configuration
loaded_model = TransformerModel.from_config(save_directory="./checkpoints/experiment_1")
# Or load from config dict
config_dict = {"vocab_size": 50000, "hidden_size": 512, "num_layers": 6, "dropout": 0.2}
model_from_dict = TransformerModel.from_config(config=config_dict)
3. Training Pipeline with Ignored Parameters
class ModelTrainer(ConfigMixin):
config_name = "trainer_config.json"
ignore_for_config = ["model", "optimizer"] # Exclude runtime objects
@register_to_config
def __init__(
self,
learning_rate: float = 1e-4,
batch_size: int = 32,
num_epochs: int = 100,
weight_decay: float = 0.01,
# Runtime objects (ignored)
model=None,
optimizer=None,
# Private params (auto-ignored due to underscore)
_internal_state=None
):
self.learning_rate = learning_rate
self.batch_size = batch_size
self.num_epochs = num_epochs
self.weight_decay = weight_decay
self.model = model
self.optimizer = optimizer
self._internal_state = _internal_state
# Only hyperparameters are saved, not runtime objects
trainer = ModelTrainer(
learning_rate=2e-4,
batch_size=64,
model=some_model,
optimizer=some_optimizer
)
trainer.save_config("./experiments/run_001")
# Config only contains: learning_rate, batch_size, num_epochs, weight_decay
# and the runtime objects are passed via `runtime_kwargs` in `from_config()`
trainer = ModelTrainer.from_config(save_directory="./experiments/run_001", runtime_kwargs={"model": <some_model>})
Complete Workflow
# Create components with configurations
model = TransformerModel(hidden_size=1024, num_layers=24)
trainer = ModelTrainer(learning_rate=1e-4, batch_size=64)
# Save all configurations to experiment directory
experiment_dir = "./experiments/run_001"
model.save_config(experiment_dir)
trainer.save_config(experiment_dir)
# Later: reproduce exact setup
loaded_model = TransformerModel.from_config(save_directory=experiment_dir)
loaded_trainer = ModelTrainer.from_config(save_directory=experiment_dir, runtime_kwargs={"model": loaded_model})
Why configmixin?
Perfect for ML workflows where you need:
- Reproducible experiments with exact parameter tracking
- Easy hyperparameter management built into your classes
- Clean separation between config and runtime state
Contributing
Contributions welcome! Please submit a Pull Request.
License
Apache License 2.0 - see LICENSE file for details.
Metadata
Release files for just-config-mixin 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| just_config_mixin-0.1.1.tar.gz | 16.4 kB | Without provenance | Details for just_config_mixin-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| just_config_mixin-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for just_config_mixin-0.1.1-py3-none-any.whl |
Total release size: 32.7 kB
Release files / just_config_mixin-0.1.1.tar.gz
| Download URL | just_config_mixin-0.1.1.tar.gz |
|---|---|
| Size | 16.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e51b3c0d2315d31eba418b05c1c83b55c6836660b3dedf30a8da98be85ba413
|
|
BLAKE2b-256 checksum How to use checksums |
931f4980524aa23e10e418ab769710aa9c1e209192c5769179aef784a77f031f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.3 Linux/6.14.0-37-generic
|
Release files / just_config_mixin-0.1.1-py3-none-any.whl
| Download URL | just_config_mixin-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b55800673cd9cfd463ae91a3a46adbd006fc8a2d424c5e2ffa96c2973816f76
|
|
BLAKE2b-256 checksum How to use checksums |
1fd572ffa6e995dab12c1261d240541cf8929706c188f4ac7d8ab33346677a46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.3 Linux/6.14.0-37-generic
|
Security for just-config-mixin 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.