| 28 | class AutoParallelTest : public ::testing::Test {}; |
| 29 | |
| 30 | TEST_F(AutoParallelTest, SimpleParallel) { |
| 31 | tensorflow::Scope s = tensorflow::Scope::DisabledShapeInferenceScope(); |
| 32 | Output constant_a = ops::Const(s.WithOpName("constant_a"), 1.0f, {1}); |
| 33 | Output constant_b = ops::Const(s.WithOpName("constant_b"), 1, {1}); |
| 34 | Output var = ops::Variable(s.WithOpName("var"), {1}, DT_FLOAT); |
| 35 | Output assign = ops::Assign(s.WithOpName("assign"), {var}, {constant_a}); |
| 36 | Output identity = ops::Identity(s.WithOpName("identity"), {var}); |
| 37 | Output fifo_queue = ops::FIFOQueue(s.WithOpName("fifo_queue"), {DT_FLOAT}); |
| 38 | auto dequeue = ops::QueueDequeueMany(s.WithOpName("dequeue"), {fifo_queue}, |
| 39 | {constant_b}, {DT_FLOAT}); |
| 40 | Output add = ops::AddN(s.WithOpName("add"), {constant_a, dequeue[0]}); |
| 41 | Output learning_rate = ops::Const(s.WithOpName("learning_rate"), 0.01f, {1}); |
| 42 | Output apply_gradient = ops::ApplyGradientDescent( |
| 43 | s.WithOpName("apply_gradient"), {var}, {learning_rate}, {add}); |
| 44 | |
| 45 | GrapplerItem item; |
| 46 | item.init_ops.push_back("assign"); |
| 47 | item.fetch.push_back("apply_gradient"); |
| 48 | item.init_ops.push_back("assign"); |
| 49 | TF_CHECK_OK(s.ToGraphDef(&item.graph)); |
| 50 | |
| 51 | AutoParallel parallel(2); |
| 52 | GraphDef output; |
| 53 | Status status = parallel.Optimize(nullptr, item, &output); |
| 54 | TF_EXPECT_OK(status); |
| 55 | EXPECT_EQ(21, output.node_size()); |
| 56 | |
| 57 | const NodeDef& node_assign = output.node(0); |
| 58 | EXPECT_EQ("assign", node_assign.name()); |
| 59 | EXPECT_EQ("AutoParallel-Replica-0/constant_a", node_assign.input(1)); |
| 60 | |
| 61 | const NodeDef& node_constant_b = output.node(1); |
| 62 | EXPECT_EQ("constant_b", node_constant_b.name()); |
| 63 | |
| 64 | const NodeDef& node_fifo_queue = output.node(2); |
| 65 | EXPECT_EQ("fifo_queue", node_fifo_queue.name()); |
| 66 | |
| 67 | const NodeDef& node_identity = output.node(3); |
| 68 | EXPECT_EQ("identity", node_identity.name()); |
| 69 | EXPECT_EQ("var", node_identity.input(0)); |
| 70 | |
| 71 | const NodeDef& node_var = output.node(4); |
| 72 | EXPECT_EQ("var", node_var.name()); |
| 73 | |
| 74 | const NodeDef& node_div_const0 = output.node(5); |
| 75 | EXPECT_EQ("AutoParallel-Replica-0/AutoParallel-Div-Const", |
| 76 | node_div_const0.name()); |
| 77 | |
| 78 | const NodeDef& node_div0 = output.node(6); |
| 79 | EXPECT_EQ("AutoParallel-Replica-0/AutoParallel-Div-apply_gradient", |
| 80 | node_div0.name()); |
| 81 | const NodeDef& node_add0 = output.node(7); |
| 82 | EXPECT_EQ("AutoParallel-Replica-0/add", node_add0.name()); |
| 83 | |
| 84 | const NodeDef& node_gradient0 = output.node(8); |
| 85 | EXPECT_EQ("AutoParallel-Replica-0/apply_gradient", node_gradient0.name()); |
| 86 | |
| 87 | const NodeDef& node_constant_a0 = output.node(9); |
nothing calls this directly
no test coverage detected