class_docstr: Type spec for `JointDistributionNamed`.
class_docstr_tok: ["Type","spec","for","`","JointDistributionNamed","`","."]
code: def from_instance(cls, obj):
      model_param_specs, callable_model_params = [], []
      for d in tf.nest.flatten(obj.model):
          if auto_composite_tensor.is_composite_tensor(d):
              model_param_specs.append(
                  d._type_spec
              )  # pylint: disable=protected-access
          else:
              callable_model_params.append(d)
      non_tensor_params = {
          k: v for k, v in obj.parameters.items() if k != "model"
      }
  
      if callable_model_params:
          callable_params = dict(model=callable_model_params)
          param_specs = dict(model=model_param_specs)
      else:
          callable_params = None
          param_specs = dict(
              model=tf.nest.pack_sequence_as(
                  obj.model, model_param_specs
              )
          )
  
      spec = cls(
          param_specs=param_specs,
          non_tensor_params=non_tensor_params,
          non_identifying_kwargs=("name",),
          omit_kwargs=("parameters",),
          prefer_static_value=("batch_ndims",),
          callable_params=callable_params,
      )
  
      if callable_params:
          # Store the nested structure of `model` so that it can be reconstituted in
          # `_from_components`. If the typespec is built by `_deserialize`, this
          # attribute will not exist -- however, the type spec serializable only if
          # there are no callable elements of `model`, in which case the nested
          # structure of `model` is recorded in `param_specs`.
          structure_with_callables = tf.nest.map_structure(
              lambda x: None
              if auto_composite_tensor.is_composite_tensor(x)
              else x,
              obj.model,
          )
          spec._structure_with_callables = structure_with_callables
      return spec
  
imports: import collections
  import functools
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.internal import auto_composite_tensor
  from tensorflow_probability.python.internal import distribution_util
label_desc: Use image node_id 4 for calling the _JointDistributionNamedSpec obj's underlying member method code with example usage: obj.from_instance(cls, obj) and returns: spec