Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top-level loop for compiler #1576

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0d639ac
initial implmentation of meomry algorithm
wmdi Oct 13, 2024
da857a5
fmt
wmdi Oct 16, 2024
ef8c5c2
pass existing tests
wmdi Oct 16, 2024
982f1f5
initialize memory algorithm
wmdi Oct 31, 2024
01c6a6b
Merge remote-tracking branch 'flexflow/repo-refactor' into memory-alg
wmdi Oct 31, 2024
964c885
fix tests & format
wmdi Oct 31, 2024
0c0e7b0
minimum tests for memory algorithm
wmdi Nov 7, 2024
7778377
renaming
wmdi Dec 18, 2024
0315160
fmt
wmdi Dec 18, 2024
855a7d5
fix
wmdi Dec 30, 2024
2b4e127
rename single machine mapping
wmdi Jan 9, 2025
f72fb6f
Merge branch 'master' into memory-alg
lockshaw Jan 9, 2025
50bae93
format
wmdi Jan 9, 2025
3297d3f
Merge branch 'memory-alg' of github.com:wmdi/FlexFlow into memory-alg
wmdi Jan 9, 2025
d96b678
top-level loop for compiler
wmdi Jan 15, 2025
cd9b031
Merge branch 'master' into memory-alg
lockshaw Jan 15, 2025
1dcaa42
Merge branch 'master' into memory-alg
lockshaw Jan 20, 2025
c16bcf6
fixes
wmdi Jan 21, 2025
2e93e74
Merge branch 'memory-alg' of github.com:wmdi/FlexFlow into memory-alg
wmdi Jan 21, 2025
62389ad
upd
wmdi Jan 22, 2025
6d2fe50
fixes
wmdi Jan 29, 2025
45a931c
fix
wmdi Jan 30, 2025
efc7a9a
Merge remote-tracking branch 'flexflow/master' into memory-alg
wmdi Jan 30, 2025
4f97602
Merge remote-tracking branch 'flexflow/master' into memory-alg
wmdi Feb 12, 2025
14234b4
fix some errors introduced in merge
wmdi Feb 12, 2025
30e51fc
upd
wmdi Feb 20, 2025
ddbace1
Merge remote-tracking branch 'origin/master' into memory-alg
wmdi Feb 25, 2025
eb58e91
add test case for get mm problem tree
wmdi Feb 25, 2025
40c3494
Fix is_valid_machine_mapping_problem_tree, add hacky printing for pro…
lockshaw Feb 26, 2025
962934d
upd
wmdi Feb 27, 2025
550127a
update (#3)
Marsella8 Feb 28, 2025
948d247
fix get_optimal_machine_mapping
wmdi Mar 2, 2025
612bff5
implement divisible_by constarint type in substitutions
wmdi Mar 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/compiler/include/compiler/algorithm_config.variant.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace = "FlexFlow"
name = "AlgorithmConfig"
features = [
"eq",
"hash",
"fmt",
]

includes = [
"compiler/data_parallelism/data_parallelism_config.dtg.h",
"compiler/unity_algorithm/unity_search_config.dtg.h",
]

[[values]]
type = "::FlexFlow::DataParallelismConfig"

[[values]]
type = "::FlexFlow::UnitySearchConfig"
32 changes: 6 additions & 26 deletions lib/compiler/include/compiler/compiler.h
Original file line number Diff line number Diff line change
@@ -1,42 +1,22 @@
#ifndef _FLEXFLOW_COMPILER_COMPILER_H
#define _FLEXFLOW_COMPILER_COMPILER_H

#include "pcg/cost_values.h"
#include "pcg/machine_view.h"
#include "pcg/parallel_computation_graph/parallel_computation_graph.h"
#include "pcg/tensor_mapping.h"
#include "compiler/algorithm_config.dtg.h"
#include "compiler/cost_estimator/cost_estimator.h"
#include "compiler/search_result.dtg.h"
#include "pcg/machine_specification.dtg.h"

namespace FlexFlow {

enum class SearchAlgorithm {
DATA_PARALLEL,
};

using SearchAlgorithmConfig = std::variant<>;
using SearchSolution = std::variant<>;

struct SearchResult {
ParallelComputationGraph pcg;
TensorMapping tensor_mapping;
SearchSolution solution;
CostValues cost_values;
UNITY,
};

SearchResult optimize(ComputationGraph const &,
MachineSpecification const &,
CostEstimator const &,
SearchAlgorithm,
optional<AlgorithmConfig> const &);

// struct SearchSolution {
// LabelledMultiDiGraph<PCGOperatorAttrs, ParallelTensorShape> optimized_pcg;
// std::unordered_map<Node, MachineView> device_assignments;
// /* std::unordered_map<tensor_guid_t,
// std::unordered_set<parallel_tensor_guid_t>> tensor_mappings; */
// };
//
// SearchSolution run_data_parallelize(ComputationGraph const &,
// MachineSpecification const &);
AlgorithmConfig const &);

} // namespace FlexFlow

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace = "FlexFlow"
name = "DataParallelismConfig"
features = [
"eq",
"hash",
"fmt",
]

