Skip to content

Commit 7c76668

Browse files
Add function to convert from ComputationGraph to DynamicOpenDataflowGraph.
1 parent f4ace86 commit 7c76668

File tree

6 files changed

+122
-5
lines changed

6 files changed

+122
-5
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace = "FlexFlow"
2+
name = "dynamic_layer_guid_t"
3+
type = "variant"
4+
features = [
5+
"eq",
6+
"hash",
7+
"fmt",
8+
]
9+
10+
includes = [
11+
"pcg/layer_guid_t.dtg.h",
12+
"pcg/parallel_computation_graph/parallel_layer_guid_t.dtg.h",
13+
]
14+
15+
[[values]]
16+
name = "layer_guid"
17+
type = "::FlexFlow::layer_guid_t"
18+
19+
[[values]]
20+
name = "pcg_layer_guid"
21+
type = "::FlexFlow::parallel_layer_guid_t"

lib/task-spec/include/task-spec/dynamic_graph/dynamic_node_attrs.dtg.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ includes = [
1313
"pcg/machine_space_coordinate.dtg.h",
1414
"pcg/mapped_parallel_computation_graph/mapped_operator_task_group.h",
1515
"op-attrs/pcg_operator_attrs.dtg.h",
16-
"pcg/parallel_computation_graph/parallel_layer_guid_t.dtg.h",
16+
"task-spec/dynamic_graph/dynamic_layer_guid_t.dtg.h",
1717
"task-spec/device_specific_per_device_op_state.dtg.h",
1818
]
1919

@@ -38,8 +38,8 @@ name = "op_attrs"
3838
type = "std::optional<::FlexFlow::PCGOperatorAttrs>"
3939

4040
[[fields]]
41-
name = "pcg_layer_guid"
42-
type = "::FlexFlow::parallel_layer_guid_t"
41+
name = "layer_guid"
42+
type = "::FlexFlow::dynamic_layer_guid_t"
4343

4444
[[fields]]
4545
name = "per_device_op_state"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef _FLEXFLOW_LIB_TASK_SPEC_INCLUDE_TASK_SPEC_DYNAMIC_GRAPH_DYNAMIC_OPEN_DATAFLOW_GRAPH_FROM_CG_H
2+
#define _FLEXFLOW_LIB_TASK_SPEC_INCLUDE_TASK_SPEC_DYNAMIC_GRAPH_DYNAMIC_OPEN_DATAFLOW_GRAPH_FROM_CG_H
3+
4+
#include "pcg/computation_graph.dtg.h"
5+
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.dtg.h"
6+
7+
namespace FlexFlow {
8+
9+
DynamicOpenDataflowGraph
10+
make_dynamic_open_dataflow_graph_from_cg(ComputationGraph const &);
11+
12+
} // namespace FlexFlow
13+
14+
#endif
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace = "FlexFlow"
2+
name = "dynamic_tensor_guid_t"
3+
type = "variant"
4+
features = [
5+
"eq",
6+
"hash",
7+
"fmt",
8+
]
9+
10+
includes = [
11+
"pcg/tensor_guid_t.dtg.h",
12+
"pcg/parallel_computation_graph/parallel_tensor_guid_t.dtg.h",
13+
]
14+
15+
[[values]]
16+
name = "tensor_guid"
17+
type = "::FlexFlow::tensor_guid_t"
18+
19+
[[values]]
20+
name = "pcg_tensor_guid"
21+
type = "::FlexFlow::parallel_tensor_guid_t"

lib/task-spec/include/task-spec/dynamic_graph/dynamic_value_attrs.dtg.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ features = [
99

1010
includes = [
1111
"<optional>",
12+
"task-spec/dynamic_graph/dynamic_tensor_guid_t.dtg.h",
1213
"op-attrs/parallel_tensor_shape.dtg.h",
1314
"kernels/accessor.h",
1415
"pcg/parallel_computation_graph/parallel_tensor_guid_t.dtg.h",
@@ -21,8 +22,8 @@ src_includes = [
2122
]
2223

2324
[[fields]]
24-
name = "pcg_tensor_guid"
25-
type = "::FlexFlow::parallel_tensor_guid_t"
25+
name = "tensor_guid"
26+
type = "::FlexFlow::dynamic_tensor_guid_t"
2627

2728
[[fields]]
2829
name = "parallel_tensor_shape"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph_from_cg.h"
2+
#include "op-attrs/pcg_operator_attrs.h"
3+
#include "pcg/computation_graph.h"
4+
#include "task-spec/dynamic_graph/dynamic_layer_guid_t.dtg.h"
5+
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"
6+
#include "task-spec/dynamic_graph/dynamic_tensor_role.h"
7+
#include <optional>
8+
#include <unordered_map>
9+
10+
namespace FlexFlow {
11+
12+
DynamicOpenDataflowGraph
13+
make_dynamic_open_dataflow_graph_from_cg(ComputationGraph const &cg) {
14+
DynamicOpenDataflowGraph result = make_empty_dynamic_open_dataflow_graph();
15+
16+
for (auto const &[layer, attrs] : get_layer_attrs_mapping(cg)) {
17+
DynamicNodeAttrs result_attrs{
18+
/*task_type=*/std::nullopt,
19+
/*device_coord=*/std::nullopt,
20+
/*mapping=*/std::nullopt,
21+
/*op_attrs=*/pcg_op_attrs_from_compgraph_op_attrs(attrs.op_attrs),
22+
/*pcg_layer_guid=*/dynamic_layer_guid_t{layer},
23+
/*per_device_op_state=*/std::nullopt};
24+
25+
std::unordered_map<DynamicTensorSlot, DynamicValueAttrs> result_inputs;
26+
for (auto const &[slot_name, tensor] : get_incoming_tensors(cg, layer)) {
27+
result_inputs.emplace(
28+
std::piecewise_construct,
29+
std::forward_as_tuple(
30+
/*slot_name=*/slot_name,
31+
/*slot_tensor_role=*/mk_dynamic_tensor_role_fwd()),
32+
std::forward_as_tuple(
33+
/*tensor_guid=*/dynamic_tensor_guid_t{tensor},
34+
/*parallel_tensor_shape=*/std::nullopt,
35+
/*shard_coord=*/std::nullopt,
36+
/*accessor=*/std::nullopt,
37+
/*role=*/std::nullopt));
38+
}
39+
std::unordered_map<DynamicTensorSlot, DynamicValueAttrs> result_outputs;
40+
for (auto const &[slot_name, tensor] : get_outgoing_tensors(cg, layer)) {
41+
result_outputs.emplace(
42+
std::piecewise_construct,
43+
std::forward_as_tuple(
44+
/*slot_name=*/slot_name,
45+
/*slot_tensor_role=*/mk_dynamic_tensor_role_fwd()),
46+
std::forward_as_tuple(
47+
/*tensor_guid=*/dynamic_tensor_guid_t{tensor},
48+
/*parallel_tensor_shape=*/std::nullopt,
49+
/*shard_coord=*/std::nullopt,
50+
/*accessor=*/std::nullopt,
51+
/*role=*/std::nullopt));
52+
}
53+
54+
result.invocations.emplace(result_inputs, result_attrs, result_outputs);
55+
}
56+
57+
return result;
58+
}
59+
60+
} // namespace FlexFlow

0 commit comments

Comments
 (0)