Parameters¶

Parameters in Pyro are basically thin wrappers around PyTorch Tensors that carry unique names. As such Parameters are the primary stateful objects in Pyro. Users typically interact with parameters via the Pyro primitive pyro.param. Parameters play a central role in stochastic variational inference, where they are used to represent point estimates for the parameters in parameterized families of models and guides.

ParamStore¶

class ParamStoreDict[source]

Bases: object

Global store for parameters in Pyro. This is basically a key-value store. The typical user interacts with the ParamStore primarily through the primitive pyro.param.

See Intro Part II for further discussion and SVI Part I for some examples.

Some things to bear in mind when using parameters in Pyro:

• parameters must be assigned unique names
• the init_tensor argument to pyro.param is only used the first time that a given (named) parameter is registered with Pyro.
• for this reason, a user may need to use the clear() method if working in a REPL in order to get the desired behavior. this method can also be invoked with pyro.clear_param_store().
• the internal name of a parameter within a PyTorch nn.Module that has been registered with Pyro is prepended with the Pyro name of the module. so nothing prevents the user from having two different modules each of which contains a parameter named weight. by contrast, a user can only have one top-level parameter named weight (outside of any module).
• parameters can be saved and loaded from disk using save and load.
clear()[source]

Clear the ParamStore

get_all_param_names()[source]

Get all parameter names in the ParamStore

get_param(name, init_tensor=None, constraint=<torch.distributions.constraints._Real object>)[source]

Get parameter from its name. If it does not yet exist in the ParamStore, it will be created and stored. The Pyro primitive pyro.param dispatches to this method.

Parameters: name (str) – parameter name init_tensor (torch.Tensor) – initial tensor parameter torch.Tensor
get_state()[source]

Get the ParamStore state.

load(filename)[source]

Parameters: filename – file name to load from
named_parameters()[source]

Returns an iterator over tuples of the form (name, parameter) for each parameter in the ParamStore

param_name(p)[source]

Get parameter name from parameter

Parameters: p – parameter parameter name
replace_param(param_name, new_param, old_param)[source]

Replace the param param_name with current value old_param with the new value new_param

Parameters: param_name (str) – parameter name new_param (torch.Tensor) – the paramater to be put into the ParamStore old_param – the paramater to be removed from the ParamStore
save(filename)[source]

Save parameters to disk

Parameters: filename – file name to save to
set_state(state)[source]

Set the ParamStore state using state from a previous get_state() call

module_from_param_with_module_name(param_name)[source]
param_with_module_name(pyro_name, param_name)[source]
user_param_name(param_name)[source]