Package: configbase
ConfigBase ⚙️ A Machine Learning Configuration SystemThe goal is to simplify configuration for Machine Learning (ML) experiments. Configuration for ML experiments is mostly unsolved. It is cumbersome, error-prone and does not address the standard use-cases, for example HPO, and multi-node or multi-tenant enviroments. ConfigBase builds on top of several pilars to address those problems.Strongly typedconfiguration, with type resolution during run-time.Address need for custom types specific to ML experimentsDerived, are derived during execution, e.g. thevocab_sizedepends on the dataset.Stateless, take values which can change between execution runs or enviroments, e.g. the save directory.Finger-printing of the configuration object based on unique value assignment with their corresponding types. Where for example Stateless variables are ignored.Mutable and Imutable properties where one canfreezethe configuration to prevent changes to it.Flexible configuration definition, compositionality and hierarchical definitionRepresentation of configuration in YAML files for easy modificationEasy representation of value-distributions, i.e. fields that can take a value within a range, or conditionally, i.e. nested categorical distributions. There is easy integration for sampling and use with third party HPO algorithms.In SummaryThis repo aspires to be the poster-child ofStrictYAML,HydraandDataclassescombined and with a 🍒 on top.UsageTo install simply run:pipinstallconfigbaseTo define your configuration:fromconfigimportconfig@configclassC:a:int=5c=C(a=5)c.a# Output:5c.a=5.5c.a# Output:5Minimal ExamplesStrongly TypedfromconfigimportconfigclassMyClass:def__init__(self,a=3,b=3):self.a=aself.b=b@configclassC:a:MyClass=MyClass()b:int=5c=C(a={"a":1})c.a.a# Output:1Object-Persistenceprint(C.from_yaml(c.to_yaml()))# Output:C(a={'a':1,'b':2},b=5)Immutablec.freeze()c.b=1# Output:# RuntimeError: Can not set attribute b on frozen configuration ``C``.c.unfreeze()c.b=1c.b# Output:1Fingerprintingfromconfigimportconfig,Stateless,Derived@configclassC:a:Stateless[int]=5b:int=5c=C()c.uid# Output:'1cf3'c.a=6c.uid# Output:'1cf3'c.a=5c.uid# Output:'51fd'Distributionsfromconfigimportconfig,Distribution,CategoricalDistribution,SearchSpace@configclassA:d:float=0.5@configclassMaster:a:A=A()d:float=0.5space=SearchSpace({"a.d":Distribution(0,1,n_bins=4),"d":CategoricalDistribution([Distribution(0,0.1,n_bins=4),Distribution(0.9,1,n_bins=4)]),})m=Master()m.sample(space)# Output:Master(a={'d':0.0},d=1.0)Custom HPO Functionsdefhpo_fn(name,dist:CategoricalDistribution|Distribution):returndist.random_sample()m.sample(space,sample_fn=hpo_fn)# Output:Master(a={'d':0.5},d=0.925)Expand Search Spaceprint(m.expand(space))# Output:[Master(a={'d':0.0},d=0.0),Master(a={'d':0.0},d=0.025),Master(a={'d':0.0},d=0.05),Master(a={'d':0.0},d=0.07500000000000001),Master(a={'d':0.0},d=0.1),Master(a={'d':0.25},d=0.0),Master(a={'d':0.25},d=0.025),Master(a={'d':0.25},d=0.05),Master(a={'d':0.25},d=0.07500000000000001),Master(a={'d':0.25},d=0.1),Master(a={'d':0.5},d=0.0),Master(a={'d':0.5},d=0.025),Master(a={'d':0.5},d=0.05),Master(a={'d':0.5},d=0.07500000000000001),Master(a={'d':0.5},d=0.1),Master(a={'d':0.75},d=0.0),Master(a={'d':0.75},d=0.025),Master(a={'d':0.75},d=0.05),Master(a={'d':0.75},d=0.07500000000000001),Master(a={'d':0.75},d=0.1),Master(a={'d':1.0},d=0.0),Master(a={'d':1.0},d=0.025),Master(a={'d':1.0},d=0.05),Master(a={'d':1.0},d=0.07500000000000001),Master(a={'d':1.0},d=0.1),Master(a={'d':0.0},d=0.9),Master(a={'d':0.0},d=0.925),Master(a={'d':0.0},d=0.95),Master(a={'d':0.0},d=0.975),Master(a={'d':0.0},d=1.0),Master(a={'d':0.25},d=0.9),Master(a={'d':0.25},d=0.925),Master(a={'d':0.25},d=0.95),Master(a={'d':0.25},d=0.975),Master(a={'d':0.25},d=1.0),Master(a={'d':0.5},d=0.9),Master(a={'d':0.5},d=0.925),Master(a={'d':0.5},d=0.95),Master(a={'d':0.5},d=0.975),Master(a={'d':0.5},d=1.0),Master(a={'d':0.75},d=0.9),Master(a={'d':0.75},d=0.925),Master(a={'d':0.75},d=0.95),Master(a={'d':0.75},d=0.975),Master(a={'d':0.75},d=1.0),Master(a={'d':1.0},d=0.9),Master(a={'d':1.0},d=0.925),Master(a={'d':1.0},d=0.95),Master(a={'d':1.0},d=0.975),Master(a={'d':1.0},d=1.0)]Cite@misc{fostiropoulos2024configbase,author={Fostiropoulos, Iordanis},title={ConfigBase: A Machine Learning Configuration System },year={2024},publisher={GitHub},journal={GitHub repository},howpublished={\url{https://github.com/fostiropoulos/configbase}},}