code: def main_fun(args, ctx):
      import tensorflow_datasets as tfds
      import tensorflow as tf
      from tensorflowonspark import compat
  
      tfds.disable_progress_bar()
  
      strategy = (
          tf.distribute.experimental.MultiWorkerMirroredStrategy()
      )
  
      BUFFER_SIZE = args.buffer_size
      BATCH_SIZE = args.batch_size
      NUM_WORKERS = args.cluster_size
  
      # Scaling MNIST data from (0, 255] to (0., 1.]
      def scale(image, label):
          return tf.cast(image, tf.float32) / 255, label
  
      # workaround for https://github.com/tensorflow/datasets/issues/1405
      datasets = tfds.load(
          name="mnist", split="train", as_supervised=True
      )
      options = tf.data.Options()
      options.experimental_distribute.auto_shard_policy = (
          tf.data.experimental.AutoShardPolicy.DATA
      )
      train_datasets_unbatched = (
          datasets.with_options(options)
          .repeat()
          .map(scale)
          .shuffle(BUFFER_SIZE)
      )
  
      def build_and_compile_cnn_model():
          model = tf.keras.Sequential(
              [
                  tf.keras.layers.Conv2D(
                      32, 3, activation="relu", input_shape=(28, 28, 1)
                  ),
                  tf.keras.layers.MaxPooling2D(),
                  tf.keras.layers.Flatten(),
                  tf.keras.layers.Dense(64, activation="relu"),
                  tf.keras.layers.Dense(10, activation="softmax"),
              ]
          )
          model.compile(
              loss=tf.keras.losses.sparse_categorical_crossentropy,
              optimizer=tf.keras.optimizers.SGD(learning_rate=0.001),
              metrics=["accuracy"],
          )
          return model
  
      # single node
      # single_worker_model = build_and_compile_cnn_model()
      # single_worker_model.fit(x=train_datasets, epochs=3)
  
      # Here the batch size scales up by number of workers since
      # `tf.data.Dataset.batch` expects the global batch size. Previously we used 64,
      # and now this becomes 128.
      GLOBAL_BATCH_SIZE = BATCH_SIZE * NUM_WORKERS
      train_datasets = train_datasets_unbatched.batch(GLOBAL_BATCH_SIZE)
  
      # this fails
      # callbacks = [tf.keras.callbacks.ModelCheckpoint(filepath=args.model_dir)]
      tf.io.gfile.makedirs(args.model_dir)
      filepath = args.model_dir + "/weights-{epoch:04d}"
      callbacks = [
          tf.keras.callbacks.ModelCheckpoint(
              filepath=filepath, verbose=1, save_weights_only=True
          ),
          tf.keras.callbacks.TensorBoard(log_dir=args.model_dir),
      ]
  
      with strategy.scope():
          multi_worker_model = build_and_compile_cnn_model()
      multi_worker_model.fit(
          x=train_datasets,
          epochs=args.epochs,
          steps_per_epoch=args.steps_per_epoch,
          callbacks=callbacks,
      )
  
      compat.export_saved_model(
          multi_worker_model, args.export_dir, ctx.job_name == "chief"
      )
  
label_desc: Use image node_id 1 for calling a global function with example usage: main_fun(args, ctx) and returns: unknown,  label, model