From 1a63f90149004c5041af05a6bfe5a97f348281b7 Mon Sep 17 00:00:00 2001 From: Colin Unger Date: Sun, 25 Aug 2024 21:59:40 -0700 Subject: [PATCH] Format --- .../sub_parallel_computation_graph.h | 12 ++++++------ .../evaluate_substitution_output.h | 16 +++++++++------- .../output_expr_to_result_sub_pcg_mapping.h | 2 +- .../perform_shape_inference.h | 10 ++++++---- .../sub_parallel_computation_graph.cc | 17 +++++++---------- .../src/substitutions/substitution.cc | 4 ++-- .../evaluate_substitution_output.cc | 5 ++--- .../perform_shape_inference.cc | 3 +-- .../test/src/substitutions/substitution.cc | 8 +++++--- .../evaluate_substitution_output.cc | 13 +++++++------ .../perform_shape_inference.cc | 10 ++++++---- .../algorithms/get_subgraph_outgoing_edges.cc | 6 +++--- .../open_dataflow_graph/algorithms/as_dot.cc | 3 ++- 13 files changed, 57 insertions(+), 52 deletions(-) diff --git a/lib/substitutions/include/substitutions/sub_parallel_computation_graph.h b/lib/substitutions/include/substitutions/sub_parallel_computation_graph.h index 38b39c8bb2..6aa22af815 100644 --- a/lib/substitutions/include/substitutions/sub_parallel_computation_graph.h +++ b/lib/substitutions/include/substitutions/sub_parallel_computation_graph.h @@ -38,12 +38,12 @@ std::vector get_layer_outputs(SubParallelComputationGraph const &, parallel_layer_guid_t const &); -std::unordered_set - get_subgraph_incoming_edges(SubParallelComputationGraph const &, - std::unordered_set const &); -std::unordered_set - get_subgraph_outgoing_edges(SubParallelComputationGraph const &, - std::unordered_set const &); +std::unordered_set get_subgraph_incoming_edges( + SubParallelComputationGraph const &, + std::unordered_set const &); +std::unordered_set get_subgraph_outgoing_edges( + SubParallelComputationGraph const &, + std::unordered_set const &); std::unordered_set get_subgraph_incoming_edges( SubParallelComputationGraph const &, diff --git a/lib/substitutions/include/substitutions/substitution_internal/evaluate_substitution_output.h b/lib/substitutions/include/substitutions/substitution_internal/evaluate_substitution_output.h index 0bb15afa7f..a0461b075b 100644 --- a/lib/substitutions/include/substitutions/substitution_internal/evaluate_substitution_output.h +++ b/lib/substitutions/include/substitutions/substitution_internal/evaluate_substitution_output.h @@ -1,29 +1,31 @@ #ifndef _FLEXFLOW_LIB_SUBSTITUTIONS_INCLUDE_SUBSTITUTIONS_SUBSTITUTION_INTERNAL_EVALUATE_SUBSTITUTION_OUTPUT_H #define _FLEXFLOW_LIB_SUBSTITUTIONS_INCLUDE_SUBSTITUTIONS_SUBSTITUTION_INTERNAL_EVALUATE_SUBSTITUTION_OUTPUT_H -#include "substitutions/substitution_internal/output_expr_to_result_sub_pcg_mapping.dtg.h" #include "substitutions/pcg_pattern_match.dtg.h" #include "substitutions/sub_parallel_computation_graph.dtg.h" #include "substitutions/substitution.dtg.h" +#include "substitutions/substitution_internal/output_expr_to_result_sub_pcg_mapping.dtg.h" #include namespace FlexFlow { /** - * @brief Takes a SubParallelComputationGraph and a PCGPatternMatch where a Substitution applies and - * evaluates the Substitution's OutputGraphExpr (producing another SubParallelComputationGraph) - * using the information from the matched nodes. + * @brief Takes a SubParallelComputationGraph and a PCGPatternMatch where a + * Substitution applies and evaluates the Substitution's OutputGraphExpr + * (producing another SubParallelComputationGraph) using the information from + * the matched nodes. * - * @details Exists only to enable apply_substitution(SubParallelComputationGraph const &, Substitution const &, PCGPatternMatch const &) + * @details Exists only to enable apply_substitution(SubParallelComputationGraph + * const &, Substitution const &, PCGPatternMatch const &) * - * @note The resulting SubParallelComputationGraph has new node ids, i.e., does not have the same node ids as the OutputGraphExpr + * @note The resulting SubParallelComputationGraph has new node ids, i.e., does + * not have the same node ids as the OutputGraphExpr */ std::pair evaluate_substitution_output(SubParallelComputationGraph const &spcg, Substitution const &sub, PCGPatternMatch const &match); - } // namespace FlexFlow #endif diff --git a/lib/substitutions/include/substitutions/substitution_internal/output_expr_to_result_sub_pcg_mapping.h b/lib/substitutions/include/substitutions/substitution_internal/output_expr_to_result_sub_pcg_mapping.h index b1bcc02cd3..603cb670bf 100644 --- a/lib/substitutions/include/substitutions/substitution_internal/output_expr_to_result_sub_pcg_mapping.h +++ b/lib/substitutions/include/substitutions/substitution_internal/output_expr_to_result_sub_pcg_mapping.h @@ -2,10 +2,10 @@ #define _FLEXFLOW_LIB_SUBSTITUTIONS_INCLUDE_SUBSTITUTIONS_SUBSTITUTION_INTERNAL_OUTPUT_EXPR_TO_RESULT_SUB_PCG_MAPPING_H #include "pcg/parallel_computation_graph/parallel_tensor_guid_t.dtg.h" -#include "substitutions/substitution_internal/output_expr_to_result_sub_pcg_mapping.dtg.h" #include "substitutions/output_graph/output_graph_expr.dtg.h" #include "substitutions/output_graph/output_graph_expr_node_output.dtg.h" #include "substitutions/sub_parallel_computation_graph.dtg.h" +#include "substitutions/substitution_internal/output_expr_to_result_sub_pcg_mapping.dtg.h" namespace FlexFlow { diff --git a/lib/substitutions/include/substitutions/substitution_internal/perform_shape_inference.h b/lib/substitutions/include/substitutions/substitution_internal/perform_shape_inference.h index a56d582f36..de9d1cd78a 100644 --- a/lib/substitutions/include/substitutions/substitution_internal/perform_shape_inference.h +++ b/lib/substitutions/include/substitutions/substitution_internal/perform_shape_inference.h @@ -7,17 +7,19 @@ namespace FlexFlow { /** - * @brief Takes a SubParallelComputationGraph but without ParallelTensorShape annotations on its OpenDataflowValue%s - * and uses shape inference to fill them in. + * @brief Takes a SubParallelComputationGraph but without ParallelTensorShape + * annotations on its OpenDataflowValue%s and uses shape inference to fill them + * in. * * @details The OutputGraphExpr of a Substitution only computes * PCGOperatorAttr%s, not ParallelTensorShape%s, under the theory that shapes * can be inferred by parallel shape inference. The responsibility of this * function is to traverse the result of evaluating the OutputGraphExpr - * (resulting from evaluate_substitution_output) + * (resulting from evaluate_substitution_output) * and annotate each of the OpenDataflowValue%s with the inferred shape. * - * Exists only to enable apply_substitution(SubParallelComputationGraph const &, Substitution const &, PCGPatternMatch const &) + * Exists only to enable apply_substitution(SubParallelComputationGraph const &, + * Substitution const &, PCGPatternMatch const &) */ LabelledOpenDataflowGraphView perform_shape_inference( diff --git a/lib/substitutions/src/substitutions/sub_parallel_computation_graph.cc b/lib/substitutions/src/substitutions/sub_parallel_computation_graph.cc index e5079c2e23..54039aab60 100644 --- a/lib/substitutions/src/substitutions/sub_parallel_computation_graph.cc +++ b/lib/substitutions/src/substitutions/sub_parallel_computation_graph.cc @@ -12,7 +12,6 @@ #include "utils/graph/labelled_open_dataflow_graph/algorithms/get_graph_data.h" #include "utils/graph/labelled_open_dataflow_graph/algorithms/rewrite_node_labels.h" #include "utils/graph/node/algorithms.h" -#include "utils/graph/open_dataflow_graph/algorithms/get_subgraph_incoming_edges.h" #include "utils/graph/open_dataflow_graph/algorithms/get_open_dataflow_value_uses.h" #include "utils/graph/open_dataflow_graph/algorithms/get_subgraph_incoming_edges.h" @@ -87,15 +86,13 @@ std::vector [](DataflowOutput const &o) { return parallel_tensor_guid_t{o}; }); } -std::unordered_set - get_subgraph_outgoing_edges(SubParallelComputationGraph const &spcg, - std::unordered_set const &layers) { - std::unordered_set raw_edges = - get_subgraph_outgoing_edges(spcg.raw_graph, - transform(layers, - [](parallel_layer_guid_t const &l) { - return l.raw_graph_node; - })); +std::unordered_set get_subgraph_outgoing_edges( + SubParallelComputationGraph const &spcg, + std::unordered_set const &layers) { + std::unordered_set raw_edges = get_subgraph_outgoing_edges( + spcg.raw_graph, transform(layers, [](parallel_layer_guid_t const &l) { + return l.raw_graph_node; + })); return transform(raw_edges, [](DataflowEdge const &e) { return ParallelComputationGraphEdge{e}; }); diff --git a/lib/substitutions/src/substitutions/substitution.cc b/lib/substitutions/src/substitutions/substitution.cc index 01a88efb39..22e15cb01a 100644 --- a/lib/substitutions/src/substitutions/substitution.cc +++ b/lib/substitutions/src/substitutions/substitution.cc @@ -2,12 +2,12 @@ #include "pcg/parallel_computation_graph/parallel_computation_graph_edge.h" #include "pcg/parallel_computation_graph/parallel_tensor_guid_t.h" #include "substitutions/open_parallel_tensor_guid_t.h" -#include "substitutions/substitution_internal/evaluate_substitution_output.h" -#include "substitutions/substitution_internal/output_expr_to_result_sub_pcg_mapping.h" #include "substitutions/output_graph/output_operator_attrs_assignment.h" #include "substitutions/pcg_pattern_match.h" #include "substitutions/sub_parallel_computation_graph.h" #include "substitutions/sub_parallel_computation_graph_edge.h" +#include "substitutions/substitution_internal/evaluate_substitution_output.h" +#include "substitutions/substitution_internal/output_expr_to_result_sub_pcg_mapping.h" #include "utils/containers/merge_maps.h" #include "utils/containers/restrict_keys.h" #include "utils/containers/set_minus.h" diff --git a/lib/substitutions/src/substitutions/substitution_internal/evaluate_substitution_output.cc b/lib/substitutions/src/substitutions/substitution_internal/evaluate_substitution_output.cc index 111ad771b6..186e2fc03a 100644 --- a/lib/substitutions/src/substitutions/substitution_internal/evaluate_substitution_output.cc +++ b/lib/substitutions/src/substitutions/substitution_internal/evaluate_substitution_output.cc @@ -1,6 +1,8 @@ #include "substitutions/substitution_internal/evaluate_substitution_output.h" #include "substitutions/output_graph/output_operator_attrs_assignment.h" #include "substitutions/sub_parallel_computation_graph.h" +#include "substitutions/substitution_internal/perform_shape_inference.h" +#include "utils/containers/map_keys.h" #include "utils/containers/map_values.h" #include "utils/graph/labelled_open_dataflow_graph/algorithms/permute_input_ids.h" #include "utils/graph/labelled_open_dataflow_graph/algorithms/permute_node_ids.h" @@ -10,8 +12,6 @@ #include "utils/graph/node/algorithms/new_node.dtg.h" #include "utils/graph/open_dataflow_graph/algorithms/generate_new_input_id_permutation.h" #include "utils/graph/open_dataflow_graph/algorithms/new_dataflow_graph_input.dtg.h" -#include "utils/containers/map_keys.h" -#include "substitutions/substitution_internal/perform_shape_inference.h" namespace FlexFlow { @@ -91,5 +91,4 @@ std::pair }); } - } // namespace FlexFlow diff --git a/lib/substitutions/src/substitutions/substitution_internal/perform_shape_inference.cc b/lib/substitutions/src/substitutions/substitution_internal/perform_shape_inference.cc index 50198739d2..0bde326bd1 100644 --- a/lib/substitutions/src/substitutions/substitution_internal/perform_shape_inference.cc +++ b/lib/substitutions/src/substitutions/substitution_internal/perform_shape_inference.cc @@ -1,11 +1,11 @@ #include "substitutions/substitution_internal/perform_shape_inference.h" #include "utils/containers/map_keys.h" +#include "utils/containers/transform.h" #include "utils/containers/zip.h" #include "utils/graph/dataflow_graph/algorithms.h" #include "utils/graph/digraph/algorithms/get_topological_ordering.h" #include "utils/graph/labelled_open_dataflow_graph/algorithms/rewrite_value_labels.h" #include "utils/graph/open_dataflow_graph/algorithms/get_inputs.h" -#include "utils/containers/transform.h" namespace FlexFlow { @@ -42,5 +42,4 @@ LabelledOpenDataflowGraphView }); } - } // namespace FlexFlow diff --git a/lib/substitutions/test/src/substitutions/substitution.cc b/lib/substitutions/test/src/substitutions/substitution.cc index e7106aca9e..32f25eca29 100644 --- a/lib/substitutions/test/src/substitutions/substitution.cc +++ b/lib/substitutions/test/src/substitutions/substitution.cc @@ -21,9 +21,11 @@ TEST_SUITE(FF_TEST_SUITE) { // FAIL("TODO"); // } - TEST_CASE("evaluate_substitution_output(SubParallelComputationGraph, Substituion, PCGPatternMatch)") { - // Currently Substitution creation is very verbose. - // This is being addressed in https://github.com/flexflow/FlexFlow/issues/1473. + TEST_CASE("evaluate_substitution_output(SubParallelComputationGraph, " + "Substituion, PCGPatternMatch)") { + // Currently Substitution creation is very verbose. + // This is being addressed in + // https://github.com/flexflow/FlexFlow/issues/1473. auto pattern_g = LabelledOpenDataflowGraph:: create +#include "substitutions/substitution_internal/evaluate_substitution_output.h" #include "pcg/parallel_computation_graph/parallel_computation_graph_builder.h" #include "substitutions/open_parallel_tensor_guid_t.h" +#include "substitutions/operator_pattern/operator_attribute_constraint.h" #include "substitutions/output_graph/output_operator_attrs_assignment.h" #include "substitutions/sub_parallel_computation_graph.h" -#include "substitutions/substitution_internal/evaluate_substitution_output.h" +#include "substitutions/tensor_pattern/tensor_attribute_pattern.h" #include "utils/containers/get_only.h" #include "utils/graph/instances/unordered_set_labelled_open_dataflow_graph.h" -#include "substitutions/tensor_pattern/tensor_attribute_pattern.h" -#include "substitutions/operator_pattern/operator_attribute_constraint.h" #include "utils/integer_conversions.h" +#include using namespace ::FlexFlow; TEST_SUITE(FF_TEST_SUITE) { TEST_CASE("evaluate_substitution_output") { - // Currently Substitution creation is very verbose. - // This is being addressed in https://github.com/flexflow/FlexFlow/issues/1473. + // Currently Substitution creation is very verbose. + // This is being addressed in + // https://github.com/flexflow/FlexFlow/issues/1473. auto pattern_g = LabelledOpenDataflowGraph:: create #include "substitutions/substitution_internal/perform_shape_inference.h" #include "utils/containers/get_only.h" #include "utils/graph/instances/unordered_set_labelled_open_dataflow_graph.h" +#include "utils/graph/labelled_open_dataflow_graph/algorithms/get_graph_data.h" #include "utils/graph/labelled_open_dataflow_graph/labelled_open_dataflow_graph.h" #include "utils/integer_conversions.h" -#include "utils/graph/labelled_open_dataflow_graph/algorithms/get_graph_data.h" +#include using namespace ::FlexFlow; TEST_SUITE(FF_TEST_SUITE) { TEST_CASE("perform_shape_inference") { - auto g = LabelledOpenDataflowGraph::create< - UnorderedSetLabelledOpenDataflowGraph>(); + auto g = + LabelledOpenDataflowGraph::create< + UnorderedSetLabelledOpenDataflowGraph>(); int in_channels = 24; int out_channels = 16; diff --git a/lib/utils/src/utils/graph/dataflow_graph/algorithms/get_subgraph_outgoing_edges.cc b/lib/utils/src/utils/graph/dataflow_graph/algorithms/get_subgraph_outgoing_edges.cc index 0058e011e4..c442a26dab 100644 --- a/lib/utils/src/utils/graph/dataflow_graph/algorithms/get_subgraph_outgoing_edges.cc +++ b/lib/utils/src/utils/graph/dataflow_graph/algorithms/get_subgraph_outgoing_edges.cc @@ -6,10 +6,10 @@ namespace FlexFlow { std::unordered_set get_subgraph_outgoing_edges(DataflowGraphView const &g, - std::unordered_set const &ns) { + std::unordered_set const &ns) { - std::unordered_set all_nodes = get_nodes(g); - query_set dst_query = query_set{set_minus(all_nodes, ns)}; + std::unordered_set all_nodes = get_nodes(g); + query_set dst_query = query_set{set_minus(all_nodes, ns)}; DataflowEdgeQuery query = DataflowEdgeQuery{ query_set{ns}, diff --git a/lib/utils/src/utils/graph/open_dataflow_graph/algorithms/as_dot.cc b/lib/utils/src/utils/graph/open_dataflow_graph/algorithms/as_dot.cc index c11cd627af..2d636d8654 100644 --- a/lib/utils/src/utils/graph/open_dataflow_graph/algorithms/as_dot.cc +++ b/lib/utils/src/utils/graph/open_dataflow_graph/algorithms/as_dot.cc @@ -22,7 +22,8 @@ std::string as_dot(OpenDataflowGraphView const &g) { // WARN(@lockshaw): doing this all with string ids is ugly and error prone, // as it requires duplicating the stringification logic across functions. // -// Fixing this is tracked in issue https://github.com/flexflow/FlexFlow/issues/1476 +// Fixing this is tracked in issue +// https://github.com/flexflow/FlexFlow/issues/1476 std::string as_dot(OpenDataflowGraphView const &g, std::function const &get_node_label,