code: def global_array_to_host_local_array_impl(
      arr: Any, *, global_mesh: jax.sharding.Mesh, pspec: Any
  ):
      if pspec is None:
          raise ValueError(
              "`None` is not a valid input to the pspecs argument. Please use "
              "jax.sharding.PartitionSpec() if you wanted to replicate your input."
          )
      # If the Array is already fully addressable i.e. host local, return it.
      if isinstance(arr, array.ArrayImpl) and arr.is_fully_addressable:
          return arr
  
      global_sharding = jax.sharding.NamedSharding(global_mesh, pspec)
      local_sharding = jax.sharding.NamedSharding(
          global_mesh.local_mesh, pspec
      )
      local_aval = _global_to_local_aval(
          core.ShapedArray(arr.shape, arr.dtype), global_mesh, pspec
      )
  
      if isinstance(arr, array.ArrayImpl):
          if arr.sharding.is_equivalent_to(global_sharding, arr.ndim):
              arrays = arr._arrays
          else:
              resharded_array = jax.device_put(arr, global_sharding)
              arrays = resharded_array._arrays
          return array.ArrayImpl(
              local_aval, local_sharding, arrays, committed=True
          )
      else:
          # numpy array can show up here during AD.
          arr = xla.canonicalize_dtype(arr)
          arrays = [
              arr[index]
              for d, index in local_sharding.devices_indices_map(
                  arr.shape
              ).items()
          ]
          return pxla.batched_device_put(
              local_aval,
              local_sharding,
              arrays,
              list(global_mesh.local_mesh.devices.flat),
          )
  
imports: from __future__ import annotations
  from functools import partial, lru_cache
  from typing import Optional
  import zlib
  from typing import Any
  import jax
  import jax.numpy
  from jax.tree_util import tree_flatten, tree_map, tree_unflatten
  from jax._src import core
  from jax._src.interpreters import ad
  from jax._src.interpreters import batching
  from jax._src.interpreters import mlir
  from jax._src import array
  from jax._src import sharding_impls
  from jax._src.interpreters import pxla
  from jax.interpreters import xla
  from jax._src import pjit
  from jax.experimental.pjit import pjit
  from jax.sharding import PartitionSpec
  from jax._src import distributed
  from jax._src.util import safe_zip
  import numpy
label_desc: Use image node_id 17 for calling a global function with example usage: global_array_to_host_local_array_impl(arr) and returns: arr, array, pxla