code: def dataframe_to_xshards(
      data,
      validation_data,
      feature_cols,
      label_cols,
      mode="fit",
      num_workers=None,
      accept_str_col=False,
      shard_size=None,
  ):
      from pyspark.sql import DataFrame
  
      valid_mode = {"fit", "evaluate", "predict"}
      invalidInputError(
          mode in valid_mode,
          f"invalid mode {mode} " f"mode should be one of {valid_mode}",
      )
      invalidInputError(
          validation_data is None
          or isinstance(validation_data, DataFrame),
          "validation data must be a spark DataFrame when data is a DataFrame",
      )
      invalidInputError(
          feature_cols is not None,
          "feature_col must be provided if data is a spark dataframe",
      )
  
      if mode != "predict":
          invalidInputError(
              label_cols is not None,
              "label_cols must be provided if data is a spark dataframe",
          )
          # avoid empty partition for worker
          if data.rdd.getNumPartitions() < num_workers:
              data = data.repartition(num_workers)
          if validation_data is not None:
              num_data_part = data.rdd.getNumPartitions()
              validation_data = validation_data.repartition(
                  num_data_part
              )
  
      data = _dataframe_to_xshards(
          data, feature_cols, label_cols, accept_str_col, shard_size
      )
      if validation_data is not None:
          validation_data = _dataframe_to_xshards(
              validation_data,
              feature_cols,
              label_cols,
              accept_str_col,
              shard_size,
          )
  
      return data, validation_data
  
imports: from contextlib import closing
  import socket
  import sys
  import tempfile
  import shutil
  from bigdl.dllib.utils import log4Error
  from bigdl.dllib.utils.common import callBigDlFunc
  from bigdl.dllib.utils.file_utils import get_file_list, is_local_path
  from bigdl.orca.data import SparkXShards
  from bigdl.orca.data.utils import get_size
  from bigdl.orca.data.file import put_local_dir_tree_to_remote, put_local_file_to_remote, get_remote_file_to_local, get_remote_dir_to_local
  from bigdl.dllib.utils.utils import convert_row_to_numpy
  from functools import partial
  import numpy
  from bigdl.orca.common import SafePickle
  import os
  import subprocess
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 20 for calling a global function with example usage: dataframe_to_xshards(data, validation_data, feature_cols, label_cols, mode, num_workers, accept_str_col, shard_size) and returns: data,  validation_data