Registry / serialization / hyperpyyaml

hyperpyyaml

JSON →
library1.2.3pypypi✓ verified 35d ago

HyperPyYAML is a Python library that extends the YAML syntax for enhanced interaction with Python objects and better hyperparameter definition. It is actively maintained, with a recent version 1.2.3, and typically releases updates as needed for bug fixes and new features.

serializationai-ml
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from hyperpyyaml import load_hyperpyyaml

This quickstart demonstrates how to load a YAML string containing HyperPyYAML extensions. It shows the use of `!ref` for referencing other parameters and `!new` for instantiating Python objects (like PyTorch modules) directly from the YAML.

import torch from hyperpyyaml import load_hyperpyyaml example_hyperparams_yaml = """ base_channels: 32 kernel_size: 11 padding: !ref <kernel_size> // 2 layer1: !new:torch.nn.Conv1d in_channels: 1 out_channels: !ref <base_channels> kernel_size: !ref <kernel_size> padding: !ref <padding> model: !new:torch.nn.Sequential - !ref <layer1> - !new:torch.nn.LeakyReLU """ # Using load_hyperpyyaml to parse the YAML string loaded_hparams = load_hyperpyyaml(example_hyperparams_yaml) print(loaded_hparams['base_channels']) print(loaded_hparams['padding']) print(loaded_hparams['model'])
Debug
Known footguns
breakingHyperPyYAML allows arbitrary code execution through its custom tags, which is a feature for flexible configuration. Treat all YAML files loaded with HyperPyYAML as you would Python code. Loading untrusted YAML files can lead to security vulnerabilities.
breakingCompatibility issues with `ruamel.yaml` versions have occurred. Specifically, versions of `ruamel.yaml` 0.19.0 and above can cause breakage due to API changes.
gotchaThe `!include` tag in older versions could break due to incorrect handling of overrides, particularly when no overrides were provided or the structure was unexpected.
gotchaThe `!ref` tag creates a shallow reference to the original YAML node, meaning changes to the referenced object will affect all references. If a deep copy is desired, use the `!copy` tag instead.
deprecatedOlder versions of HyperPyYAML had issues with Python 3.8+ compatibility, particularly concerning `ast.Constant`.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources