Example usage:

# Simple getting and setting.
print(pyro.settings.get())  # print all settings
print(pyro.settings.get("cholesky_relative_jitter"))  # print one
pyro.settings.set(cholesky_relative_jitter=0.5)  # set one
pyro.settings.set(**my_settings)  # set many

# Use as a contextmanager.
with pyro.settings.context(cholesky_relative_jitter=0.5):

# Use as a decorator.
fn = pyro.settings.context(cholesky_relative_jitter=0.5)(my_function)

# Register a new setting.
    "binomial_approx_sample_thresh",  # alias
    "pyro.distributions.torch",       # module
    "Binomial.approx_sample_thresh",  # deep name

# Register a new setting on a user-provided validator.
    "binomial_approx_sample_thresh",  # alias
    "pyro.distributions.torch",       # module
    "Binomial.approx_sample_thresh",  # deep name
def validate_thresh(thresh):  # called each time setting is set
    assert isinstance(thresh, float)
    assert thresh > 0

Default Settings

  • binomial_approx_log_prob_tol = 0.0

  • binomial_approx_sample_thresh = inf

  • cholesky_relative_jitter = 4.0

  • module_local_params = False

  • validate_distributions_pyro = True

  • validate_distributions_torch = True

  • validate_infer = True

  • validate_poutine = True

Settings Interface

get(alias: Optional[str] = None) Any[source]

Gets one or all global settings.


alias (str) – The name of a registered setting.


The currently set value.

set(**kwargs) None[source]

Sets one or more settings.


**kwargs – alias=value pairs.

context(**kwargs) Iterator[None][source]

Context manager to temporarily override one or more settings. This also works as a decorator.


**kwargs – alias=value pairs.

register(alias: str, modulename: str, deepname: str, validator: Optional[Callable] = None) Callable[source]

Register a global settings.

This should be declared in the module where the setting is defined.

This can be used either as a declaration:

settings.register("my_setting", __name__, "MY_SETTING")

or as a decorator on a user-defined validator function:

@settings.register("my_setting", __name__, "MY_SETTING")
def _validate_my_setting(value):
    assert isinstance(value, float)
    assert 0 < value
  • alias (str) – A valid python identifier serving as a settings alias. Lower snake case preferred, e.g. my_setting.

  • modulename (str) – The module name where the setting is declared, typically __name__.

  • deepname (str) – A .-separated string of names. E.g. for a module constant, use MY_CONSTANT. For a class attributue, use MyClass.my_attribute.

  • validator (callable) – Optional validator that inputs a value, possibly raises validation errors, and returns None.