Upgrade to Pro — share decks privately, control downloads, hide ads and more …

jsonargparse - Say goodbye to configuration hassles

jsonargparse - Say goodbye to configuration hassles

Talk about the open-source library jsonargparse at PyConDE / PyData Berlin 2022

Marianne Stecklina

April 12, 2022
Tweet

More Decks by Marianne Stecklina

Other Decks in Programming

Transcript

  1. • Deep Learning Engineer at omni:us • colleague of Mauricio

    Villegas, creator of jsonargparse • early user of jsonargparse How I came to give this talk That’s me! That’s Mauricio!
  2. jsonargparse is an open-source library that helps to configure your

    code by creating a CLI. *CLI = command line interface
  3. Why CLIs are great compared to… no interface • run

    program differently without modifying code • easier to use for others graphical user interface (GUI) • easier to create • perfect for batch tasks • perfect for scheduled tasks • useful in terminal-only environments
  4. https://github.com/stecklin/pycon22-jsonargparse • Compare python 0_argparse.py --help and python 1_cli.py --help

    • Run python 1_cli.py PyCON --year 2022 • Print config using python 1_cli.py --print_config > config.yaml • Edit config.yaml • Run python 1_cli.py --config config.yaml • Run python 1_cli.py --config config.yaml --year 2024 • Run python 1_cli.py --year 2024 --config config.yaml • Run PYCON_CONFERENCE_NAME=PyCON PYCON_YEAR=2024 python 2_cli_with_env_variables.py Live Demo
  5. Key features • CLIs with minimal code overhead • possible

    to parse ◦ command line arguments ◦ config files ◦ environment variables
  6. https://github.com/stecklin/pycon22-jsonargparse • Run python 3_image_classification.py --help • Run python 3_image_classification.py

    --dataset.help Cifar10Dataset • Run python 3_image_classification.py --config configs/3_config.yaml --dataset.augment maybe • Run python 3_image_classification.py --config configs/3_config.yaml --dataset.data_dir /home/ghosts/ Live Demo
  7. Key features • config (and help) is hierarchical • config

    structure always in sync with code • type checks
  8. Different datasets & models ConvNet kernel_size: int num_layers: int VisionTransformer

    num_layers: int num_heads: int hidden_dim: int mlp_dim: int {abstract} Model num_classes: int Cifar10Dataset ImageNetDataset {abstract} Dataset data_dir: path_dr batch_size: int augment: bool
  9. https://github.com/stecklin/pycon22-jsonargparse • Run python 4_subclasses.py --help • Run python 4_subclasses.py

    --dataset ImageNetDataset --model ConvNet --print_config • Run python 4_subclasses.py --config configs/4_config.yaml • Run python 4_subclasses.py --dataset configs/4_cifar10.yaml --model configs/4_conv_net.yaml • Run python 4_subclasses.py --config configs/4_config_with_subconfigs.yaml • Run python 5_model_composition.py --config configs/5_config.yaml Live Demo