votes up 2

Unexpected task_type: %r

Package:
keras
github stars 51164
Exception Class:
ValueError

Raise code

        else:
          server.join()
    elif task_type == _TaskType.EVALUATOR:
      return _run_single_worker(eval_fn, eval_strategy, cluster_spec, task_type,
                                task_id, session_config, rpc_layer)
    else:
      if task_type != _TaskType.PS:
        raise ValueError("Unexpected task_type: %r" % task_type)
      server.join()


def normalize_cluster_spec(cluster_spec):
  """Makes `cluster_spec` into a `ClusterSpec` object.

  Args: """

Ways to fix

votes up 0 votes down

Code to reproduce(WRONG)

import tensorflow as tf
import numpy as np
import json
import os

os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
os.environ.pop('TF_CONFIG', None)
tf_config = {
    'cluster': {
        'worker': ['localhost:8081']
    },
    'task': {'type': 'workr', 'index': 0}  # Providing a task type other than chief, worker, evaluator, ps and None raises the unrecognised task_type exception
}

os.environ["TF_CONFIG"] = json.dumps(tf_config)

mirrored_strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy()

with mirrored_strategy.scope():
  model = tf.keras.Sequential([tf.keras.layers.Dense(1, input_shape=(1,))])

model.compile(loss='mse', optimizer='sgd')

dataset = tf.data.Dataset.from_tensors(([1.],[1.])).repeat(100).batch(10)

model.fit(dataset,epochs=2)
model.evaluate(dataset)

Working Solution(FIXED)

import tensorflow as tf
import numpy as np
import json
import os

os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
os.environ.pop('TF_CONFIG', None)
tf_config = {
    'cluster': {
        'worker': ['localhost:8081']
    },
    'task': {'type': 'worker', 'index': 0}  # Fixed the exception by providing the task as worker
}

os.environ["TF_CONFIG"] = json.dumps(tf_config)

mirrored_strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy()

with mirrored_strategy.scope():
  model = tf.keras.Sequential([tf.keras.layers.Dense(1, input_shape=(1,))])

model.compile(loss='mse', optimizer='sgd')

dataset = tf.data.Dataset.from_tensors(([1.],[1.])).repeat(100).batch(10)

model.fit(dataset,epochs=2)
model.evaluate(dataset)
Jun 12, 2021 umangtaneja98 answer
umangtaneja98 741

Add a possible fix

Please authorize to post fix