code: def validate_composition(
      adapter_composition: AdapterCompositionBlock,
      level=0,
      model_type=None,
  ):
      if level > 1 and not (
          isinstance(adapter_composition, Stack)
          or isinstance(adapter_composition, str)
      ):
          raise ValueError(
              f"Adapter setup is too deep. Cannot have {adapter_composition} at level {level}."
          )
      if isinstance(adapter_composition, AdapterCompositionBlock):
          block_type = type(adapter_composition)
          if model_type and block_type in SUPPORTED_MODELS:
              if model_type not in SUPPORTED_MODELS[block_type]:
                  raise ValueError(
                      f"Models of type {model_type} don't support adapter composition using {block_type.__name__}."
                  )
          for child in adapter_composition:
              if (
                  not type(child)
                  in ALLOWED_NESTINGS[type(adapter_composition)]
              ):
                  raise ValueError(
                      f"Adapter setup is invalid. Cannot nest {child} in {adapter_composition}"
                  )
              # recursively validate children
              validate_composition(child, level=level + 1)
  
imports: import itertools
  from collections.abc import Sequence
  from typing import List, Optional, Set, Tuple, Union
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: validate_composition(adapter_composition, level, model_type) without return types