code: def _write_files_from_queue(
      file_queue: queue.Queue,
      result_queue: queue.Queue,
      planner: SavePlanner,
      inflight_threshhold: int,
      fs: AbstractFileSystem,
  ) -> None:
      try:
          while True:
              (
                  file_name,
                  storage_key,
                  write_items,
              ) = file_queue.get_nowait()
              loader: _TensorLoader
  
              if torch.cuda.is_available() and inflight_threshhold > 0:
                  loader = _OverlappingCpuLoader(
                      planner.resolve_data,
                      inflight_threshhold=inflight_threshhold,
                  )
              else:
                  loader = _SerialCpuLoader(
                      planner.resolve_data,
                  )
  
              tensor_w = [
                  wi
                  for wi in write_items
                  if wi.type != WriteItemType.BYTE_IO
              ]
              for write_item in tensor_w:
                  loader.add(_item_size(write_item), write_item)
              loader.start_loading()
  
              bytes_w = [
                  wi
                  for wi in write_items
                  if wi.type == WriteItemType.BYTE_IO
              ]
              write_results = []
  
              with fs.transaction:
                  with fsspec.open(file_name, "wb") as stream:
                      for write_item in bytes_w:
                          data = planner.resolve_data(write_item)
                          write_results.append(
                              _write_item(
                                  stream, data, write_item, storage_key
                              )
                          )
  
                      for tensor, write_item in loader.values():
                          assert tensor.is_cpu
                          write_results.append(
                              _write_item(
                                  stream,
                                  tensor,
                                  write_item,
                                  storage_key,
                              )
                          )
              result_queue.put(write_results)
      except queue.Empty:
          pass
  
imports: import collections
  import dataclasses
  import io
  import os
  import pickle
  import queue
  import threading
  from abc import ABC, abstractmethod
  from dataclasses import dataclass
  from typing import Callable, cast, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  import fsspec
  from fsspec import AbstractFileSystem
  from fsspec.core import url_to_fs
  import torch
  from torch import Tensor
  from torch._utils import _get_device_module
  from torch.distributed._shard._utils import narrow_tensor_by_index
  from torch.distributed.checkpoint.metadata import Metadata, MetadataIndex
  from torch.distributed.checkpoint.planner import LoadItemType, LoadPlan, LoadPlanner, ReadItem, SavePlan, SavePlanner, WriteItem, WriteItemType
  from torch.distributed.checkpoint.storage import StorageReader, StorageWriter, WriteResult
  from torch.distributed.checkpoint.utils import _create_file_view
  from torch.futures import Future
label_desc: Use image node_id 4 for calling a global function with example usage: _write_files_from_queue(file_queue, result_queue, planner, inflight_threshhold, fs) without return types