class_docstr: Given a callable that contains Pyro primitive calls,
  return a callable that runs the original, reusing the values at sites in trace
  at those sites in the new trace
  
  Consider the following Pyro program:
  
      >>> def model(x):
      ...     s = pyro.param("s", torch.tensor(0.5))
      ...     z = pyro.sample("z", dist.Normal(x, s))
      ...     return z ** 2
  
  ``replay`` makes ``sample`` statements behave as if they had sampled the values
  at the corresponding sites in the trace:
  
      >>> old_trace = pyro.poutine.trace(model).get_trace(1.0)
      >>> replayed_model = pyro.poutine.replay(model, trace=old_trace)
      >>> bool(replayed_model(0.0) == old_trace.nodes["_RETURN"]["value"])
      True
  
  :param fn: a stochastic function (callable containing Pyro primitive calls)
  :param trace: a :class:`~pyro.poutine.Trace` data structure to replay against
  :param params: dict of names of param sites and constrained values
      in fn to replay against
  :returns: a stochastic function decorated with a :class:`~pyro.poutine.replay_messenger.ReplayMessenger`
docstr: :param msg: current message at a trace site.
  
  At a sample site that appears in self.trace,
  returns the value from self.trace instead of sampling
  from the stochastic function at the site.
  
  At a sample site that does not appear in self.trace,
  reverts to default Messenger._pyro_sample behavior with no additional side effects.
docstr_tok: [":","param","msg",":","current","message","at","a","trace","site",".","At","a","sample","site","that","appears","in","self.trace",",","returns","the","value","from","self.trace","instead","of","sampling","from","the","stochastic","function","at","the","site",".","At","a","sample","site","that","does","not","appear","in","self.trace",",","reverts","to","default","Messenger._pyro_sample","behavior","with","no","additional","side","effects","."]
code: def _pyro_sample(self, msg: "Message") -> None:
      """
      :param msg: current message at a trace site.
  
      At a sample site that appears in self.trace,
      returns the value from self.trace instead of sampling
      from the stochastic function at the site.
  
      At a sample site that does not appear in self.trace,
      reverts to default Messenger._pyro_sample behavior with no additional side effects.
      """
      assert msg["name"] is not None
      name = msg["name"]
      if self.trace is not None and name in self.trace:
          guide_msg = self.trace.nodes[name]
          if msg["is_observed"]:
              return None
          if guide_msg["type"] != "sample" or guide_msg["is_observed"]:
              raise RuntimeError(
                  "site {} must be sampled in trace".format(name)
              )
          msg["done"] = True
          msg["value"] = guide_msg["value"]
          msg["infer"] = guide_msg["infer"]
  
imports: from typing import TYPE_CHECKING, Dict, Optional
  from pyro.poutine.messenger import Messenger
label_desc: Use image node_id 2 for calling the ReplayMessenger obj's underlying member method code with example usage: obj._pyro_sample(msg) and returns: None