Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
510c2d9
Start on pcg builder
lockshaw Jun 4, 2024
7b55ed1
Add tests and some implementation for pcg builder
lockshaw Jun 4, 2024
c379efd
Add pcg tests, make dtgen constructors explicit to fix bug
lockshaw Jun 10, 2024
35fa653
Add remainder of PCG tests
lockshaw Jun 10, 2024
865a28e
Merge remote-tracking branch 'origin/repo-refactor' into pcg-builder
lockshaw Jun 10, 2024
f379539
Fix build issues in local-execution
lockshaw Jun 10, 2024
2dbb3b9
Format
lockshaw Jun 10, 2024
4050c99
Address Reyna comments, add topological_order function for PCG
lockshaw Jun 17, 2024
42c1968
Pre multidigraph refactor
lockshaw Jun 19, 2024
3be816f
Removing visitable from sp code
lockshaw Jun 21, 2024
6d68324
Add open dataflow graph, start to replace pcg dataflow graph
lockshaw Jun 23, 2024
64a3403
Start refactoring substitutions
lockshaw Jun 24, 2024
7d4c7be
Add utility functions to support pattern matching
lockshaw Jun 25, 2024
9ab9eb2
Pre-refactor inputs
lockshaw Jun 26, 2024
7ae7c65
Merge remote-tracking branch 'origin/repo-refactor' into dataflow-graph
lockshaw Jun 26, 2024
f9b129e
Fix proj url
lockshaw Jun 26, 2024
cf73f08
Get back to substitutions, now with unordered graph inputs
lockshaw Jul 7, 2024
5fd666d
Get substitutions building
lockshaw Jul 13, 2024
5f0c88a
substitutions-tests now builds
lockshaw Jul 13, 2024
3228f2d
Fix bug in filter, pass some initial substitution tests
lockshaw Jul 14, 2024
5f4cc01
Add tests for fmt::to_string, fix some substitutions bugs
lockshaw Jul 15, 2024
ad60be0
Pass initial unit tests for find_pattern_matches
lockshaw Jul 15, 2024
a972da2
Start on unit tests for pcg pattern
lockshaw Jul 15, 2024
bcf776e
Pass initial test for find_pattern_matches
lockshaw Jul 19, 2024
e28400e
Merge remote-tracking branch 'origin/repo-refactor' into dataflow-graph
lockshaw Jul 19, 2024
fe6d65d
Fix small build issue in tests
lockshaw Jul 19, 2024
e647af7
Format
lockshaw Jul 19, 2024
8b58760
Sync tests in CI with tests in proj
lockshaw Jul 19, 2024
1fafb9d
Fix minor build errors in kernels and local-execution
lockshaw Jul 19, 2024
0804314
Format
lockshaw Jul 19, 2024
dd5465c
Remove outdated code
lockshaw Jul 20, 2024
29ec5b8
More outdated code removal
lockshaw Jul 20, 2024
ff41743
More cleanup, add test for sp decomposition
lockshaw Jul 20, 2024
e71d200
Pull apart containers.h
lockshaw Jul 21, 2024
c06710c
More sp testing and fixes
lockshaw Jul 21, 2024
2f75566
Break up graph algorithms.h
lockshaw Jul 21, 2024
c81d3a4
Pre- full SP algo commit
lockshaw Jul 23, 2024
2a11c7e
Add initial implementation and tests for cbc decomposition and invers…
lockshaw Jul 23, 2024
71a9e0f
Pass test for get_inverse_line_graph
lockshaw Jul 24, 2024
25eb1db
Add new multidigraph
lockshaw Jul 24, 2024
64f1932
Fix get_inverse_line_graph to return a MultiDiGraph instead of a DiGraph
lockshaw Jul 24, 2024
31c8d17
Add tests for parallel and series reduction finding
lockshaw Jul 24, 2024
19e7e28
Add really rough implementation of valdez sp decomposition
lockshaw Jul 24, 2024
3791e86
Fix local-execution build
lockshaw Jul 25, 2024
267b72d
Add implementations and tests for applying series/parallel reductions
lockshaw Jul 25, 2024
131ceeb
Add transformer pcg prototype
hsdfzhsdfz Jul 25, 2024
bb2769a
Format
lockshaw Jul 26, 2024
39cb7b3
Clean up sp decomposition interface and tests
lockshaw Jul 27, 2024
ce0234d
Format
lockshaw Jul 27, 2024
3dc3ec6
Add comments for top-level substitutions functions, add proj doxygen …
lockshaw Jul 31, 2024
ee518c2
Start sketching out substitutions code
lockshaw Jul 31, 2024
f69b95a
Merge branch 'dataflow-graph' into substitutions-fix
lockshaw Jul 31, 2024
3c06b88
Fix build errors
lockshaw Aug 1, 2024
3d6f681
Add ability to permute node ids
lockshaw Aug 1, 2024
098a9d1
Cleanup and start to test new substitutions code
lockshaw Aug 4, 2024
9bd4f14
Add test case for evaluate_substitution_output
lockshaw Aug 5, 2024
101083b
Add naive isomorphism detection code
lockshaw Aug 5, 2024
9fec50c
Add graph inputs to open dataflow graph isomorphism
lockshaw Aug 6, 2024
7c60736
Add input permutation to evaluate_substitution_output
lockshaw Aug 6, 2024
c3363fb
Update based on review comments
hsdfzhsdfz Aug 8, 2024
f2660ea
Merge branch 'repo-refactor' into transformer-pcg-prototype
lockshaw Aug 8, 2024
cb6eab2
Fix permute_node_ids
lockshaw Aug 8, 2024
2f3d67a
Add test for permute_input_ids
lockshaw Aug 8, 2024
54211ae
Add models makefile and test
hsdfzhsdfz Aug 10, 2024
8dd0498
Update
hsdfzhsdfz Aug 10, 2024
b1f74fc
Pass test
hsdfzhsdfz Aug 17, 2024
98901a4
Enhance Transformer implementation
hsdfzhsdfz Aug 17, 2024
76de8ec
Reflect review comments
hsdfzhsdfz Aug 22, 2024
03cbd02
Migrate over to mutable implementation of apply_substitution
lockshaw Aug 23, 2024
4a8deae
Add fast isomorphism checking and an initial implementation of full s…
lockshaw Aug 24, 2024
0757e94
Pass initial full substitutions test
lockshaw Aug 24, 2024
ba0a174
Cleanup old isomorphism checking code
lockshaw Aug 24, 2024
4dfa403
Merge remote-tracking branch 'origin/repo-refactor' into substitution…
lockshaw Aug 24, 2024
f156f96
Fix post-merge bugs
lockshaw Aug 24, 2024
738755d
[WIP] Save initial refactor
hsdfzhsdfz Aug 25, 2024
5f09298
Fix broken pcg builder test
lockshaw Aug 26, 2024
deff4f8
Format
lockshaw Aug 26, 2024
d71d24f
Reorganize code and remove some outdated code pre-code-review
lockshaw Aug 26, 2024
1a63f90
Format
lockshaw Aug 26, 2024
073f4d3
Implement actual encorder decoder architecture
hsdfzhsdfz Aug 27, 2024
3c2edcd
Merge branch 'repo-refactor' of https://github.com/flexflow/FlexFlow …
hsdfzhsdfz Aug 29, 2024
6bb12bf
Remove duplicated definition
hsdfzhsdfz Aug 29, 2024
a2eb8b4
Update based on review
hsdfzhsdfz Aug 31, 2024
bf1dbfa
Update argument order
hsdfzhsdfz Aug 31, 2024
aecbbe6
Address review comments
lockshaw Aug 31, 2024
afc6f7f
Address missed comment
lockshaw Aug 31, 2024
7d6fadf
Remove latex dependency to avoid CI out-of-disk-space
lockshaw Aug 31, 2024
f804308
Format
lockshaw Aug 31, 2024
e87eab7
Implement most of the shape inference and ComputationGraphBuilder sup…
lockshaw Sep 1, 2024
4dd0f8f
Fix bug in LayerNorm shape inference tests, disable {?} doctest default
lockshaw Sep 1, 2024
8d1087b
Fix transformer test
lockshaw Sep 1, 2024
438efcc
Format
lockshaw Sep 1, 2024
cfede68
Merge branch 'add-transformer-model' into dump-model-arch
lockshaw Sep 1, 2024
2102dec
Get initial export-model-arch binary building
lockshaw Sep 2, 2024
3de6e06
Actually dump valid json from export-model-arch
lockshaw Sep 2, 2024
ff73219
Some minor polishing of export-model-arch
lockshaw Sep 2, 2024
00c4e28
Merge branch 'repo-refactor' into dump-model-arch
lockshaw Sep 3, 2024
31820fc
Add binary sp tree logic and start on sp decomposition of computation…
lockshaw Sep 4, 2024
f89c74b
Fix sp decomposition export of transformer (a lot of cleanup now needed)
lockshaw Sep 5, 2024
6bb5022
Flesh out export-model-arch CLI and features
lockshaw Sep 6, 2024
a03913c
Merge remote-tracking branch 'origin/repo-refactor' into dump-model-arch
lockshaw Sep 6, 2024
07b4bc2
Format
lockshaw Sep 6, 2024
59f2a49
Add split_test model
lockshaw Sep 6, 2024
32c429d
Add single_operator model for testing
lockshaw Sep 6, 2024
69ab046
Add substitution-to-dot and export-model-arch build to CI
lockshaw Sep 7, 2024
066d87e
Cleanup generic_binary_sp_decomposition_tree
lockshaw Sep 7, 2024
96ae3b0
Format
lockshaw Sep 7, 2024
530a734
Fix substitution-to-dot name in CI
lockshaw Sep 7, 2024
951f57e
Add testing for cli_get_help_message
lockshaw Sep 7, 2024
af98df1
Add testing for cli_parse
lockshaw Sep 7, 2024
b97bdb3
Add missing include in export_model_arch
lockshaw Sep 7, 2024
728b80f
Add basic test for cli_parse on raw argv
lockshaw Sep 8, 2024
73e1c6c
Rename serial-parallel -> series-parallel
lockshaw Sep 8, 2024
60f1084
Add a bunch of testing for new code
lockshaw Sep 8, 2024
fe3cfe2
Add tests for computation graph sp decomposition
lockshaw Sep 8, 2024
c9a7ed6
Format
lockshaw Sep 8, 2024
59d9068
Fix build error in export-model-arch
lockshaw Sep 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
42 changes: 25 additions & 17 deletions .github/workflows/per-lib-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,71 +62,79 @@ jobs:

