config.graph_options.optimizer_options.global_jit_level = tf.OptimizerOptions.ON_1
    with tf.Session(config=config) as sess:
        sess.run(tf.global_variables_initializer())
        sess.run(tf.tables_initializer())

        if args.cross_check == 1:
            finalized_tf_output_ids_result, tf_output_ids_result, tf_parent_ids_result, \
                tf_sequence_lengths_result = sess.run(
                    [finalized_tf_output_ids, tf_output_ids, tf_parent_ids, tf_sequence_lengths])
            finalized_op_output_ids_result, op_output_ids_result, op_parent_ids_result, \
                op_sequence_lengths_result = sess.run(
                    [finalized_op_output_ids, op_output_ids, op_parent_ids, op_sequence_lengths])

            int_result_cross_check(
                "Output ids",
                tf_output_ids_result,
                op_output_ids_result,
                shape=[1 + max_seq_len, batch_size * beam_width])
            int_result_cross_check(
                "Parent ids",
                tf_parent_ids_result,
                op_parent_ids_result,
                shape=[1 + max_seq_len, batch_size * beam_width])
            int_result_cross_check("Sequence lengths",
                                   tf_sequence_lengths_result,
                                   op_sequence_lengths_result,
                                   shape=[1, batch_size * beam_width])
            int_result_cross_check(
                "Finalized output ids",
                finalized_tf_output_ids_result.T,
                finalized_op_output_ids_result.T,
示例#2
0
        config.graph_options.optimizer_options.global_jit_level = tf.OptimizerOptions.ON_1
    with tf.Session(config=config) as sess:
        sess.run(tf.global_variables_initializer())
        sess.run(tf.tables_initializer())

        if args.cross_check == 1:
            finalized_tf_output_ids_result, tf_output_ids_result, tf_parent_ids_result, \
                tf_sequence_lengths_result = sess.run(
                    [finalized_tf_output_ids, tf_output_ids, tf_parent_ids, tf_sequence_lengths])
            finalized_op_output_ids_result, op_output_ids_result, op_parent_ids_result, \
                op_sequence_lengths_result = sess.run(
                    [finalized_op_output_ids, op_output_ids, op_parent_ids, op_sequence_lengths])

            print("[INFO] BeamSearch cross check:")
            int_result_cross_check("Output ids",
                                   tf_output_ids_result,
                                   op_output_ids_result,
                                   shape=[batch_size, beam_width, max_seq_len])
            int_result_cross_check("Parent ids",
                                   tf_parent_ids_result,
                                   op_parent_ids_result,
                                   shape=[batch_size, beam_width, max_seq_len])
            int_result_cross_check("Sequence lengths",
                                   tf_sequence_lengths_result,
                                   op_sequence_lengths_result,
                                   shape=[batch_size, beam_width, 1])
            int_result_cross_check("Finalized output ids",
                                   finalized_tf_output_ids_result.T,
                                   finalized_op_output_ids_result.T,
                                   shape=[batch_size, beam_width, max_seq_len])

            tf_sampling_ids, tf_sampling_length = sess.run(