code: def test_name_preserved_by_to_pyro_module():
      features = torch.randn(4)
      data = torch.randn(3)
  
      class Model(PyroModule):
          def __init__(self):
              super().__init__()
              self.scale = PyroParam(
                  torch.ones(3), constraints.positive
              )
              self.loc = torch.nn.Linear(4, 3)
  
          def forward(self, features, data):
              loc = self.loc(features)
              scale = self.scale
              with pyro.plate("data", len(data)):
                  pyro.sample("obs", dist.Normal(loc, scale), obs=data)
  
      model = Model()
      params = list(model.parameters())
      param_names = set()
  
      def optim_config(param_name):
          param_names.add(param_name)
          return {"lr": 0.0}
  
      # Record while model.loc is an nn.Module.
      loss = (
          poutine.trace(model).get_trace(features, data).log_prob_sum()
      )
      loss.backward()
      adam = optim.Adam(optim_config)
      adam(params)
      assert param_names
      expected_param_names = param_names.copy()
      del adam, loss
      param_names.clear()
      pyro.clear_param_store()
  
      # Record while model.loc is a PyroModule.
      to_pyro_module_(model.loc)
      loss = (
          poutine.trace(model).get_trace(features, data).log_prob_sum()
      )
      loss.backward()
      adam = optim.Adam(optim_config)
      adam(params)
      assert param_names
      actual_param_names = param_names.copy()
      del adam, loss
      param_names.clear()
      pyro.clear_param_store()
  
      assert actual_param_names == {"scale", "loc.weight", "loc.bias"}
      assert actual_param_names == expected_param_names
  
imports: import os
  from tempfile import TemporaryDirectory
  from unittest import TestCase
  import pytest
  import torch
  from torch.distributions import constraints
  import pyro
  import pyro.distributions
  import pyro.optim
  from pyro import poutine
  from pyro.distributions import Normal, Uniform
  from pyro.infer import SVI, Trace_ELBO, TraceGraph_ELBO
  from pyro.nn.module import PyroModule, PyroParam, to_pyro_module_
  from pyro.optim.optim import is_scheduler
  from tests.common import assert_equal
label_desc: Use image node_id 8 for calling a global function with example usage: test_name_preserved_by_to_pyro_module() and returns: dict