- name: Build utils
run: |
build_libs.sh utils
build_target.sh utils

- name: Build op-attrs
run: |
build_libs.sh op-attrs
build_target.sh op-attrs

- name: Build pcg
run: |
build_libs.sh pcg
build_target.sh pcg

- name: Build kernels
run: |
build_libs.sh kernels
build_target.sh kernels

- name: Build substitutions
run: |
build_libs.sh substitutions
build_target.sh substitutions

- name: Build compiler
run: |
build_libs.sh compiler
build_target.sh compiler

- name: Build substitution-generator
run: |
build_libs.sh substitution-generator
build_target.sh substitution-generator

- name: Build local-execution
run: |
build_libs.sh local-execution
build_target.sh local-execution

- name: Build models
run: |
build_libs.sh models
build_target.sh models

- name: Build substitution-to-dot
run: |
build_target.sh substitution-to-dot

- name: Build export-model-arch
run: |
build_target.sh export-model-arch

- name: Test utils
run: |
test_libs.sh utils
test_target.sh utils

- name: Test op-attrs
run: |
test_libs.sh op-attrs
test_target.sh op-attrs

- name: Test pcg
run: |
test_libs.sh pcg
test_target.sh pcg

- name: Test substitutions
run: |
test_libs.sh substitutions
test_target.sh substitutions