includes = [
]

[[fields]]
name = "degree"
type = "int"
16 changes: 0 additions & 16 deletions lib/compiler/include/compiler/graph_optimize_result.struct.toml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define _FLEXFLOW_COMPILER_MACHINE_MAPPING_H

#include "compiler/machine_mapping/machine_mapping.dtg.h"
#include "compiler/machine_mapping/machine_mapping_result.h"
#include "compiler/series_parallel/pcg/pcg_binary_sp_decomposition.dtg.h"
#include "pcg/device_id_t.dtg.h"
#include "pcg/machine_specification.dtg.h"
#include "pcg/operator_task_space.dtg.h"
Expand All @@ -14,6 +16,13 @@ MachineMapping combine_disjoint_mappings(MachineMapping const &,

bool nodes_are_disjoint(MachineMapping const &m1, MachineMapping const &m2);

parallel_layer_guid_t
get_layer_from_path(PCGBinarySPDecomposition const &sp_decomposition,
BinaryTreePath const &path);

std::optional<MachineMapping> get_machine_mapping_from_machine_mapping_result(
PCGBinarySPDecomposition const &, MachineMappingResult const &);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "compiler/machine_mapping/machine_mapping_problem_tree/machine_mapping_problem_tree.dtg.h"
#include "compiler/machine_mapping/machine_mapping_problem_tree/mm_problem_tree_parallel_split.dtg.h"
#include "compiler/machine_mapping/machine_mapping_problem_tree/mm_problem_tree_series_split.dtg.h"
#include "compiler/machine_mapping/machine_mapping_problem_tree/unmapped_op_cost_estimate_key.dtg.h"
#include "utils/full_binary_tree/binary_tree_path.dtg.h"
#include "utils/graph/series_parallel/binary_sp_decomposition_tree/generic_binary_sp_decomposition_tree/generic_binary_sp_decomposition_tree_implementation.dtg.h"
#include "utils/graph/series_parallel/sp_decomposition_tree_node_type.dtg.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ includes = [
"op-attrs/parallel_tensor_shape.dtg.h",
"<vector>",
"pcg/machine_view.dtg.h",
"pcg/operator_task_space.dtg.h",
]

src_includes = [
Expand All @@ -34,3 +35,6 @@ type = "std::vector<::FlexFlow::ParallelTensorShape>"
name = "output_shapes"
type = "std::vector<::FlexFlow::ParallelTensorShape>"

[[fields]]
name = "op_task_space"
type = "::FlexFlow::OperatorTaskSpace"
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ FeasibleMachineMappingResult require_feasible(MachineMappingResult const &);
make_singleton_machine_mapping_result(float runtime,
MachineView const &machine_view);

[[nodiscard]] float get_runtime_cost(MachineMappingResult const &mm_result);

} // namespace FlexFlow

#endif
17 changes: 17 additions & 0 deletions lib/compiler/include/compiler/search_result.struct.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace = "FlexFlow"
name = "SearchResult"
features = [
]

includes = [
"pcg/parallel_computation_graph/parallel_computation_graph.h",
"compiler/machine_mapping/machine_mapping.h",
]

[[fields]]
name = "pcg"
type = "::FlexFlow::ParallelComputationGraph"

[[fields]]
name = "machine_mapping"
type = "::FlexFlow::MachineMapping"
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_SERIES_PARALLEL_GET_PCG_BALANCED_BINARY_SP_DECOMPOSITION_H
#define _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_SERIES_PARALLEL_GET_PCG_BALANCED_BINARY_SP_DECOMPOSITION_H

