TensorFlow1.15,估计量的内部逻辑';什么是输入?还是镜像战略的内在逻辑?

TensorFlow1.15,估计量的内部逻辑';什么是输入?还是镜像战略的内在逻辑?,tensorflow,deep-learning,tensorflow-datasets,tensorflow-estimator,bert-language-model,Tensorflow,Deep Learning,Tensorflow Datasets,Tensorflow Estimator,Bert Language Model,我在一台有4个GPU的机器上训练伯特,而不是1个GPU 对于每个培训步骤,我想知道是输入\u fn提供1 GPU 1批还是4 GPU 1批 米罗战略代码: distribution = tf.contrib.distribute.MirroredStrategy( devices=["device:GPU:%d" % i for i in range(FLAGS.n_gpus)], cross_tower_ops=tf.distribute.Hierarc

我在一台有4个GPU的机器上训练伯特,而不是1个GPU

对于每个培训步骤,我想知道是
输入\u fn
提供1 GPU 1批还是4 GPU 1批

米罗战略代码:

    distribution = tf.contrib.distribute.MirroredStrategy(
        devices=["device:GPU:%d" % i for i in range(FLAGS.n_gpus)],
        cross_tower_ops=tf.distribute.HierarchicalCopyAllReduce())

    run_config = RunConfig(
        train_distribute=distribution,
        log_step_count_steps=log_every_n_steps,
        model_dir=FLAGS.output_dir,
        save_checkpoints_steps=FLAGS.save_checkpoints_steps)

    model_fn = model_fn_builder(
        bert_config=bert_config,
        init_checkpoint=FLAGS.init_checkpoint,
        learning_rate=FLAGS.learning_rate,
        num_train_steps=FLAGS.num_train_steps,
        num_warmup_steps=FLAGS.num_warmup_steps,
        use_tpu=FLAGS.use_tpu,
        use_one_hot_embeddings=FLAGS.use_tpu)

    estimator = Estimator(
        model_fn=model_fn,
        params={},
        config=run_config)
输入\u fn
代码:

  def input_fn(params):
        batch_size = FLAGS.train_batch_size

        name_to_features = {
            "input_ids":
                tf.FixedLenFeature([max_seq_length], tf.int64),
            "input_mask":
                tf.FixedLenFeature([max_seq_length], tf.int64),
            "segment_ids":
                tf.FixedLenFeature([max_seq_length], tf.int64),
            "masked_lm_positions":
                tf.FixedLenFeature([max_predictions_per_seq], tf.int64),
            "masked_lm_ids":
                tf.FixedLenFeature([max_predictions_per_seq], tf.int64),
            "masked_lm_weights":
                tf.FixedLenFeature([max_predictions_per_seq], tf.float32),
            "next_sentence_labels":
                tf.FixedLenFeature([1], tf.int64),
        }

        if is_training:
            d = tf.data.Dataset.from_tensor_slices(tf.constant(input_files))
            d = d.repeat()
            d = d.shuffle(buffer_size=len(input_files))

            cycle_length = min(num_cpu_threads, len(input_files))

            d = d.apply(
                tf.contrib.data.parallel_interleave(
                    tf.data.TFRecordDataset,
                    sloppy=is_training,
                    cycle_length=cycle_length))
            d = d.shuffle(buffer_size=100)
        else:
            d = tf.data.TFRecordDataset(input_files)
            d = d.repeat()

        d = d.apply(
            tf.contrib.data.map_and_batch(
                lambda record: _decode_record(record, name_to_features),
                batch_size=batch_size,
                num_parallel_batches=num_cpu_threads,
                drop_remainder=True))
        d = d.prefetch(10)
        return d
其他代码:

estimator.train(input_fn, max_steps=FLAGS.num_train_steps)
如果
input\u fn
给出1个GPU 1批,则
train\u batch\u size
应为每个GPU的最大批量大小

如果
input\u fn
给出一批4个GPU,则
训练批大小应为每个GPU*4的最大批大小。

input\u fn
返回1个GPU的1个批次

批处理单元大小
适用于1 GPU