# - name: Test compiler
# run: |
# test_libs.sh compiler
# test_target.sh compiler

- name: Test substitution-generator
run: |
test_libs.sh substitution-generator
test_target.sh substitution-generator

- name: Test local-execution
run: |
test_libs.sh local-execution
test_target.sh local-execution

- name: Test models
run: |
test_libs.sh models
test_target.sh models

- name: Generate code coverage
run: |
Expand Down
2 changes: 2 additions & 0 deletions .proj.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ build_targets = [
"substitution-generator",
"local-execution",
"models",
"export-model-arch",
"substitution-to-dot",
]

test_targets = [
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ option(FF_BUILD_UNIT_TESTS "build non-operator unit tests" OFF)
option(FF_BUILD_SUBSTITUTION_TOOL "build substitution conversion tool" OFF)
option(FF_BUILD_VISUALIZATION_TOOL "build substitution visualization tool" ON)
option(FF_BUILD_ARG_PARSER "build command line argument parser" OFF)
option(FF_BUILD_BIN_EXPORT_MODEL_ARCH "build export-model-arch utility" ON)

set(FF_CUDA_ARCH "autodetect" CACHE STRING "Target CUDA Arch")
if (FF_CUDA_ARCH STREQUAL "")
Expand Down
6 changes: 5 additions & 1 deletion bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ if(FF_BUILD_SUBSTITUTION_TOOL)
endif()

if(FF_BUILD_VISUALIZATION_TOOL)
add_subdirectory(substitutions-to-dot)
add_subdirectory(substitution-to-dot)
endif()

if(FF_BUILD_ARG_PARSER)
add_subdirectory(arg_parser)
endif()

if(FF_BUILD_BIN_EXPORT_MODEL_ARCH)
add_subdirectory(export-model-arch)
endif()
12 changes: 12 additions & 0 deletions bin/export-model-arch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ff_add_executable(
NAME
export-model-arch
SRC_PATTERNS
src/*.cc
PRIVATE_INCLUDE
include/
DEPS
utils
models
compiler
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace = "FlexFlow"
name = "JsonSPModelExport"
features = [
"eq",
"hash",
"json",
"fmt",
]

includes = [
"pcg/file_format/v1/v1_computation_graph.dtg.h",
"utils/graph/series_parallel/binary_sp_decomposition_tree/generic_binary_sp_decomposition_tree/generic_binary_sp_decomposition_tree.h",
]

src_includes = [
"utils/graph/series_parallel/binary_sp_decomposition_tree/generic_binary_sp_decomposition_tree/hash.h",
"utils/graph/series_parallel/binary_sp_decomposition_tree/generic_binary_sp_decomposition_tree/fmt.h",
"utils/graph/series_parallel/binary_sp_decomposition_tree/generic_binary_sp_decomposition_tree/json.h",
]

[[fields]]
name = "sp_decomposition"
type = "::FlexFlow::GenericBinarySPDecompositionTree<int>"

[[fields]]
name = "computation_graph"
type = "::FlexFlow::V1ComputationGraph"
208 changes: 208 additions & 0 deletions bin/export-model-arch/src/export_model_arch.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#include "compiler/series_parallel/computation_graph_binary_sp_decomposition.h"
#include "compiler/series_parallel/get_computation_graph_series_parallel_decomposition.h"
#include "export_model_arch/json_sp_model_export.dtg.h"
#include "models/split_test/split_test.h"
#include "models/transformer/transformer.h"
#include "op-attrs/computation_graph_op_attrs.h"
#include "pcg/computation_graph.h"
#include "pcg/file_format/v1/v1_computation_graph.h"
#include "utils/cli/cli_get_help_message.h"
#include "utils/cli/cli_parse.h"
#include "utils/cli/cli_parse_result.h"
#include "utils/cli/cli_spec.h"
#include "utils/graph/series_parallel/binary_sp_decomposition_tree/generic_binary_sp_decomposition_tree/transform.h"
#include "utils/graph/series_parallel/binary_sp_decomposition_tree/right_associative_binary_sp_tree_from_nary.h"
#include "utils/graph/series_parallel/get_series_parallel_decomposition.h"

using namespace ::FlexFlow;

ComputationGraph get_single_operator_computation_graph() {
ComputationGraphBuilder b;

size_t batch_size = 8;
size_t in_channels = 16;
size_t out_channels = 12;
TensorShape input_shape = TensorShape{
TensorDims{FFOrdered<size_t>{
batch_size,
in_channels,
out_channels,
}},
DataType::FLOAT,
};

tensor_guid_t input = b.create_input(input_shape, CreateGrad::YES);

InitializerAttrs kernel_initializer =
InitializerAttrs{GlorotUniformAttrs{/*seed=*/12}};
InitializerAttrs bias_initializer = InitializerAttrs{ZeroInitializerAttrs{}};
tensor_guid_t output = b.dense(input,
in_channels,
Activation::RELU,
/*use_bias=*/true,
DataType::FLOAT,
kernel_initializer,
bias_initializer,
"my_example_operator");