#include "compiler/series_parallel/pcg/pcg_binary_sp_decomposition.dtg.h"

namespace FlexFlow {

std::optional<PCGBinarySPDecomposition>
Expand Down
24 changes: 0 additions & 24 deletions lib/compiler/include/compiler/unity_algorithm.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef _FLEXFLOW_COMPILER_MCMC_STATE_H
#define _FLEXFLOW_COMPILER_MCMC_STATE_H

#include "compiler/graph_optimize_result.dtg.h"
#include "pcg/parallel_computation_graph/parallel_computation_graph.h"

namespace FlexFlow {

struct GraphOptimizeState {
GraphOptimizeState(GraphOptimizeResult const &graph_optimize_result,
float runtime);
GraphOptimizeState(ParallelComputationGraph const &pcg,
float runtime_with_optimal_mm);

GraphOptimizeResult graph_optimize_result;
float runtime;
ParallelComputationGraph pcg;
float runtime_with_optimal_mm;

bool operator==(GraphOptimizeState const &other) const;
bool operator!=(GraphOptimizeState const &other) const;
Expand Down
20 changes: 20 additions & 0 deletions lib/compiler/include/compiler/unity_algorithm/unity_algorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _FLEXFLOW_COMPILER_UNITY_ALGORITHM_H
#define _FLEXFLOW_COMPILER_UNITY_ALGORITHM_H

#include "compiler/cost_estimator/cost_estimator.h"
#include "compiler/search_result.dtg.h"
#include "compiler/unity_algorithm/unity_search_config.dtg.h"
#include "pcg/machine_specification.dtg.h"
#include "substitutions/substitution.h"

namespace FlexFlow {

SearchResult graph_optimize(ParallelComputationGraph &pcg,
CostEstimator const &cost_estimator,
MachineSpecification const &resources,
std::vector<Substitution> const &substitutions,
UnitySearchConfig const &search_config);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace = "FlexFlow"
name = "OptimizerConfig"
name = "UnitySearchConfig"
features = [
"eq",
"hash",
Expand Down
27 changes: 27 additions & 0 deletions lib/compiler/src/compiler/compiler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "compiler/compiler.h"
#include "compiler/unity_algorithm/unity_algorithm.h"
#include "utils/overload.h"

namespace FlexFlow {

SearchResult optimize(ComputationGraph const &computation_graph,

Check warning on line 7 in lib/compiler/src/compiler/compiler.cc

View check run for this annotation

Codecov / codecov/patch

lib/compiler/src/compiler/compiler.cc#L7

Added line #L7 was not covered by tests
MachineSpecification const &machine_specification,
CostEstimator const &cost_estimator,
AlgorithmConfig const &search_config) {
return search_config.visit<SearchResult>(overload{
[&](DataParallelismConfig const &config) -> SearchResult {
throw std::runtime_error(
"Data parallel search algorithm is not implemented yet");

Check warning on line 14 in lib/compiler/src/compiler/compiler.cc

View check run for this annotation

Codecov / codecov/patch

lib/compiler/src/compiler/compiler.cc#L11-L14

Added lines #L11 - L14 were not covered by tests
},
[&](UnitySearchConfig const &config) {
ParallelComputationGraph pcg =

Check warning on line 17 in lib/compiler/src/compiler/compiler.cc

View check run for this annotation

Codecov / codecov/patch

lib/compiler/src/compiler/compiler.cc#L16-L17

Added lines #L16 - L17 were not covered by tests
parallel_computation_graph_from_computation_graph(
computation_graph);
std::vector<Substitution> substitutions; // TODO: Implement this
return graph_optimize(
pcg, cost_estimator, machine_specification, substitutions, config);
},
});

Check warning on line 24 in lib/compiler/src/compiler/compiler.cc

View check run for this annotation

Codecov / codecov/patch

lib/compiler/src/compiler/compiler.cc#L19-L24

Added lines #L19 - L24 were not covered by tests
}

} // namespace FlexFlow
85 changes: 0 additions & 85 deletions lib/compiler/src/compiler/graph_optimize_state.cc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "compiler/allowed_machine_views.h"
#include "compiler/machine_mapping/allowed_machine_views.h"
#include "pcg/machine_specification.h"
#include "pcg/machine_view.h"
#include "pcg/multi_dimensional_stride.dtg.h"
Expand Down
Loading
Loading