Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hparams: add Python layer for hparams and metrics (#2126)
Summary: This change introduces `HParam`, `Metric`, and `Experiment` classes, which represent their proto counterparts in a more Python-friendly way. It similarly includes a `Domain` class hierarchy, which does not correspond to a specific proto message, but rather unifies the domain variants defined on the `HParamInfo` proto. The design is roughly as in the original sketch of #1998. The primary benefit of this change is that having first-class domains enables clients to reuse the domain information for both the experiment summary and the underlying tuning algorithm. We don’t provide a method to do this out of the box, because we don’t actually provide any tuners at this time, but it’s easy to write (e.g.) a `sample_uniform` function like the one included in this commit. Then, sampling is as easy as ```python hparams = {h: sample_uniform(h.domain, rng) for h in HPARAMS} ``` It is also now more convenient to reference hparam values such that static analysis can detect potential typos, because the `HParam` objects themselves can be declared as constants and used as keys in a dict. Writing `hparams["dropuot"]` fails at runtime, but `hparams[HP_DROPUOT]` fails at lint time. As a pleasant bonus, hparam definitions are now more compact, fitting on one line instead of several. The demo code has net fewer lines. Manual summary writer management is still required. A future change will introduce a Keras callback to reduce this overhead. Test Plan: Some unit tests included, and the demo still works. wchargin-branch: hparams-structured-api
- Loading branch information