code: def test_elbo_enumerate_plate_4(outer_obs, inner_obs, scale):
      #    a ---> outer_obs
      #      \
      #  +-----\------------------+
      #  |       \                |
      #  | b ---> inner_obs   N=2 |
      #  +------------------------+
      # This tests two different observations, one outside and one inside an plate.
      pyro.param(
          "probs_a",
          torch.tensor([0.4, 0.6]),
          constraint=constraints.simplex,
      )
      pyro.param(
          "probs_b",
          torch.tensor([0.6, 0.4]),
          constraint=constraints.simplex,
      )
      pyro.param("locs", torch.tensor([-1.0, 1.0]))
      pyro.param(
          "scales",
          torch.tensor([1.0, 2.0]),
          constraint=constraints.positive,
      )
      outer_data = torch.tensor(2.0)
      inner_data = torch.tensor([0.5, 1.5])
  
      @handlers.scale(scale=scale)
      def auto_model():
          probs_a = pyro.param("probs_a")
          probs_b = pyro.param("probs_b")
          locs = pyro.param("locs")
          scales = pyro.param("scales")
          a = pyro.sample(
              "a",
              dist.Categorical(probs_a),
              infer={"enumerate": "parallel"},
          )
          if outer_obs:
              pyro.sample(
                  "outer_obs",
                  dist.Normal(0.0, scales[a]),
                  obs=outer_data,
              )
          with pyro.plate("inner", 2):
              b = pyro.sample(
                  "b",
                  dist.Categorical(probs_b),
                  infer={"enumerate": "parallel"},
              )
              if inner_obs:
                  pyro.sample(
                      "inner_obs",
                      dist.Normal(locs[b], scales[a]),
                      obs=inner_data,
                  )
  
      @handlers.scale(scale=scale)
      def hand_model():
          probs_a = pyro.param("probs_a")
          probs_b = pyro.param("probs_b")
          locs = pyro.param("locs")
          scales = pyro.param("scales")
          a = pyro.sample(
              "a",
              dist.Categorical(probs_a),
              infer={"enumerate": "parallel"},
          )
          if outer_obs:
              pyro.sample(
                  "outer_obs",
                  dist.Normal(0.0, scales[a]),
                  obs=outer_data,
              )
          for i in pyro.plate("inner", 2):
              b = pyro.sample(
                  "b_{}".format(i),
                  dist.Categorical(probs_b),
                  infer={"enumerate": "parallel"},
              )
              if inner_obs:
                  pyro.sample(
                      "inner_obs_{}".format(i),
                      dist.Normal(locs[b], scales[a]),
                      obs=inner_data[i],
                  )
  
      def guide():
          pass
  
      elbo = infer.TraceEnum_ELBO(max_plate_nesting=1)
      auto_loss = elbo.differentiable_loss(auto_model, guide)
      elbo = infer.TraceEnum_ELBO(max_plate_nesting=0)
      hand_loss = elbo.differentiable_loss(hand_model, guide)
      _check_loss_and_grads(hand_loss, auto_loss)
  
imports: import logging
  import os
  import pyroapi
  import pytest
  import torch
  from torch.autograd import grad
  from torch.distributions import constraints
  from pyro.ops.indexing import Vindex
  from pyro.util import torch_isnan
  from tests.common import assert_equal, xfail_param
label_desc: Use image node_id 9 for calling a global function with example usage: test_elbo_enumerate_plate_4(outer_obs, inner_obs, scale) without return types