What do the options in ConfigProto like allow_soft_placement and log_device_placement mean?

后端 未结 4 1706
攒了一身酷
攒了一身酷 2020-12-13 06:24

We see this quite often in many of the TensorFlow tutorials:

sess = tf.Session(config=tf.ConfigProto(allow_soft_placem         


        
4条回答
  •  抹茶落季
    2020-12-13 07:15

    If you look at the API of ConfigProto, on line 278, you will see this:

      // Whether soft placement is allowed. If allow_soft_placement is true,
      // an op will be placed on CPU if
      //   1. there's no GPU implementation for the OP
      // or
      //   2. no GPU devices are known or registered
      // or
      //   3. need to co-locate with reftype input(s) which are from CPU.
      bool allow_soft_placement = 7;
    

    What this really means is that if you do something like this without allow_soft_placement=True, TensorFlow will throw an error.

    with tf.device('/gpu:0'):
        # some op that doesn't have a GPU implementation
    

    Right below it, you will see on line 281:

      // Whether device placements should be logged.
      bool log_device_placement = 8;
    

    When log_device_placement=True, you will get a verbose output of something like this:

    2017-07-03 01:13:59.466748: I tensorflow/core/common_runtime/simple_placer.cc:841] Placeholder_1: (Placeholder)/job:localhost/replica:0/task:0/cpu:0
    Placeholder: (Placeholder): /job:localhost/replica:0/task:0/cpu:0
    2017-07-03 01:13:59.466765: I tensorflow/core/common_runtime/simple_placer.cc:841] Placeholder: (Placeholder)/job:localhost/replica:0/task:0/cpu:0
    Variable/initial_value: (Const): /job:localhost/replica:0/task:0/cpu:0
    2017-07-03 01:13:59.466783: I tensorflow/core/common_runtime/simple_placer.cc:841] Variable/initial_value: (Const)/job:localhost/replica:0/task:0/cpu:0
    

    You can see where each operation is mapped to. For this case, they are all mapped to /cpu:0, but if you're in a distributed setting, there would be many more devices.

提交回复
热议问题