code: def bm_schools_model(data, draws, chains):
      import beanmachine.ppl as bm  # pylint: disable=import-error
      import torch
      import torch.distributions as dist
  
      class EightSchools:
          @bm.random_variable
          def mu(self):
              return dist.Normal(0, 5)
  
          @bm.random_variable
          def tau(self):
              return dist.HalfCauchy(5)
  
          @bm.random_variable
          def eta(self):
              return dist.Normal(0, 1).expand((data["J"],))
  
          @bm.functional
          def theta(self):
              return self.mu() + self.tau() * self.eta()
  
          @bm.random_variable
          def obs(self):
              return dist.Normal(
                  self.theta(), torch.from_numpy(data["sigma"]).float()
              )
  
      model = EightSchools()
  
      prior = bm.GlobalNoUTurnSampler().infer(
          queries=[model.mu(), model.tau(), model.eta()],
          observations={},
          num_samples=draws,
          num_adaptive_samples=500,
          num_chains=chains,
      )
  
      posterior = bm.GlobalNoUTurnSampler().infer(
          queries=[model.mu(), model.tau(), model.eta()],
          observations={
              model.obs(): torch.from_numpy(data["y"]).float()
          },
          num_samples=draws,
          num_adaptive_samples=500,
          num_chains=chains,
      )
      return model, prior, posterior
  
imports: import gzip
  import importlib
  import logging
  import os
  import sys
  from typing import Any, Dict, List, Optional, Tuple, Union
  import cloudpickle
  import numpy
  import pytest
  from _pytest.outcomes import Skipped
  from packaging.version import Version
  from ..data import InferenceData, from_dict
label_desc: Use image node_id 21 for calling a global function with example usage: bm_schools_model(data, draws, chains) and returns: model,  prior,  posterior, dist, dist, dist, unknown, dist