return b.computation_graph;
}

ComputationGraph get_default_transformer_computation_graph() {
TransformerConfig config = get_default_transformer_config();
ComputationGraph cg = get_transformer_computation_graph(config);

return cg;
}

tl::expected<ComputationGraph, std::string>
get_model_computation_graph(std::string const &model_name) {
if (model_name == "transformer") {
return get_default_transformer_computation_graph();
} else if (model_name == "split_test") {
int batch_size = 8;
return get_split_test_computation_graph(batch_size);
} else if (model_name == "single_operator") {
return get_single_operator_computation_graph();
} else {
return tl::unexpected(fmt::format("Unknown model name: {}", model_name));
}
}

tl::expected<JsonSPModelExport, std::string>
get_sp_model_export(std::string const &model_name) {
ComputationGraph computation_graph = ({
tl::expected<ComputationGraph, std::string> result =
get_model_computation_graph(model_name);
if (!result.has_value()) {
return tl::unexpected(result.error());
}
result.value();
});

ComputationGraphBinarySPDecomposition sp_decomposition = ({
std::optional<ComputationGraphBinarySPDecomposition> result =
get_computation_graph_right_assoc_binary_sp_decomposition(
computation_graph);
if (!result.has_value()) {
return tl::unexpected("Failed to generate series-parallel decomposition "
"of computation graph.");
}
result.value();
});

std::pair<V1ComputationGraph, bidict<int, layer_guid_t>> v1_result =
to_v1_including_node_numbering(computation_graph);
V1ComputationGraph v1_cg = v1_result.first;
bidict<int, layer_guid_t> layer_numbering = v1_result.second;
GenericBinarySPDecompositionTree<int> v1_sp_decomposition =
transform(sp_decomposition.raw_tree,
[&](layer_guid_t const &l) { return layer_numbering.at_r(l); });

return JsonSPModelExport{
v1_sp_decomposition,
v1_cg,
};
}

