Package: corider
Co-RiderTiny configuration library tailored for Deep Learning project and theRidelibrary.pipinstallcoriderOrganising configurations and arguments for Deep Learning projectsKeeping track of, merging and exposing configurations as arguments can be cumbersome and introduces a lot of boiler-plate code.
This tiny library aims to introduce a configuration structure, that will fit many Deep Learning projects.A basic configuration is defined as follows:fromcoriderimportConfigsc1=Configs()c1.add(name="learning_rate",type=int,default=2,strategy="loguniform",description="Learning rate for optimizer",choices=(1e-8,1),)c1.add(name="optimizer",type=str,default="sgd",strategy="constant",description="Optimizer to use.",choices=["sgd","adam"],)ArgparseCo-Rideris fully compartible withargparseand can both load and dump argparse configurations:# argparse_example.pyfromargparseimportArgumentParserfromcoriderimportConfigsparser=ArgumentParser(add_help=True)parser.add_argument("--defined_with_argparse",default=42,choices=(42,1337),type=int,help="Nonsensical parameter defined for demo purposes.",)c2=Configs.from_argument_parser(parser)c2.add(name="defined_with_corider",type=int,default="lit",description="Another parameter for demo purposes",choices=["lit","woke"],)new_parser=c2.add_argparse_args(ArgumentParser(add_help=True))args=new_parser.parse_args()# Do somethin with the argsUse from shell as usual:$pythonargparse_example.py--help
usage:argparse_example.py[-h][--defined_with_argparse{42,1337}][--defined_with_corider{lit,woke}]optionalarguments:-h,--helpshowthishelpmessageandexit--defined_with_argparse{42,1337}Nonsensicalparameterdefinedfordemopurpose.(Default:42)--defined_with_corider{lit,woke}Anotherparameterfordemopurpose(Default:lit)Ray TuneBy now you may have wodered about thestrategyparameter.
This parameter is intended for hyperparameter optimizers to indicate which sampling strategy to employ during hyperparameter search.Four strategies are available:"constant": Parameter is not searchable and must be selected elsewhere, e.g. usingargparse"choice": Choose randomly from a list/set/tuple/range of parameters, e.g.["lit", "woke"]"uniform": Pick values at random from an interval, e.g.(0, 10)"loguniform": Pick values in a log uniform manner, e.g.(1e-8, 1)For now, an automatic export toRay[Tune]is included, which can be used as follows:fromrayimporttune# Configs which had strategy "constant" can be added as argparse argsparser=c.add_tune_argparse_args(ArgumentParser())args=parser.parse_args()# Other parameters are exported in a Tune-compatible formattune_config=c.tune_config()# Run searchanalysis=tune.run(your_training_function,config=tune_config,...# Other tune.run parameters)Argument addition and subtracktionCo-Ridercan add and subtract configs as needed:c1=...# As defined above (has: "learning_rate", "optimizer")c2=...# As defined above (has: "defined_with_argparse", "defined_with_corider")c3=Configs()c3.add(name="learning_rate",# Also defined in c1type=int,default=2,strategy="loguniform",description="Learning rate for optimizer",choices=(1e-8,1),)# Has: "optimizer," "defined_with_argparse", "defined_with_corider"c4=c1+c2-c3Load configuration from fileA configuration can be loaded from either.yamlor.jsonformatted files:# example_conf.yamldropout:type:floatstrategy:choicechoices:[0.0,0.1,0.2,0.3,0.4]learning_rate:type:floatstrategy:loguniformchoices:[0.01,0.5]weight_decay:type:floatstrategy:loguniformchoices:[0.000001,0.001]c=Configs.from_file("example_conf.yaml")