code: def _extract_flow(layers: Sequence[MessagePassing]) -> FlowDirection:
      """Extract the flow direction from the message passing layers."""
      flow: Optional[FlowDirection] = None
      for layer in layers:
          if flow is None:
              if layer.flow not in FLOW_DIRECTIONS:
                  raise AssertionError(
                      f"Invalid flow: {layer.flow}. Valid flows: {FLOW_DIRECTIONS}"
                  )
              flow = layer.flow
          elif flow != layer.flow:
              raise ValueError(
                  f"Different flow directions across layers: {[l.flow for l in layers]}"
              )
      # default flow
      return flow or "source_to_target"
  
imports: from abc import ABC, abstractmethod
  from typing import Collection, Literal, Optional, Sequence
  import torch
  from class_resolver import ClassResolver, HintOrType, OneOrManyHintOrType, OneOrManyOptionalKwargs, OptionalKwargs
  from class_resolver.contrib.torch import activation_resolver
  from docdata import parse_docdata
  from torch import nn
  from .representation import Representation
  from .utils import ShapeError
  from ..triples.triples_factory import CoreTriplesFactory
  from ..typing import OneOrSequence
  from ..utils import get_edge_index, upgrade_to_sequence
label_desc: Use image node_id 1 for calling a global function with example usage: _extract_flow(layers) and returns: unknown