int main(int argc, char **argv) {
CLISpec cli = empty_cli_spec();

CLIArgumentKey arg_key_help = cli_add_help_flag(cli);

CLIArgumentKey key_sp_decomposition =
cli_add_flag(cli,
CLIFlagSpec{"sp-decomposition",
std::nullopt,
"also output a series parallel decomposition of "
"the model's computation graph"});

CLIArgumentKey key_dot = cli_add_flag(
cli,
CLIFlagSpec{
"dot",
std::nullopt,
"output a dot representation of the model's computation graph"});

CLIArgumentKey key_preprocessed_dot = cli_add_flag(
cli,
CLIFlagSpec{"preprocessed-dot",
std::nullopt,
"output a dot representation of model's computation graph "
"for preprocessed to help check series-parallel structure"});

std::vector<std::string> model_options = {
"transformer", "split_test", "single_operator"};
CLIArgumentKey key_model_name = cli_add_positional_argument(
cli,
CLIPositionalArgumentSpec{
"model", model_options, "name of the model to export"});

assert(argc >= 1);
std::string prog_name = argv[0];

CLIParseResult parsed = ({
tl::expected<CLIParseResult, std::string> result =
cli_parse(cli, argc, argv);
if (!result.has_value()) {
std::string error_msg = result.error();
std::cerr << cli_get_help_message(prog_name, cli);
std::cerr << std::endl;
std::cerr << "error: " << error_msg << std::endl;
return 1;
}

result.value();
});

bool help = cli_get_flag(parsed, arg_key_help);
if (help) {
std::cerr << cli_get_help_message(prog_name, cli);
return 1;
}

std::string model_name = cli_get_argument(parsed, key_model_name);
bool sp_decompositition = cli_get_flag(parsed, key_sp_decomposition);
bool dot = cli_get_flag(parsed, key_dot);
bool preprocessed_dot = cli_get_flag(parsed, key_preprocessed_dot);

auto handle_error = [](auto const &result) {
if (!result.has_value()) {
std::cerr << "error: " << result.error() << std::endl;
exit(1);
}

return result.value();
};

if (dot) {
ComputationGraph cg = handle_error(get_model_computation_graph(model_name));

std::cout << as_dot(cg) << std::endl;
return 0;
}

if (preprocessed_dot) {
ComputationGraph cg = handle_error(get_model_computation_graph(model_name));
std::string rendered =
render_preprocessed_computation_graph_for_sp_decomposition(cg);

std::cout << rendered << std::endl;
return 0;
}

nlohmann::json json_output;
if (sp_decompositition) {
JsonSPModelExport model_export =
handle_error(get_sp_model_export(model_name));

json_output = model_export;
} else {
ComputationGraph cg = handle_error(get_model_computation_graph(model_name));

json_output = to_v1(cg);
}
std::cout << json_output.dump(2) << std::endl;

return 0;
}
Loading