class_docstr: TF version of ModelV2, which should contain a tf keras Model.
  
  Note that this class by itself is not a valid model unless you
  implement forward() in a subclass.
class_docstr_tok: ["TF","version","of","ModelV2",",","which","should","contain","a","tf","keras","Model",".","Note","that","this","class","by","itself","is","not","a","valid","model","unless","you","implement","forward","(",")","in","a","subclass","."]
code: def _find_sub_modules(current_key, struct):
      # Keras Model: key=k + "." + var-name (replace '/' by '.').
      if isinstance(struct, tf.keras.models.Model) or isinstance(
          struct, tf.Module
      ):
          ret = {}
          for var in struct.variables:
              name = re.sub("/", ".", var.name)
              key = current_key + "." + name
              ret[key] = var
          return ret
      # Other TFModelV2: Include its vars into ours.
      elif isinstance(struct, TFModelV2):
          return {
              current_key + "." + key: var
              for key, var in struct.variables(as_dict=True).items()
          }
      # tf.Variable
      elif isinstance(struct, tf.Variable):
          return {current_key: struct}
      # List/Tuple.
      elif isinstance(struct, (tuple, list)):
          ret = {}
          for i, value in enumerate(struct):
              sub_vars = TFModelV2._find_sub_modules(
                  current_key + "_{}".format(i), value
              )
              ret.update(sub_vars)
          return ret
      # Dict.
      elif isinstance(struct, dict):
          if current_key:
              current_key += "_"
          ret = {}
          for key, value in struct.items():
              sub_vars = TFModelV2._find_sub_modules(
                  current_key + str(key), value
              )
              ret.update(sub_vars)
          return ret
      return {}
  
file_path: ray/rllib/models/tf/tf_modelv2.py
imports: import contextlib
  import gymnasium
  import re
  from typing import Dict, List, Union
  from ray.util import log_once
  from ray.rllib.models.modelv2 import ModelV2
  from ray.rllib.utils.annotations import override, PublicAPI
  from ray.rllib.utils.deprecation import deprecation_warning
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.typing import ModelConfigDict, TensorType
label_desc: Use image node_id 7 for calling the TFModelV2 obj's underlying member method code with example usage: obj._find_sub_modules(current_key, struct) and returns: dict, ret, unknown, dict, ret, ret