class_docstr: A TestCase mixin for common tests on inference gym targets.
class_docstr_tok: ["A","TestCase","mixin","for","common","tests","on","inference","gym","targets","."]
docstr: Validates that a model does not materialize args too early.
  
  Given a `model_fn` and a set of NumPy arrays in `kwargs` this verifies that
  none of the arrays are actually accessed by anything other than `dtype` and
  `shape` properties when accessing similarly lightweight properties of the
  model.
  
  Args:
    model_fn: A function that returns a Model.
    **kwargs: Keyword arguments to pass to `model_fn`. Each value should be a
      NumPy array.
docstr_tok: ["Validates","that","a","model","does","not","materialize","args","too","early",".","Given","a","`","model_fn","`","and","a","set","of","NumPy","arrays","in","`","kwargs","`","this","verifies","that","none","of","the","arrays","are","actually","accessed","by","anything","other","than","`","dtype","`","and","`","shape","`","properties","when","accessing","similarly","lightweight","properties","of","the","model",".","Args",":","model_fn",":","A","function","that","returns","a","Model",".","*","*","kwargs",":","Keyword","arguments","to","pass","to","`","model_fn","`",".","Each","value","should","be","a","NumPy","array","."]
code: def validate_deferred_materialization(self, model_fn, **kwargs):
      """Validates that a model does not materialize args too early.
  
      Given a `model_fn` and a set of NumPy arrays in `kwargs` this verifies that
      none of the arrays are actually accessed by anything other than `dtype` and
      `shape` properties when accessing similarly lightweight properties of the
      model.
  
      Args:
        model_fn: A function that returns a Model.
        **kwargs: Keyword arguments to pass to `model_fn`. Each value should be a
          NumPy array.
      """
      deferred_kwargs = {}
  
      def make_loud_materialization(name, value):
          if value is None:
              return None
  
          def do_assert():
              raise AssertionError(
                  "Erroneously materialized {}".format(name)
              )
  
          empty = np.zeros(0)
          return tfp.util.DeferredTensor(
              empty,
              lambda _: do_assert(),
              shape=value.shape,
              dtype=value.dtype,
          )
  
      for k, v in kwargs.items():
          deferred_kwargs[k] = make_loud_materialization(k, v)
  
      model = model_fn(**deferred_kwargs)
      _ = model.dtype
      _ = model.name
      _ = model.event_shape
      _ = model.default_event_space_bijector
      _ = model.sample_transformations
      _ = str(model)
  
imports: import collections
  import importlib
  from absl import flags
  from absl import logging
  import jax
  import numpy
  import tensorflow.compat.v2
  import tensorflow_probability
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 5 for calling the InferenceGymTestCase obj's underlying member method code with example usage: obj.validate_deferred_materialization(model_fn) and returns: tfp, None