code: def write_ckpt(pytree, dir, shard):
      # ckpt_dir = Path(dir)
      # ckpt_dir.mkdir(parents=True, exist_ok=True)
  
      flattened, structure = jax.tree_flatten(pytree)
  
      start = time.time()
      # cpu_flattened = jax.device_put(flattened, cpu_device)
      cpu_flattened = index_weights(flattened, shard)
      # print(f"Moved indexed in {time.time() - start:.06}s")
  
      cpu_flattened_chunked = split(cpu_flattened, pieces)
  
      # start = time.time()
      # cpu_float = move_weights(cpu_flattened)
      # print(f"changed weight types in {time.time() - start:.06}s")
  
      with multiprocessing.pool.ThreadPool(pieces) as p:
          write_fn = functools.partial(
              write, ckpt_dir=f"{dir}shard_{shard}/"
          )
  
          start = time.time()
          list(
              (
                  p.imap_unordered(
                      write_fn, enumerate(cpu_flattened_chunked)
                  )
              )
          )
  
imports: import functools
  import io
  import json
  import time
  import jax
  import jax.numpy
  import numpy
  import multiprocessing
  import ray
  from smart_open import open
  from mesh_transformer.util import head_print
label_desc: Use image node_id 5 for calling a global function with example usage: write_ckpt(pytree, dir, shard) without return types