Top Related Projects
Facebook AI Research Sequence-to-Sequence Toolkit written in Python.
Canonical source repository for PyYAML
Flexible Python configuration system. The last one you will ever need.
Gin provides a lightweight configuration framework for Python
Composable transformations of Python+NumPy programs: differentiate, vectorize, JIT to GPU/TPU, and more
An open source AutoML toolkit for automate machine learning lifecycle, including feature engineering, neural architecture search, model compression and hyper-parameter tuning.
Quick Overview
Hydra is a framework for elegantly configuring complex applications. It aims to simplify the development of research and other complex applications by providing a powerful configuration system. Hydra allows for easy management of hierarchical configurations, command-line overrides, and dynamic composition of config files.
Pros
- Flexible and hierarchical configuration management
- Easy command-line overrides and config composition
- Supports multiple config file formats (YAML, JSON, etc.)
- Integrates well with popular ML frameworks like PyTorch
Cons
- Learning curve for complex configurations
- Can be overkill for simple projects
- Limited IDE support for config file autocompletion
- Some users report occasional issues with config resolution
Code Examples
- Basic configuration usage:
from hydra import initialize, compose
with initialize(config_path="conf"):
cfg = compose(config_name="config")
print(cfg.database.host)
print(cfg.database.port)
- Command-line overrides:
from hydra import main, initialize
@main(config_path="conf", config_name="config")
def my_app(cfg):
print(cfg.database.host)
print(cfg.database.port)
if __name__ == "__main__":
my_app()
# Run with: python my_app.py database.host=localhost database.port=5432
- Config composition:
from hydra import initialize, compose
with initialize(config_path="conf"):
cfg = compose(config_name="config", overrides=["db=mysql", "environment=production"])
print(cfg.db.driver)
print(cfg.environment.name)
Getting Started
- Install Hydra:
pip install hydra-core
- Create a config file
conf/config.yaml
:
database:
host: localhost
port: 3306
- Create a Python script
my_app.py
:
import hydra
from omegaconf import DictConfig
@hydra.main(config_path="conf", config_name="config")
def my_app(cfg: DictConfig) -> None:
print(f"Host: {cfg.database.host}")
print(f"Port: {cfg.database.port}")
if __name__ == "__main__":
my_app()
- Run the application:
python my_app.py
Competitor Comparisons
Facebook AI Research Sequence-to-Sequence Toolkit written in Python.
Pros of fairseq
- Specialized for sequence modeling tasks like machine translation and text generation
- Includes pre-trained models and benchmarks for various NLP tasks
- Offers a wide range of architectures and training techniques specific to NLP
Cons of fairseq
- More complex setup and usage compared to Hydra's simplicity
- Less flexible for general-purpose configuration management
- Steeper learning curve for users not familiar with NLP concepts
Code Comparison
fairseq:
from fairseq.models.transformer import TransformerModel
en2de = TransformerModel.from_pretrained(
'/path/to/model',
checkpoint_file='model.pt',
data_name_or_path='data-bin/wmt14_en_de'
)
en2de.translate('Hello world!')
Hydra:
import hydra
from omegaconf import DictConfig
@hydra.main(config_path="conf", config_name="config")
def my_app(cfg: DictConfig) -> None:
print(cfg.db.host)
print(cfg.db.port)
The code snippets highlight the different focus areas of the two libraries. fairseq provides high-level APIs for NLP tasks, while Hydra offers a general-purpose configuration management system.
Canonical source repository for PyYAML
Pros of PyYAML
- Lightweight and focused solely on YAML parsing and dumping
- Widely adopted and well-established in the Python ecosystem
- Supports all YAML 1.1 specifications
Cons of PyYAML
- Lacks advanced configuration management features
- No built-in support for command-line overrides or dynamic configuration
- Limited functionality beyond basic YAML handling
Code Comparison
PyYAML:
import yaml
with open('config.yaml', 'r') as file:
config = yaml.safe_load(file)
print(config['database']['host'])
Hydra:
import hydra
from omegaconf import DictConfig
@hydra.main(config_path="conf", config_name="config")
def my_app(cfg: DictConfig) -> None:
print(cfg.database.host)
if __name__ == "__main__":
my_app()
PyYAML focuses on simple YAML parsing, while Hydra provides a more comprehensive configuration management system with features like command-line overrides, config composition, and runtime configuration changes. Hydra builds upon PyYAML's functionality, offering a higher-level abstraction for complex configuration scenarios in larger applications and machine learning projects.
Flexible Python configuration system. The last one you will ever need.
Pros of OmegaConf
- Lightweight and focused solely on configuration management
- More flexible and customizable for advanced use cases
- Can be used independently of any framework or application structure
Cons of OmegaConf
- Lacks built-in CLI argument parsing and command-line completion
- Doesn't provide out-of-the-box support for multi-run experiments or sweeps
- Requires more manual setup for complex configuration scenarios
Code Comparison
OmegaConf:
from omegaconf import OmegaConf
cfg = OmegaConf.load('config.yaml')
print(cfg.database.host)
cfg.merge_with_cli()
Hydra:
import hydra
@hydra.main(config_path="conf", config_name="config")
def my_app(cfg):
print(cfg.database.host)
if __name__ == "__main__":
my_app()
Summary
OmegaConf is a lightweight configuration library that offers flexibility and customization. It's ideal for projects that need fine-grained control over configuration management. Hydra, built on top of OmegaConf, provides a more comprehensive framework with additional features like CLI integration and experiment management. While OmegaConf is more adaptable, Hydra offers a more structured approach with built-in conveniences for larger projects and complex experimental setups.
Gin provides a lightweight configuration framework for Python
Pros of Gin-config
- Simpler syntax and easier to learn for beginners
- Better integration with TensorFlow and other Google ML libraries
- More flexible when it comes to modifying configurations at runtime
Cons of Gin-config
- Less powerful composition and override capabilities
- Limited support for complex nested configurations
- Smaller community and fewer third-party integrations
Code Comparison
Hydra configuration example:
db:
driver: mysql
user: omry
pass: secret
Gin-config configuration example:
import gin
@gin.configurable
def database(driver, user, password):
# Database connection logic here
pass
gin.parse_config_file('config.gin')
Both Hydra and Gin-config are configuration frameworks for Python applications, but they have different approaches and strengths. Hydra focuses on composable configurations and is more suitable for complex, hierarchical setups. Gin-config, on the other hand, offers a simpler syntax and tighter integration with Google's machine learning ecosystem.
Hydra excels in managing multiple configuration files, allowing for easy overrides and composition. It also provides powerful command-line integration and dynamic configuration generation. Gin-config, while more limited in these aspects, offers a more straightforward approach to configuration binding and is particularly well-suited for TensorFlow-based projects.
Composable transformations of Python+NumPy programs: differentiate, vectorize, JIT to GPU/TPU, and more
Pros of JAX
- Powerful numerical computing library with automatic differentiation
- Supports GPU/TPU acceleration for high-performance machine learning
- Combines NumPy-like syntax with JIT compilation for efficiency
Cons of JAX
- Steeper learning curve for those unfamiliar with functional programming
- Less focus on configuration management compared to Hydra
- Narrower scope, primarily for numerical computing and ML
Code Comparison
JAX example:
import jax.numpy as jnp
from jax import grad, jit
def f(x):
return jnp.sum(jnp.sin(x))
grad_f = jit(grad(f))
Hydra example:
import hydra
from omegaconf import DictConfig
@hydra.main(config_path="config", config_name="config")
def my_app(cfg: DictConfig) -> None:
print(cfg.db.host)
JAX focuses on numerical operations and automatic differentiation, while Hydra emphasizes configuration management for applications. JAX is more suited for machine learning and scientific computing tasks, whereas Hydra excels in managing complex configurations for various applications.
An open source AutoML toolkit for automate machine learning lifecycle, including feature engineering, neural architecture search, model compression and hyper-parameter tuning.
Pros of NNI
- More comprehensive AutoML toolkit with support for feature engineering, model compression, and hyperparameter tuning
- Provides a web UI for experiment management and visualization
- Supports a wider range of ML frameworks and cloud platforms
Cons of NNI
- Steeper learning curve due to its broader scope and more complex features
- Potentially heavier resource usage for large-scale experiments
- Less focus on configuration management compared to Hydra
Code Comparison
Hydra configuration example:
db:
driver: mysql
user: omry
pass: secret
NNI configuration example:
authorName: default
experimentName: example_mnist
trialConcurrency: 1
maxExecDuration: 1h
maxTrialNum: 10
trainingServicePlatform: local
searchSpacePath: search_space.json
While Hydra focuses on configuration management, NNI's configuration is geared towards experiment setup and hyperparameter search. Hydra's approach is more general-purpose, while NNI is specifically tailored for machine learning workflows.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
A framework for elegantly configuring complex applications.
Check the website for more information,
or click the thumbnail below for a one-minute video introduction to Hydra.
Releases
Stable
Hydra 1.3 is the stable version of Hydra.
- Documentation
- Installation :
pip install hydra-core --upgrade
See the NEWS.md file for a summary of recent changes to Hydra.
License
Hydra is licensed under MIT License.
Hydra Ecosystem
Check out these third-party libraries that build on Hydra's functionality:
- hydra-zen: Pythonic utilities for working with Hydra. Dynamic config generation capabilities, enhanced config store features, a Python API for launching Hydra jobs, and more.
- lightning-hydra-template: user-friendly template combining Hydra with Pytorch-Lightning for ML experimentation.
- hydra-torch: configen-generated configuration classes enabling type-safe PyTorch configuration for Hydra apps.
- NVIDIA's DeepLearningExamples repository contains a Hydra Launcher plugin, the distributed_launcher, which makes use of the pytorch distributed.launch API.
Ask questions in Github Discussions or StackOverflow (Use the tag #fb-hydra or #omegaconf):
Check out the Meta AI blog post to learn about how Hydra fits into Meta's efforts to reengineer deep learning platforms for interoperability.
Citing Hydra
If you use Hydra in your research please use the following BibTeX entry:
@Misc{Yadan2019Hydra,
author = {Omry Yadan},
title = {Hydra - A framework for elegantly configuring complex applications},
howpublished = {Github},
year = {2019},
url = {https://github.com/facebookresearch/hydra}
}
Top Related Projects
Facebook AI Research Sequence-to-Sequence Toolkit written in Python.
Canonical source repository for PyYAML
Flexible Python configuration system. The last one you will ever need.
Gin provides a lightweight configuration framework for Python
Composable transformations of Python+NumPy programs: differentiate, vectorize, JIT to GPU/TPU, and more
An open source AutoML toolkit for automate machine learning lifecycle, including feature engineering, neural architecture search, model compression and hyper-parameter tuning.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot