code: def test_sample():
      class Model(nn.Linear, PyroModule):
          def __init__(self, in_features, out_features):
              super().__init__(in_features, out_features)
              self.weight = PyroSample(
                  lambda self: dist.Normal(0, 1)
                  .expand([self.out_features, self.in_features])
                  .to_event(2)
              )
  
      class Guide(nn.Linear, PyroModule):
          def __init__(self, in_features, out_features):
              super().__init__(in_features, out_features)
              self.loc = PyroParam(torch.zeros_like(self.weight))
              self.scale = PyroParam(
                  torch.ones_like(self.weight),
                  constraint=constraints.positive,
              )
              self.weight = PyroSample(
                  lambda self: dist.Normal(
                      self.loc, self.scale
                  ).to_event(2)
              )
  
      data = torch.randn(8)
      model = Model(8, 2)
      guide = Guide(8, 2)
  
      optim = Adam({"lr": 0.01})
      svi = SVI(model, guide, optim, Trace_ELBO())
      for step in range(3):
          svi.step(data)
  
imports: import io
  import warnings
  import pytest
  import torch
  from torch import nn
  from torch.distributions import constraints, transform_to
  import pyro
  import pyro.distributions
  from pyro import poutine
  from pyro.infer import SVI, Trace_ELBO
  from pyro.nn.module import PyroModule, PyroParam, PyroSample, clear, to_pyro_module_
  from pyro.optim import Adam
  from tests.common import assert_equal
label_desc: Use image node_id 12 for calling a global function with example usage: test_sample() without return types