Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
35 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
e18c6ab
add failed example
wmdi Mar 12, 2025
677b0fe
Merge remote-tracking branch 'flexflow/master' into memory-alg
wmdi Apr 29, 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"

namespace FlexFlow {

Expand All @@ -10,6 +12,9 @@ MachineMapping combine_disjoint_mappings(MachineMapping const &,

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

MachineMapping get_machine_mapping_from_machine_mapping_result(
PCGBinarySPDecomposition const &, MachineMappingResult const &);

} // 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
21 changes: 21 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,21 @@
#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,
DeviceType device_type);

} // 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
31 changes: 31 additions & 0 deletions lib/compiler/src/compiler/compiler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "compiler/compiler.h"
#include "compiler/unity_algorithm/unity_algorithm.h"
#include "utils/overload.h"

namespace FlexFlow {

SearchResult optimize(ComputationGraph const &computation_graph,
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");
},
[&](UnitySearchConfig const &config) {
ParallelComputationGraph pcg =
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,
DeviceType::GPU);

},
});
}

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

This file was deleted.

37 changes: 37 additions & 0 deletions lib/compiler/src/compiler/machine_mapping/machine_mapping.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "compiler/machine_mapping/machine_mapping.h"
#include "compiler/series_parallel/pcg/pcg_binary_sp_decomposition.h"
#include "utils/containers/are_disjoint.h"
#include "utils/containers/keys.h"
#include "utils/containers/merge_maps.h"
#include "utils/containers/map_keys.h"
#include "utils/graph/series_parallel/binary_sp_decomposition_tree/binary_sp_decomposition_tree.h"

namespace FlexFlow {

Expand All @@ -14,4 +17,38 @@ bool nodes_are_disjoint(MachineMapping const &m1, MachineMapping const &m2) {
return are_disjoint(keys(m1.machine_views), keys(m2.machine_views));
}

MachineMapping get_machine_mapping_from_machine_mapping_result(
PCGBinarySPDecomposition const &sp_decomposition,
MachineMappingResult const &mm_result) {

BinarySPDecompositionTree sp_tree =
binary_sp_tree_from_pcg_sp_tree(sp_decomposition);

auto get_layer_from_path =
[&](BinaryTreePath const &path) -> parallel_layer_guid_t {
std::optional<BinarySPDecompositionTree> subtree_optional =
binary_sp_decomposition_tree_get_subtree_at_path(sp_tree, path);
if (!subtree_optional.has_value()) {
throw std::runtime_error(fmt::format("Invalid tree path {}", path));
}
BinarySPDecompositionTree subtree = subtree_optional.value();
if (!subtree.is_node()) {
throw std::runtime_error(fmt::format("Invalid tree path to a leaf: found {} instead", subtree));
}
return parallel_layer_guid_t{
subtree.require_node(),
};
};

std::unordered_map<parallel_layer_guid_t, MachineView> mm;

if (mm_result.raw_result) {
FeasibleMachineMappingResult const &feasible_mm_result =
mm_result.raw_result.value();
mm = map_keys(feasible_mm_result.machine_mapping.raw_mapping, get_layer_from_path);
}

return MachineMapping{mm};
}

} // namespace FlexFlow
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "compiler/allowed_machine_views.h"
#include "compiler/unity_algorithm/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