簡體   English   中英

使用TensorFlow2進行分布式學習不起作用

[英]Distributed Learning with TensorFlow2 is not working

我正在嘗試使用Tensorflow版本2.0.0a(CPU版本)在VS-Code中使用分布式TF。

我正在使用Windows和Linux系統(兩台不同的計算機),兩者都很好。

對於已分發的TF,我按照https://www.tensorflow.org/alpha/guide/distribute_strategy上的教程進行了操作。

我已經嘗試過不同的端口並關閉防火牆。 我還嘗試將主系統從Windows切換到Linux,但現在我認為它可能是代碼的問題,或者可能是標記為實驗的TF版本。

from __future__ import absolute_import, division, print_function, unicode_literals

import tensorflow_datasets as tfds    
import tensorflow as tf    
import json    
import os

BUFFER_SIZE = 10000    
BATCH_SIZE = 64

def scale(image, label):

   image = tf.cast(image, tf.float32)
   image /= 255
   return image, label


datasets, info = tfds.load(name='mnist', with_info=True, as_supervised=True)

train_datasets_unbatched = datasets['train'].map(scale).shuffle(BUFFER_SIZE)

train_datasets = train_datasets_unbatched.batch(BATCH_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


#multiworker conf:

os.environ['TF_CONFIG'] = json.dumps({    
    'cluster': {    
        'worker': ["192.168.0.12:2468", "192.168.0.13:1357"]    
    },    
    'task': {'type': 'worker', 'index': 0}    
})

strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy()
NUM_WORKERS = 2

GLOBAL_BATCH_SIZE = 64 * NUM_WORKERS

#--------------------------------------------------------------------

#In the following line the error occurs

train_datasets = train_datasets_unbatched.batch(GLOBAL_BATCH_SIZE)

#--------------------------------------------------------------------


with strategy.scope():    
    multi_worker_model = build_and_compile_cnn_model()  
    multi_worker_model.fit(x=train_datasets, epochs=3)

我希望工作人員開始學習過程,但我得到錯誤:

“F tensorflow / core / framework / device_base.cc:33]設備未實現name()”

據我所知,每個工作者都應該有一個唯一的任務索引,例如:

你應該在第一台機器上:

os.environ['TF_CONFIG'] = json.dumps({    
    'cluster': {    
        'worker': ["192.168.0.12:2468", "192.168.0.13:1357"]    
    },    
    'task': {'type': 'worker', 'index': 0}    
})

在第二個:

os.environ['TF_CONFIG'] = json.dumps({    
    'cluster': {    
        'worker': ["192.168.0.12:2468", "192.168.0.13:1357"]    
    },    
    'task': {'type': 'worker', 'index': 1}    
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM