Skip to content

Problem initializing DT_DOUBLE variables in distributed TF #4767

Closed

Description

@yaroslavvb

If you save code below as init_bug.py and run as python init_bug.py, it crashes with error below when running init_op. It works fine using local session or when changing dtype to np.float32. Also fails for np.int32 type. Tried on 0.11rc0 on MacOS

tensorflow.python.framework.errors.InternalError: Output 0 of type float_ref does not match declared output type double_ref for node Variable = Variable[container="", dtype=DT_DOUBLE, shape=[], shared_name="", _device="/job:worker/replica:0/task:0/cpu:0"]()

import subprocess, sys
import tensorflow as tf
import numpy as np

worker_ip="127.0.0.1:12222"
cluster = {"worker": [worker_ip]}
clusterspec = tf.train.ClusterSpec(cluster).as_cluster_def()

def launch_worker():
  def runcmd(cmd): subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT)
  runcmd("python init_bug.py worker")

if __name__=='__main__':
  if len(sys.argv)<2:
    dtype=np.float64
    global_param_var = tf.Variable(np.array(1).astype(dtype), dtype=dtype)
    init_op = tf.initialize_all_variables()
    launch_worker()
    sess = tf.Session("grpc://"+worker_ip)
    sess.run(init_op)

  else:
    print("Launching worker")
    server = tf.train.Server(clusterspec, job_name="worker")
    server.join()

Activity

  1. yaroslavvb commented on Oct 4, 2016

    @yaroslavvb
    ContributorAuthor

    same problem if I use ones_initializer or zeros_initializer with any dtype other than float32 @mrry

  2. mrry commented on Oct 4, 2016

    @mrry
    Contributor

    I ran your program (with an additional print sess.run(global_param_var) to confirm it was working) using 0.11rc0 on Linux, and I couldn't reproduce your problem.

    I presume you're falling foul of implicit by-name variable sharing between sessions on the same server. If you create a DT_FLOAT variable called "Variable" on the server, then create a DT_DOUBLE variable called "Variable" in a different session on the same server, you'll get the error you described.

    To avoid the problem, call tf.Session.reset("grpc://" + worker_ip) before starting a subsequent session, or use a with tf.container(): block to place the variables in different namespaces.

  3. yaroslavvb commented on Oct 4, 2016

    @yaroslavvb
    ContributorAuthor

    Ah, indeed, it was remembering old state, tf.Session.reset fixes things, thanks!

  4. yaroslavvb commented on Oct 4, 2016

    @yaroslavvb
    ContributorAuthor

    PS: it seems more robust to just kill processes, tf.Session.reset seems to occasionally hang if called at the same time as launching the server process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions