class_docstr: Declares a Pyro-managed random attribute of a :class:`PyroModule`, similar
  to :func:`pyro.sample <pyro.primitives.sample>`.
  
  This can be used either to set attributes of :class:`PyroModule`
  instances::
  
      assert isinstance(my_module, PyroModule)
      my_module.x = PyroSample(Normal(0, 1))                    # independent
      my_module.y = PyroSample(lambda self: Normal(self.x, 1))  # dependent
  
  or EXPERIMENTALLY as a decorator on lazy initialization methods::
  
      class MyModule(PyroModule):
          @PyroSample
          def x(self):
              return Normal(0, 1)       # independent
  
          @PyroSample
          def y(self):
              return Normal(self.x, 1)  # dependent
  
          def forward(self):
              return self.y             # accessed like a @property
  
  :param prior: distribution object or function that inputs the
      :class:`PyroModule` instance ``self`` and returns a distribution
      object.
class_docstr_tok: ["Declares","a","Pyro-managed","random","attribute","of","a",":","class",":","`","PyroModule","`",",","similar","to",":","func",":","`","pyro.sample","<","pyro.primitives.sample",">","`",".","This","can","be","used","either","to","set","attributes","of",":","class",":","`","PyroModule","`","instances",":",":","assert","isinstance","(","my_module",",","PyroModule",")","my_module.x","=","PyroSample","(","Normal","(","0",",","1",")",")","#","independent","my_module.y","=","PyroSample","(","lambda","self",":","Normal","(","self.x",",","1",")",")","#","dependent","or","EXPERIMENTALLY","as","a","decorator","on","lazy","initialization","methods",":",":","class","MyModule","(","PyroModule",")",":","@","PyroSample","def","x","(","self",")",":","return","Normal","(","0",",","1",")","#","independent","@","PyroSample","def","y","(","self",")",":","return","Normal","(","self.x",",","1",")","#","dependent","def","forward","(","self",")",":","return","self.y","#","accessed","like","a","@","property",":","param","prior",":","distribution","object","or","function","that","inputs","the",":","class",":","`","PyroModule","`","instance","``","self","``","and","returns","a","distribution","object","."]
code: def __init__(self, prior):
      super().__init__()
      if not hasattr(prior, "sample"):  # if not a distribution
          assert 1 == sum(
              1
              for p in inspect.signature(prior).parameters.values()
              if p.default is inspect.Parameter.empty
          ), "prior should take the single argument 'self'"
          self.name = getattr(prior, "__name__", None)
          if self.name is not None:
              # Ensure decorated function is accessible for pickling.
              prior.__name__ = "_pyro_prior_" + prior.__name__
              qualname = prior.__qualname__.rsplit(".", 1)
              qualname[-1] = prior.__name__
              prior.__qualname__ = ".".join(qualname)
  
imports: import functools
  import inspect
  import weakref
  from collections import OrderedDict, namedtuple
  import torch
  from torch.distributions import constraints, transform_to
  import pyro
  from pyro.ops.provenance import detach_provenance
  from pyro.poutine.runtime import _PYRO_PARAM_STORE
label_desc: Use image node_id 1 to create a new PyroSample object from inherited base classes:  with example: obj = PyroSample(prior)