code: def _serialize_exported(
      builder: flatbuffers.Builder, exp: export.Exported, vjp_order: int
  ) -> int:
      # Serialize bottom-up
      fun_name = builder.CreateString(exp.fun_name)
      in_tree = _serialize_pytreedef(builder, exp.in_tree)
      in_avals = _serialize_array(
          builder, _serialize_aval, exp.in_avals
      )
      out_tree = _serialize_pytreedef(builder, exp.out_tree)
      out_avals = _serialize_array(
          builder, _serialize_aval, exp.out_avals
      )
      in_shardings = _serialize_array(
          builder, _serialize_sharding, exp.in_shardings
      )
      out_shardings = _serialize_array(
          builder, _serialize_sharding, exp.out_shardings
      )
      ordered_effects = _serialize_array(
          builder, _serialize_effect, exp.ordered_effects
      )
      unordered_effects = _serialize_array(
          builder, _serialize_effect, exp.unordered_effects
      )
      disabled_safety_checks = _serialize_array(
          builder,
          _serialize_disabled_safety_check,
          exp.disabled_safety_checks,
      )
      lowering_platforms = _serialize_array(
          builder,
          lambda b, p: b.CreateString(p),
          exp.lowering_platforms,
      )
      mlir_module_serialized = builder.CreateByteVector(
          exp.mlir_module_serialized
      )
      module_kept_var_idx = builder.CreateNumpyVector(
          np.array(exp.module_kept_var_idx, dtype=np.uint16)
      )
  
      vjp = None
      if vjp_order > 0:
          if not exp.has_vjp():
              # TODO: add test
              raise ValueError(
                  "serialization of an Exported that does not have vjps of high-enough "
                  "order"
              )
          vjp = _serialize_exported(builder, exp.vjp(), vjp_order - 1)
  
      ser_flatbuf.ExportedStart(builder)
      ser_flatbuf.ExportedAddSerializationVersion(
          builder, _SERIALIZATION_VERSION
      )
      ser_flatbuf.ExportedAddFunctionName(builder, fun_name)
      ser_flatbuf.ExportedAddInTree(builder, in_tree)
      ser_flatbuf.ExportedAddInAvals(builder, in_avals)
      ser_flatbuf.ExportedAddOutTree(builder, out_tree)
      ser_flatbuf.ExportedAddOutAvals(builder, out_avals)
      ser_flatbuf.ExportedAddNrDevices(builder, exp.nr_devices)
      ser_flatbuf.ExportedAddInShardings(builder, in_shardings)
      ser_flatbuf.ExportedAddOutShardings(builder, out_shardings)
      ser_flatbuf.ExportedAddLoweringPlatforms(
          builder, lowering_platforms
      )
      ser_flatbuf.ExportedAddOrderedEffects(builder, ordered_effects)
      ser_flatbuf.ExportedAddUnorderedEffects(
          builder, unordered_effects
      )
      ser_flatbuf.ExportedAddDisabledChecks(
          builder, disabled_safety_checks
      )
      ser_flatbuf.ExportedAddMlirModuleSerialized(
          builder, mlir_module_serialized
      )
      ser_flatbuf.ExportedAddMlirModuleSerializationVersion(
          builder, exp.mlir_module_serialization_version
      )
      ser_flatbuf.ExportedAddModuleKeptVarIdx(
          builder, module_kept_var_idx
      )
      ser_flatbuf.ExportedAddUsesShapePolymorphism(
          builder, exp.uses_shape_polymorphism
      )
      if vjp is not None:
          ser_flatbuf.ExportedAddVjp(builder, vjp)
      return ser_flatbuf.ExportedEnd(builder)
  
imports: from typing import Callable, TypeVar
  from collections.abc import Sequence
  from jax._src import core
  from jax._src import dtypes
  from jax._src import effects
  from jax._src import tree_util
  from jax._src.lib import xla_client
  from jax.experimental.export import serialization_generated
  from jax.experimental.export import _export
  from jax.experimental import export
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: _serialize_exported(builder, exp, vjp_order) and returns: ser_flatbuf