Pyrallis - Simple Configuration with Dataclasses Pyrausta (also called pyrallis…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
Pyrallis - Simple Configuration with Dataclasses Pyrausta (also called pyrallis (πυραλλίς), pyragones) is a mythological insect-sized dragon from Cyprus.
Pyrallis is a simple library, derived from simple-parsing and inspired by Hydra, for automagically creating project configuration from a dataclass.
GIF
Why pyrallis? With pyrallis your configuration is linked directly to your pre-defined dataclass, allowing you to easily create different configuration structures, including nested ones, using an object-oriented design. The parsed arguments are used to initialize your dataclass, giving you the typing hints and automatic code completion of a full dataclass object.
My First Pyrallis Example 👶 There are several key features to pyrallis but at its core pyrallis simply allows defining an argument parser using a dataclass.
from dataclasses import dataclass import pyrallis
@dataclass class TrainConfig: """ Training config for Machine Learning """ workers: int = 8 # The number of workers for training exp_name: str = 'default_exp' # The experiment name
def main(): cfg = pyrallis.parse(config_class=TrainConfig) print(f'Training {cfg.exp_name} with {cfg.workers} workers...') The arguments can then be specified using command-line arguments, a yaml configuration file, or both.
$ python train_model.py --config_path=some_config.yaml --exp_name=my_first_exp Training my_first_exp with 42 workers... Assuming the following configuration file
exp_name: my_yaml_exp workers: 42
- Assistant
To use the provided
TrainConfigdataclass withpyrallis, you need to ensure that the configuration file (some_config.yaml) matches the structure defined in the dataclass. Here's how you can set up thepyrallisconfiguration and use it in yourmainfunction:- Create a configuration file named
some_config.yamlwith the following content:
yamlworkers: 42 exp_name: my_yaml_exp- Modify the
mainfunction to use the configuration file:
python - Create a configuration file named
- User
How to write code with pyrallis
- Assistant
To write code using
pyrallis, follow these steps:- Install
pyrallisandpyyamllibraries:
bashpip install pyrallis pyyaml- Create a configuration file (e.g.,
config.yaml) with the desired configuration values:
yamlworkers: 42 exp_name: my_exp- Define a dataclass that represents your configuration structure:
pythonfrom dataclasses import dataclass import pyrallis import yaml @dataclass class TrainConfig: """ Training config for Machine Learning """ workers: int = 8 # The number of workers for training exp_name: str = 'default_exp' # The experiment name - Install
- User
Can you show me a code example for using pyrallis?
- Assistant
Sure! Here's a complete example demonstrating how to use
pyrallisto manage your project configuration.- First, create a configuration file named
config.yamlwith the following content:
yamlworkers: 42 exp_name: my_exp- Next, define a dataclass that represents your configuration structure:
pythonfrom dataclasses import dataclass import pyrallis import yaml @dataclass class TrainConfig: """ Training config for Machine Learning """ workers: int = 8 # The number of workers for training exp_name: str = 'default_exp' # The experiment name - First, create a configuration file named
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.