From 47dcb52a383ce55c8f81915c8900592fc145d0fd Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Fri, 6 Mar 2026 12:08:35 -0800 Subject: [PATCH 1/2] First pass JSON serialization for graph types with Claude. --- .../parallel_computation_graph.dtg.toml | 8 +- .../dataflow_graph/dataflow_edge.dtg.toml | 1 + .../dataflow_graph/dataflow_input.dtg.toml | 1 + .../dataflow_graph/dataflow_output.dtg.toml | 1 + .../unordered_set_kwarg_dataflow_graph.h | 124 ++++++++++++++++++ .../utils/graph/kwarg_dataflow_graph/json.h | 45 +++++++ .../kwarg_dataflow_edge.dtg.toml | 1 + .../kwarg_dataflow_input.dtg.toml | 1 + .../kwarg_dataflow_output.dtg.toml | 1 + .../graph/labelled_dataflow_graph/json.h | 49 +++++++ .../labelled_kwarg_dataflow_graph/json.h | 77 +++++++++++ .../from_labelled_open_dataflow_graph_data.h | 1 + ...labelled_open_dataflow_graph_data.dtg.toml | 1 + .../graph/labelled_open_dataflow_graph/json.h | 46 +++++++ ...ed_open_kwarg_dataflow_graph_data.dtg.toml | 1 + .../labelled_open_kwarg_dataflow_graph/json.h | 75 +++++++++++ .../dataflow_graph_input.dtg.toml | 1 + .../dataflow_input_edge.dtg.toml | 1 + .../open_dataflow_edge.dtg.toml | 1 + .../open_dataflow_value.dtg.toml | 1 + .../open_kwarg_dataflow_graph_data.dtg.toml | 1 + .../kwarg_dataflow_input_edge.dtg.toml | 1 + .../open_kwarg_dataflow_edge.dtg.toml | 1 + .../open_kwarg_dataflow_value.dtg.toml | 1 + .../instances/graph_json_instantiations.cc | 24 ++++ .../unordered_set_kwarg_dataflow_graph.cc | 8 ++ 26 files changed, 472 insertions(+), 1 deletion(-) create mode 100644 lib/utils/include/utils/graph/instances/unordered_set_kwarg_dataflow_graph.h create mode 100644 lib/utils/include/utils/graph/kwarg_dataflow_graph/json.h create mode 100644 lib/utils/include/utils/graph/labelled_dataflow_graph/json.h create mode 100644 lib/utils/include/utils/graph/labelled_kwarg_dataflow_graph/json.h create mode 100644 lib/utils/include/utils/graph/labelled_open_dataflow_graph/json.h create mode 100644 lib/utils/include/utils/graph/labelled_open_kwarg_dataflow_graph/json.h create mode 100644 lib/utils/src/utils/graph/instances/graph_json_instantiations.cc create mode 100644 lib/utils/src/utils/graph/instances/unordered_set_kwarg_dataflow_graph.cc diff --git a/lib/pcg/include/pcg/parallel_computation_graph/parallel_computation_graph.dtg.toml b/lib/pcg/include/pcg/parallel_computation_graph/parallel_computation_graph.dtg.toml index 3e46248850..f3ac5da222 100644 --- a/lib/pcg/include/pcg/parallel_computation_graph/parallel_computation_graph.dtg.toml +++ b/lib/pcg/include/pcg/parallel_computation_graph/parallel_computation_graph.dtg.toml @@ -1,7 +1,9 @@ namespace = "FlexFlow" name = "ParallelComputationGraph" type = "struct" -features = [ ] +features = [ + "json", +] includes = [ "utils/graph/labelled_kwarg_dataflow_graph/labelled_kwarg_dataflow_graph.h", @@ -10,6 +12,10 @@ includes = [ "op-attrs/tensor_slot_name.dtg.h", ] +src_includes = [ + "utils/graph/labelled_kwarg_dataflow_graph/json.h", +] + [[fields]] name = "raw_graph" type = "::FlexFlow::LabelledKwargDataflowGraph<::FlexFlow::ParallelLayerAttrs, ::FlexFlow::ParallelTensorAttrs, ::FlexFlow::TensorSlotName>" diff --git a/lib/utils/include/utils/graph/dataflow_graph/dataflow_edge.dtg.toml b/lib/utils/include/utils/graph/dataflow_graph/dataflow_edge.dtg.toml index 7a73c1a8aa..b8aec00152 100644 --- a/lib/utils/include/utils/graph/dataflow_graph/dataflow_edge.dtg.toml +++ b/lib/utils/include/utils/graph/dataflow_graph/dataflow_edge.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] includes = [ diff --git a/lib/utils/include/utils/graph/dataflow_graph/dataflow_input.dtg.toml b/lib/utils/include/utils/graph/dataflow_graph/dataflow_input.dtg.toml index 8169d1f736..3fb0af86d0 100644 --- a/lib/utils/include/utils/graph/dataflow_graph/dataflow_input.dtg.toml +++ b/lib/utils/include/utils/graph/dataflow_graph/dataflow_input.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] includes = [ diff --git a/lib/utils/include/utils/graph/dataflow_graph/dataflow_output.dtg.toml b/lib/utils/include/utils/graph/dataflow_graph/dataflow_output.dtg.toml index dee7152aa2..69aae6d17e 100644 --- a/lib/utils/include/utils/graph/dataflow_graph/dataflow_output.dtg.toml +++ b/lib/utils/include/utils/graph/dataflow_graph/dataflow_output.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] includes = [ diff --git a/lib/utils/include/utils/graph/instances/unordered_set_kwarg_dataflow_graph.h b/lib/utils/include/utils/graph/instances/unordered_set_kwarg_dataflow_graph.h new file mode 100644 index 0000000000..835a6b85a2 --- /dev/null +++ b/lib/utils/include/utils/graph/instances/unordered_set_kwarg_dataflow_graph.h @@ -0,0 +1,124 @@ +#ifndef _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_INSTANCES_UNORDERED_SET_KWARG_DATAFLOW_GRAPH_H +#define _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_INSTANCES_UNORDERED_SET_KWARG_DATAFLOW_GRAPH_H + +#include "utils/containers/filter.h" +#include "utils/containers/generate_map.h" +#include "utils/containers/keys.h" +#include "utils/graph/kwarg_dataflow_graph/algorithms/get_all_kwarg_dataflow_edges.h" +#include "utils/graph/kwarg_dataflow_graph/algorithms/get_all_kwarg_dataflow_outputs.h" +#include "utils/graph/kwarg_dataflow_graph/i_kwarg_dataflow_graph.h" +#include "utils/graph/kwarg_dataflow_graph/kwarg_dataflow_edge_query.h" +#include "utils/graph/kwarg_dataflow_graph/kwarg_dataflow_output_query.h" +#include "utils/graph/node/algorithms.h" +#include "utils/graph/node/node_source.h" + +namespace FlexFlow { + +template +struct UnorderedSetKwargDataflowGraph final + : public IKwargDataflowGraph { +public: + UnorderedSetKwargDataflowGraph() = default; + + KwargNodeAddedResult add_node( + std::unordered_map> const &inputs, + std::unordered_set const &output_slots) override { + Node new_node = this->node_source.new_node(); + this->nodes.insert(new_node); + + for (auto const &[slot, src] : inputs) { + this->edges.insert(KwargDataflowEdge{ + src, + KwargDataflowInput{new_node, slot}, + }); + } + + std::unordered_map> outputs = + generate_map( + output_slots, + [&](SlotName const &slot) -> KwargDataflowOutput { + KwargDataflowOutput out{new_node, slot}; + this->outputs.insert(out); + return out; + }); + + return KwargNodeAddedResult{ + /*node=*/new_node, + /*outputs=*/outputs, + }; + } + + void add_node_unsafe( + Node const &node, + std::unordered_map> const &inputs, + std::unordered_map> const + &outputs) override { + this->nodes.insert(node); + + for (auto const &[slot, src] : inputs) { + this->edges.insert(KwargDataflowEdge{ + src, + KwargDataflowInput{node, slot}, + }); + } + + for (auto const &[slot, out] : outputs) { + this->outputs.insert(out); + } + } + + std::unordered_set query_nodes(NodeQuery const &q) const override { + return filter(this->nodes, + [&](Node const &n) { return includes(q.nodes, n); }); + } + + std::unordered_set> + query_edges(KwargDataflowEdgeQuery const &q) const override { + return filter(this->edges, [&](KwargDataflowEdge const &e) { + return kwarg_dataflow_edge_query_includes(q, e); + }); + } + + std::unordered_set> query_outputs( + KwargDataflowOutputQuery const &q) const override { + return filter(this->outputs, [&](KwargDataflowOutput const &o) { + return kwarg_dataflow_output_query_includes(q, o); + }); + } + + void inplace_materialize_from( + KwargDataflowGraphView const &view) override { + this->nodes = get_nodes(view); + this->edges = get_all_kwarg_dataflow_edges(view); + this->outputs = get_all_kwarg_dataflow_outputs(view); + } + + UnorderedSetKwargDataflowGraph *clone() const override { + return new UnorderedSetKwargDataflowGraph{ + this->node_source, + this->nodes, + this->edges, + this->outputs, + }; + } + +private: + UnorderedSetKwargDataflowGraph( + NodeSource const &node_source, + std::unordered_set const &nodes, + std::unordered_set> const &edges, + std::unordered_set> const &outputs) + : node_source(node_source), nodes(nodes), edges(edges), outputs(outputs) { + } + +private: + NodeSource node_source; + std::unordered_set nodes; + std::unordered_set> edges; + std::unordered_set> outputs; +}; +CHECK_RC_COPY_VIRTUAL_COMPLIANT(UnorderedSetKwargDataflowGraph); + +} // namespace FlexFlow + +#endif diff --git a/lib/utils/include/utils/graph/kwarg_dataflow_graph/json.h b/lib/utils/include/utils/graph/kwarg_dataflow_graph/json.h new file mode 100644 index 0000000000..11b2196712 --- /dev/null +++ b/lib/utils/include/utils/graph/kwarg_dataflow_graph/json.h @@ -0,0 +1,45 @@ +#ifndef _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_KWARG_DATAFLOW_GRAPH_JSON_H +#define _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_KWARG_DATAFLOW_GRAPH_JSON_H + +#include "utils/graph/instances/unordered_set_kwarg_dataflow_graph.h" +#include "utils/graph/kwarg_dataflow_graph/algorithms/view_as_open_kwarg_dataflow_graph.h" +#include "utils/graph/kwarg_dataflow_graph/kwarg_dataflow_graph.h" +#include "utils/graph/open_kwarg_dataflow_graph/algorithms/get_open_kwarg_dataflow_graph_data.h" +#include "utils/graph/open_kwarg_dataflow_graph/algorithms/open_kwarg_dataflow_graph_data.dtg.h" +#include "utils/graph/open_kwarg_dataflow_graph/algorithms/view_from_open_kwarg_dataflow_graph_data.h" +#include "utils/json/check_is_json_deserializable.h" +#include "utils/json/check_is_json_serializable.h" +#include "utils/json/monostate.h" +#include +#include + +namespace nlohmann { + +template +struct adl_serializer<::FlexFlow::KwargDataflowGraph> { + static ::FlexFlow::KwargDataflowGraph from_json(json const &j) { + CHECK_IS_JSON_DESERIALIZABLE( + ::FlexFlow::OpenKwargDataflowGraphData); + + auto data = j.template get< + ::FlexFlow::OpenKwargDataflowGraphData>(); + ::FlexFlow::OpenKwargDataflowGraphView view = + ::FlexFlow::view_from_open_kwarg_dataflow_graph_data(data); + return ::FlexFlow::KwargDataflowGraph::template create_copy_of< + ::FlexFlow::UnorderedSetKwargDataflowGraph>(view); + } + + static void to_json(json &j, + ::FlexFlow::KwargDataflowGraph const &g) { + CHECK_IS_JSON_SERIALIZABLE( + ::FlexFlow::OpenKwargDataflowGraphData); + + ::FlexFlow::OpenKwargDataflowGraphView open_view = + ::FlexFlow::view_as_open_kwarg_dataflow_graph(g); + j = ::FlexFlow::get_open_kwarg_dataflow_graph_data(open_view); + } +}; + +} // namespace nlohmann + +#endif diff --git a/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_edge.dtg.toml b/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_edge.dtg.toml index b0b67cbdd9..73aba3e74a 100644 --- a/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_edge.dtg.toml +++ b/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_edge.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] template_params = [ diff --git a/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_input.dtg.toml b/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_input.dtg.toml index 5f092f0540..ae21725b68 100644 --- a/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_input.dtg.toml +++ b/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_input.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] template_params = [ diff --git a/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_output.dtg.toml b/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_output.dtg.toml index f286fb90a7..5b537eac88 100644 --- a/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_output.dtg.toml +++ b/lib/utils/include/utils/graph/kwarg_dataflow_graph/kwarg_dataflow_output.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] template_params = [ diff --git a/lib/utils/include/utils/graph/labelled_dataflow_graph/json.h b/lib/utils/include/utils/graph/labelled_dataflow_graph/json.h new file mode 100644 index 0000000000..594925d845 --- /dev/null +++ b/lib/utils/include/utils/graph/labelled_dataflow_graph/json.h @@ -0,0 +1,49 @@ +#ifndef _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_DATAFLOW_GRAPH_JSON_H +#define _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_DATAFLOW_GRAPH_JSON_H + +#include "utils/graph/instances/unordered_set_labelled_open_dataflow_graph.h" +#include "utils/graph/labelled_dataflow_graph/algorithms/view_as_labelled_open_dataflow_graph.h" +#include "utils/graph/labelled_dataflow_graph/labelled_dataflow_graph.h" +#include "utils/graph/labelled_open_dataflow_graph/algorithms/from_labelled_open_dataflow_graph_data.h" +#include "utils/graph/labelled_open_dataflow_graph/algorithms/get_graph_data.h" +#include "utils/graph/labelled_open_dataflow_graph/algorithms/labelled_open_dataflow_graph_data.dtg.h" +#include "utils/json/check_is_json_deserializable.h" +#include "utils/json/check_is_json_serializable.h" +#include + +namespace nlohmann { + +template +struct adl_serializer< + ::FlexFlow::LabelledDataflowGraph> { + static ::FlexFlow::LabelledDataflowGraph + from_json(json const &j) { + CHECK_IS_JSON_DESERIALIZABLE( + ::FlexFlow::LabelledOpenDataflowGraphData); + + auto data = j.template get< + ::FlexFlow::LabelledOpenDataflowGraphData>(); + ::FlexFlow::LabelledOpenDataflowGraphView + open_view = ::FlexFlow::from_labelled_open_dataflow_graph_data(data); + return ::FlexFlow::LabelledDataflowGraph:: + template create_copy_of< + ::FlexFlow::UnorderedSetLabelledOpenDataflowGraph>( + open_view); + } + + static void to_json( + json &j, + ::FlexFlow::LabelledDataflowGraph const &g) { + CHECK_IS_JSON_SERIALIZABLE( + ::FlexFlow::LabelledOpenDataflowGraphData); + + ::FlexFlow::LabelledOpenDataflowGraphView + open_view = ::FlexFlow::view_as_labelled_open_dataflow_graph(g); + j = ::FlexFlow::get_graph_data(open_view); + } +}; + +} // namespace nlohmann + +#endif diff --git a/lib/utils/include/utils/graph/labelled_kwarg_dataflow_graph/json.h b/lib/utils/include/utils/graph/labelled_kwarg_dataflow_graph/json.h new file mode 100644 index 0000000000..a394fc39e4 --- /dev/null +++ b/lib/utils/include/utils/graph/labelled_kwarg_dataflow_graph/json.h @@ -0,0 +1,77 @@ +#ifndef _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_KWARG_DATAFLOW_GRAPH_JSON_H +#define _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_KWARG_DATAFLOW_GRAPH_JSON_H + +#include "utils/graph/instances/unordered_set_labelled_open_kwarg_dataflow_graph.h" +#include "utils/graph/labelled_kwarg_dataflow_graph/algorithms/view_as_labelled_open_kwarg_dataflow_graph.h" +#include "utils/graph/labelled_kwarg_dataflow_graph/labelled_kwarg_dataflow_graph.h" +#include "utils/graph/labelled_open_kwarg_dataflow_graph/algorithms/get_labelled_open_kwarg_dataflow_graph_data.h" +#include "utils/graph/labelled_open_kwarg_dataflow_graph/algorithms/labelled_open_kwarg_dataflow_graph_data.dtg.h" +#include "utils/graph/labelled_open_kwarg_dataflow_graph/algorithms/view_from_labelled_open_kwarg_dataflow_graph_data.h" +#include "utils/json/check_is_json_deserializable.h" +#include "utils/json/check_is_json_serializable.h" +#include "utils/json/monostate.h" +#include +#include + +namespace nlohmann { + +template +struct adl_serializer< + ::FlexFlow::LabelledKwargDataflowGraph> { + static ::FlexFlow:: + LabelledKwargDataflowGraph + from_json(json const &j) { + CHECK_IS_JSON_DESERIALIZABLE( + ::FlexFlow::LabelledOpenKwargDataflowGraphData); + + auto data = j.template get< + ::FlexFlow::LabelledOpenKwargDataflowGraphData>(); + ::FlexFlow::LabelledOpenKwargDataflowGraphView + open_view = + ::FlexFlow::view_from_labelled_open_kwarg_dataflow_graph_data(data); + return ::FlexFlow:: + LabelledKwargDataflowGraph:: + template create_copy_of< + ::FlexFlow::UnorderedSetLabelledOpenKwargDataflowGraph< + NodeLabel, + OutputLabel, + std::monostate, + SlotName>>(open_view); + } + + static void + to_json(json &j, + ::FlexFlow::LabelledKwargDataflowGraph const &g) { + CHECK_IS_JSON_SERIALIZABLE( + ::FlexFlow::LabelledOpenKwargDataflowGraphData); + + ::FlexFlow::LabelledOpenKwargDataflowGraphView + open_view = ::FlexFlow::view_as_labelled_open_kwarg_dataflow_graph< + NodeLabel, + OutputLabel, + std::monostate, + SlotName>(g); + j = ::FlexFlow::get_labelled_open_kwarg_dataflow_graph_data(open_view); + } +}; + +} // namespace nlohmann + +#endif diff --git a/lib/utils/include/utils/graph/labelled_open_dataflow_graph/algorithms/from_labelled_open_dataflow_graph_data.h b/lib/utils/include/utils/graph/labelled_open_dataflow_graph/algorithms/from_labelled_open_dataflow_graph_data.h index 106d500464..bd341b9d81 100644 --- a/lib/utils/include/utils/graph/labelled_open_dataflow_graph/algorithms/from_labelled_open_dataflow_graph_data.h +++ b/lib/utils/include/utils/graph/labelled_open_dataflow_graph/algorithms/from_labelled_open_dataflow_graph_data.h @@ -3,6 +3,7 @@ #include "utils/containers/filtrans.h" #include "utils/graph/labelled_open_dataflow_graph/algorithms/labelled_open_dataflow_graph_data.dtg.h" +#include "utils/graph/labelled_open_dataflow_graph/algorithms/with_labelling.h" #include "utils/graph/labelled_open_dataflow_graph/labelled_open_dataflow_graph_view.h" #include "utils/graph/open_dataflow_graph/algorithms/from_open_dataflow_graph_data.h" #include "utils/graph/open_dataflow_graph/algorithms/open_dataflow_graph_data.dtg.h" diff --git a/lib/utils/include/utils/graph/labelled_open_dataflow_graph/algorithms/labelled_open_dataflow_graph_data.dtg.toml b/lib/utils/include/utils/graph/labelled_open_dataflow_graph/algorithms/labelled_open_dataflow_graph_data.dtg.toml index 32880d697b..a8d3bbf81f 100644 --- a/lib/utils/include/utils/graph/labelled_open_dataflow_graph/algorithms/labelled_open_dataflow_graph_data.dtg.toml +++ b/lib/utils/include/utils/graph/labelled_open_dataflow_graph/algorithms/labelled_open_dataflow_graph_data.dtg.toml @@ -5,6 +5,7 @@ features = [ "eq", "hash", "fmt", + "json", ] template_params = ["NodeLabel", "ValueLabel"] diff --git a/lib/utils/include/utils/graph/labelled_open_dataflow_graph/json.h b/lib/utils/include/utils/graph/labelled_open_dataflow_graph/json.h new file mode 100644 index 0000000000..09d50f2f16 --- /dev/null +++ b/lib/utils/include/utils/graph/labelled_open_dataflow_graph/json.h @@ -0,0 +1,46 @@ +#ifndef _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_OPEN_DATAFLOW_GRAPH_JSON_H +#define _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_OPEN_DATAFLOW_GRAPH_JSON_H + +#include "utils/graph/instances/unordered_set_labelled_open_dataflow_graph.h" +#include "utils/graph/labelled_open_dataflow_graph/algorithms/from_labelled_open_dataflow_graph_data.h" +#include "utils/graph/labelled_open_dataflow_graph/algorithms/get_graph_data.h" +#include "utils/graph/labelled_open_dataflow_graph/algorithms/labelled_open_dataflow_graph_data.dtg.h" +#include "utils/graph/labelled_open_dataflow_graph/labelled_open_dataflow_graph.h" +#include "utils/json/check_is_json_deserializable.h" +#include "utils/json/check_is_json_serializable.h" +#include + +namespace nlohmann { + +template +struct adl_serializer< + ::FlexFlow::LabelledOpenDataflowGraph> { + static ::FlexFlow::LabelledOpenDataflowGraph + from_json(json const &j) { + CHECK_IS_JSON_DESERIALIZABLE( + ::FlexFlow::LabelledOpenDataflowGraphData); + + auto data = j.template get< + ::FlexFlow::LabelledOpenDataflowGraphData>(); + ::FlexFlow::LabelledOpenDataflowGraphView view = + ::FlexFlow::from_labelled_open_dataflow_graph_data(data); + return ::FlexFlow::LabelledOpenDataflowGraph:: + template create_copy_of< + ::FlexFlow::UnorderedSetLabelledOpenDataflowGraph>( + view); + } + + static void to_json( + json &j, + ::FlexFlow::LabelledOpenDataflowGraph const &g) { + CHECK_IS_JSON_SERIALIZABLE( + ::FlexFlow::LabelledOpenDataflowGraphData); + + j = ::FlexFlow::get_graph_data(g); + } +}; + +} // namespace nlohmann + +#endif diff --git a/lib/utils/include/utils/graph/labelled_open_kwarg_dataflow_graph/algorithms/labelled_open_kwarg_dataflow_graph_data.dtg.toml b/lib/utils/include/utils/graph/labelled_open_kwarg_dataflow_graph/algorithms/labelled_open_kwarg_dataflow_graph_data.dtg.toml index a3ba15c6ff..3662a702b2 100644 --- a/lib/utils/include/utils/graph/labelled_open_kwarg_dataflow_graph/algorithms/labelled_open_kwarg_dataflow_graph_data.dtg.toml +++ b/lib/utils/include/utils/graph/labelled_open_kwarg_dataflow_graph/algorithms/labelled_open_kwarg_dataflow_graph_data.dtg.toml @@ -5,6 +5,7 @@ features = [ "eq", "hash", "fmt", + "json", ] template_params = [ diff --git a/lib/utils/include/utils/graph/labelled_open_kwarg_dataflow_graph/json.h b/lib/utils/include/utils/graph/labelled_open_kwarg_dataflow_graph/json.h new file mode 100644 index 0000000000..8973bae350 --- /dev/null +++ b/lib/utils/include/utils/graph/labelled_open_kwarg_dataflow_graph/json.h @@ -0,0 +1,75 @@ +#ifndef _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_OPEN_KWARG_DATAFLOW_GRAPH_JSON_H +#define _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_OPEN_KWARG_DATAFLOW_GRAPH_JSON_H + +#include "utils/graph/instances/unordered_set_labelled_open_kwarg_dataflow_graph.h" +#include "utils/graph/labelled_open_kwarg_dataflow_graph/algorithms/get_labelled_open_kwarg_dataflow_graph_data.h" +#include "utils/graph/labelled_open_kwarg_dataflow_graph/algorithms/labelled_open_kwarg_dataflow_graph_data.dtg.h" +#include "utils/graph/labelled_open_kwarg_dataflow_graph/algorithms/view_from_labelled_open_kwarg_dataflow_graph_data.h" +#include "utils/graph/labelled_open_kwarg_dataflow_graph/labelled_open_kwarg_dataflow_graph.h" +#include "utils/json/check_is_json_deserializable.h" +#include "utils/json/check_is_json_serializable.h" +#include + +namespace nlohmann { + +template +struct adl_serializer<::FlexFlow::LabelledOpenKwargDataflowGraph> { + static ::FlexFlow::LabelledOpenKwargDataflowGraph + from_json(json const &j) { + CHECK_IS_JSON_DESERIALIZABLE( + ::FlexFlow::LabelledOpenKwargDataflowGraphData); + + auto data = j.template get< + ::FlexFlow::LabelledOpenKwargDataflowGraphData>(); + ::FlexFlow::LabelledOpenKwargDataflowGraphView + view = + ::FlexFlow::view_from_labelled_open_kwarg_dataflow_graph_data(data); + return ::FlexFlow::LabelledOpenKwargDataflowGraph:: + template create_copy_of< + ::FlexFlow::UnorderedSetLabelledOpenKwargDataflowGraph< + NodeLabel, + ValueLabel, + GraphInputName, + SlotName>>(view); + } + + static void + to_json(json &j, + ::FlexFlow::LabelledOpenKwargDataflowGraph const &g) { + CHECK_IS_JSON_SERIALIZABLE( + ::FlexFlow::LabelledOpenKwargDataflowGraphData); + + j = ::FlexFlow::get_labelled_open_kwarg_dataflow_graph_data(g); + } +}; + +} // namespace nlohmann + +#endif diff --git a/lib/utils/include/utils/graph/open_dataflow_graph/dataflow_graph_input.dtg.toml b/lib/utils/include/utils/graph/open_dataflow_graph/dataflow_graph_input.dtg.toml index ba26d75e03..7b2f0ebba3 100644 --- a/lib/utils/include/utils/graph/open_dataflow_graph/dataflow_graph_input.dtg.toml +++ b/lib/utils/include/utils/graph/open_dataflow_graph/dataflow_graph_input.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] includes = [ diff --git a/lib/utils/include/utils/graph/open_dataflow_graph/dataflow_input_edge.dtg.toml b/lib/utils/include/utils/graph/open_dataflow_graph/dataflow_input_edge.dtg.toml index 138f17edee..26938dda85 100644 --- a/lib/utils/include/utils/graph/open_dataflow_graph/dataflow_input_edge.dtg.toml +++ b/lib/utils/include/utils/graph/open_dataflow_graph/dataflow_input_edge.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] includes = [ diff --git a/lib/utils/include/utils/graph/open_dataflow_graph/open_dataflow_edge.dtg.toml b/lib/utils/include/utils/graph/open_dataflow_graph/open_dataflow_edge.dtg.toml index 722b1ba682..d58495a427 100644 --- a/lib/utils/include/utils/graph/open_dataflow_graph/open_dataflow_edge.dtg.toml +++ b/lib/utils/include/utils/graph/open_dataflow_graph/open_dataflow_edge.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] includes = [ diff --git a/lib/utils/include/utils/graph/open_dataflow_graph/open_dataflow_value.dtg.toml b/lib/utils/include/utils/graph/open_dataflow_graph/open_dataflow_value.dtg.toml index f77af58411..129621440c 100644 --- a/lib/utils/include/utils/graph/open_dataflow_graph/open_dataflow_value.dtg.toml +++ b/lib/utils/include/utils/graph/open_dataflow_graph/open_dataflow_value.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] includes = [ diff --git a/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/algorithms/open_kwarg_dataflow_graph_data.dtg.toml b/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/algorithms/open_kwarg_dataflow_graph_data.dtg.toml index 49c139cd0a..d9c16cd793 100644 --- a/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/algorithms/open_kwarg_dataflow_graph_data.dtg.toml +++ b/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/algorithms/open_kwarg_dataflow_graph_data.dtg.toml @@ -5,6 +5,7 @@ features = [ "eq", "hash", "fmt", + "json", ] template_params = [ diff --git a/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/kwarg_dataflow_input_edge.dtg.toml b/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/kwarg_dataflow_input_edge.dtg.toml index eec48bb4e0..0d8eea4af3 100644 --- a/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/kwarg_dataflow_input_edge.dtg.toml +++ b/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/kwarg_dataflow_input_edge.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] template_params = [ diff --git a/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/open_kwarg_dataflow_edge.dtg.toml b/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/open_kwarg_dataflow_edge.dtg.toml index cc9d11c608..e0abfe1ac7 100644 --- a/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/open_kwarg_dataflow_edge.dtg.toml +++ b/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/open_kwarg_dataflow_edge.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] template_params = [ diff --git a/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/open_kwarg_dataflow_value.dtg.toml b/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/open_kwarg_dataflow_value.dtg.toml index 24a2021eca..1f24f7997e 100644 --- a/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/open_kwarg_dataflow_value.dtg.toml +++ b/lib/utils/include/utils/graph/open_kwarg_dataflow_graph/open_kwarg_dataflow_value.dtg.toml @@ -6,6 +6,7 @@ features = [ "ord", "hash", "fmt", + "json", ] template_params = [ diff --git a/lib/utils/src/utils/graph/instances/graph_json_instantiations.cc b/lib/utils/src/utils/graph/instances/graph_json_instantiations.cc new file mode 100644 index 0000000000..68ed7c0723 --- /dev/null +++ b/lib/utils/src/utils/graph/instances/graph_json_instantiations.cc @@ -0,0 +1,24 @@ +#include "utils/graph/instances/unordered_set_kwarg_dataflow_graph.h" +#include "utils/graph/kwarg_dataflow_graph/json.h" +#include "utils/graph/labelled_dataflow_graph/json.h" +#include "utils/graph/labelled_kwarg_dataflow_graph/json.h" +#include "utils/graph/labelled_open_dataflow_graph/json.h" +#include "utils/graph/labelled_open_kwarg_dataflow_graph/json.h" + +namespace FlexFlow { + +template class UnorderedSetKwargDataflowGraph; + +} // namespace FlexFlow + +namespace nlohmann { + +template struct adl_serializer<::FlexFlow::LabelledOpenDataflowGraph>; +template struct adl_serializer<::FlexFlow::LabelledDataflowGraph>; +template struct adl_serializer< + ::FlexFlow::LabelledOpenKwargDataflowGraph>; +template struct adl_serializer< + ::FlexFlow::LabelledKwargDataflowGraph>; +template struct adl_serializer<::FlexFlow::KwargDataflowGraph>; + +} // namespace nlohmann diff --git a/lib/utils/src/utils/graph/instances/unordered_set_kwarg_dataflow_graph.cc b/lib/utils/src/utils/graph/instances/unordered_set_kwarg_dataflow_graph.cc new file mode 100644 index 0000000000..13b31ee8b9 --- /dev/null +++ b/lib/utils/src/utils/graph/instances/unordered_set_kwarg_dataflow_graph.cc @@ -0,0 +1,8 @@ +#include "utils/graph/instances/unordered_set_kwarg_dataflow_graph.h" +#include "utils/archetypes/ordered_value_type.h" + +namespace FlexFlow { + +template struct UnorderedSetKwargDataflowGraph>; + +} // namespace FlexFlow From 368b9db0d523bf7dec50413410fbf7f8a06b285e Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Fri, 6 Mar 2026 12:14:42 -0800 Subject: [PATCH 2/2] Cosmetic cleanup. --- .../utils/graph/instances/graph_json_instantiations.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/utils/src/utils/graph/instances/graph_json_instantiations.cc b/lib/utils/src/utils/graph/instances/graph_json_instantiations.cc index 68ed7c0723..97126d2ecb 100644 --- a/lib/utils/src/utils/graph/instances/graph_json_instantiations.cc +++ b/lib/utils/src/utils/graph/instances/graph_json_instantiations.cc @@ -13,12 +13,12 @@ template class UnorderedSetKwargDataflowGraph; namespace nlohmann { -template struct adl_serializer<::FlexFlow::LabelledOpenDataflowGraph>; +template struct adl_serializer<::FlexFlow::KwargDataflowGraph>; template struct adl_serializer<::FlexFlow::LabelledDataflowGraph>; -template struct adl_serializer< - ::FlexFlow::LabelledOpenKwargDataflowGraph>; template struct adl_serializer< ::FlexFlow::LabelledKwargDataflowGraph>; -template struct adl_serializer<::FlexFlow::KwargDataflowGraph>; +template struct adl_serializer<::FlexFlow::LabelledOpenDataflowGraph>; +template struct adl_serializer< + ::FlexFlow::LabelledOpenKwargDataflowGraph>; } // namespace nlohmann