Skip to main content

Espresso Config

A struct config parser that you can set up in the time it takes to make an espresso. To install, run

pip install espresso-config

Python 3.8 or newer is required.

Why Espresso Config?

There are a million of parsers that can turn a YAML configuration / CLI flags into a configuration file, e.g., Hydra, ML Collections, so why another one? Espresso Config was designed to meet the following requirements:

  1. Support structured configs (i.e., define configurations with classes)
  2. Allow nested classes in configuration
  3. Functions

Motivating Example

Imagine you want to run the following experiment:

backbone: t5-large
model:
  metrics:
    rouge:
      _target_: torchmetrics.functional.text.rouge.rouge_score
  tokenizer:
    _target_: transformers.AutoTokenizer.from_pretrained
    pretrained_model_name_or_path: t5-large
  transformer:
    _target_: transformers.AutoModelForSeq2SeqLM.from_pretrained
    max_sequence_length: 64
    pretrained_model_name_or_path: t5-large

Sure, you could parse that yaml file and get a dict. But (a) working with dictionaries is tedious (b) there's no typing, and (c) you don't want to have to declare all blocks each time; it would be good if you could save some commonly used configurations, such as the parameters for one of transformer or tokenizer keys.

Espresso Config allows you to solve all off those problems by specifying a struct class as follows:

from espresso_config import (
    ConfigNode,
    ConfigRegistry,
    ConfigParam,
    ConfigFlexNode
)

@ConfigRegistry.add
class seq2seq(ConfigNode):
    _target_: ConfigParam(str) = 'transformers.AutoModelForSeq2SeqLM.from_pretrained'

@ConfigRegistry.add
class tok(ConfigNode):
    _target_: ConfigParam(str) = 'transformers.AutoTokenizer.from_pretrained'

@ConfigRegistry.add
class rouge(ConfigNode):
    _target_: ConfigParam(str) = 'torchmetrics.functional.text.rouge.rouge_score'

class ApplicationConfig(ConfigNode):
    backbone: ConfigParam(str)
    class model(ConfigNode):
        class transformer(ConfigNode):
            _target_: ConfigParam(str)
            pretrained_model_name_or_path: ConfigParam(str) = '${backbone}'
            max_sequence_length: ConfigParam(int) = 64
        class tokenizer(ConfigNode):
            _target_: ConfigParam(str)
            pretrained_model_name_or_path: ConfigParam(str) = '${backbone}'
        metrics: ConfigParam(ConfigFlexNode) = {}

Then, your YAML configuration can be as simple as:

backbone: t5-large
model:
  transformer@seq2seq: {}
  tokenizer@tok: {}
  metrics:
    rouge@rouge: {}

Voila! To load the config, run:

from espresso_config import config_from_file

config = config_from_file(ApplicationConfig, path_to_yaml)

Placeholder Variable

A placeholder variable is a config value that references another section of the config, e.g. another value or section. It uses syntax ${path.to.key}.

Registry Reference

A registry reference is a reference to a node config that has been added to the config registry. It uses syntax @placeholder_name.

Metadata

Release files for espresso-config 0.11.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for espresso-config 0.11.1
File Size Uploaded
espresso-config-0.11.1.tar.gz 28.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for espresso-config 0.11.1
File Interpreter ABI Platform
espresso_config-0.11.1-py3-none-any.whl Python 3 none any Details

Total release size: 60.7 kB

Release files / espresso-config-0.11.1.tar.gz

Download URL espresso-config-0.11.1.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
14ae8e281c14391a401cdb9ff5bef07cc49c76531081243f0a8ad1103b2cd4ea
BLAKE2b-256 checksum
How to use checksums
dee4b9641ff62ae9fd1e8c6b28e16fa8480cbcb1c1a132eb6709cf948d6a8460
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.12

Release files / espresso_config-0.11.1-py3-none-any.whl

Download URL espresso_config-0.11.1-py3-none-any.whl
Size 31.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b3603ddae69120d789dd93407ec04d9d60f7ee0465094a44206252d530e4eb1
BLAKE2b-256 checksum
How to use checksums
4df5ce1df6c081c97ccb1df89172143579e07f7a8a4149af162475cc83e9beb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.12

Release history Release notifications | RSS feed

This release

0.11.1 This release

2 release files

0.11.0

2 release files

0.10.2

2 release files

0.10.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8

2 release files

0.7.1

2 release files

0.7

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page