Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 25 additions & 1 deletion .proj.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ has-cuda-benchmarks = false
[targets.task-spec]
type = "lib"
has-cpu-only-tests = true
has-cpu-only-benchmarks = false
has-cpu-only-benchmarks = true
has-cuda-tests = false
has-cuda-benchmarks = false

Expand Down Expand Up @@ -216,6 +216,30 @@ budget = 4_700_000_000
name = "get_computation_graph_series_parallel_decomposition_on_inception_v3"
budget = 7_000_000_000

[[benchmarks.task-spec]]
name = "make_empty_dynamic_open_dataflow_graph"
budget = 90_000_000

[[benchmarks.task-spec]]
name = "dynamic_open_dataflow_graph_from_invocation_set"
budget = 4_200_000_000

[[benchmarks.task-spec]]
name = "dynamic_graph_get_id_for_invocation"
budget = 3_400_000

[[benchmarks.task-spec]]
name = "dynamic_graph_get_invocation_for_id"
budget = 2_000_000

[[benchmarks.task-spec]]
name = "dynamic_graph_get_id_for_value"
budget = 900_000

[[benchmarks.task-spec]]
name = "dynamic_graph_get_value_for_id"
budget = 600_000

# default_build_targets = [
# "utils",
# ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "pcg/computation_graph.dtg.h"
#include "pcg/optimizer_attrs.dtg.h"
#include "task-spec/dynamic_graph/dynamic_layer_guid_t.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"
#include "task-spec/dynamic_graph/dynamic_tensor_accessor.dtg.h"
#include "task-spec/dynamic_graph/dynamic_value_attrs.dtg.h"
#include "task-spec/global_device_id_t.dtg.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "kernels/device_handle_t.dtg.h"
#include "kernels/profiling_settings.dtg.h"
#include "pcg/optimizer_attrs.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"
#include "task-spec/global_device_id_t.dtg.h"

namespace FlexFlow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _FLEXFLOW_LIB_LOCAL_EXECUTION_INCLUDE_LOCAL_EXECUTION_TENSOR_ALLOCATION_H

#include "kernels/allocation.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"

namespace FlexFlow {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "realm-execution/per_device_op_state_backing.dtg.h"
#include "realm-execution/realm_context.h"
#include "realm-execution/tensor_instance_backing.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"

namespace FlexFlow {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "realm-execution/realm_context.h"
#include "realm-execution/tensor_instance_backing.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"

namespace FlexFlow {

Expand Down
2 changes: 1 addition & 1 deletion lib/realm-execution/include/realm-execution/pcg_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "realm-execution/per_device_op_state_backing.dtg.h"
#include "realm-execution/realm_context.h"
#include "realm-execution/tensor_instance_backing.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"
#include "task-spec/dynamic_graph/dynamic_tensor_accessor.dtg.h"
#include "task-spec/dynamic_graph/dynamic_value_attrs.dtg.h"
#include "task-spec/global_device_id_t.dtg.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ PerDeviceOpStateBacking perform_distributed_per_device_op_state_initialization(

std::map<DynamicNodeInvocation, DeviceSpecificPtr<PerDeviceOpState> *>
device_state_map;
for (DynamicNodeInvocation const &invocation : dg.invocations) {
for (DynamicNodeInvocation const &invocation :
get_dynamic_invocation_set(dg)) {
// Nodes mapped to multiple devices are always parallel operators and don't
// have any initialization to perform anyway
std::optional<global_device_id_t> device_id =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ TensorInstanceBacking perform_instance_allocation(
}
};

for (DynamicNodeInvocation const &invocation : g.invocations) {
for (DynamicNodeInvocation const &invocation :
get_dynamic_invocation_set(g)) {
for (DynamicValueAttrs const &input : values(invocation.inputs)) {
allocate(input);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/realm-execution/src/realm-execution/pcg_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ PCGInstance create_pcg_instance(

logit_grad_value =
transform(logit_grad_value, [&](DynamicValueAttrs const &lgv) {
for (DynamicNodeInvocation const &invocation : dg.invocations) {
for (DynamicNodeInvocation const &invocation :
get_dynamic_invocation_set(dg)) {
if (invocation.node_attrs.task_type != DynamicTaskType::LOSS) {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions lib/task-spec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ ff_add_library(
)

add_subdirectory(test)
add_subdirectory(benchmark)
10 changes: 10 additions & 0 deletions lib/task-spec/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ff_add_benchmark_executable(
NAME
task-spec-benchmarks
SRC_PATTERNS
src/*.cc
PRIVATE_INCLUDE
include/
DEPS
task-spec
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _FLEXFLOW_LIB_TASK_SPEC_BENCHMARK_INCLUDE_BENCHMARK_TASK_SPEC_CONTAINERS_TRANSFORM_H
#define _FLEXFLOW_LIB_TASK_SPEC_BENCHMARK_INCLUDE_BENCHMARK_TASK_SPEC_CONTAINERS_TRANSFORM_H

namespace FlexFlow {

void benchmark_make_empty_dynamic_open_dataflow_graph(bool dry_run);

void benchmark_dynamic_open_dataflow_graph_from_invocation_set(bool dry_run);

void benchmark_dynamic_graph_get_id_for_invocation(bool dry_run);

void benchmark_dynamic_graph_get_invocation_for_id(bool dry_run);

void benchmark_dynamic_graph_get_id_for_value(bool dry_run);

void benchmark_dynamic_graph_get_value_for_id(bool dry_run);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#include "benchmark/task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"
#include "op-attrs/ops/element_unary.h"
#include "task-spec/dynamic_graph/dynamic_node_invocation.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"
#include "task-spec/dynamic_graph/dynamic_value_attrs.dtg.h"
#include "utils/benchmark_utils/loop.h"
#include "utils/containers/at_idx.h"
#include "utils/containers/get_only.h"
#include "utils/containers/range.h"
#include "utils/containers/range_inclusive.h"
#include "utils/nonnegative_int/nonnegative_int.h"
#include <vector>

namespace FlexFlow {

static std::set<DynamicNodeInvocation> create_benchmark_invocation_set() {
auto mk_dynamic_value = [](size_t node_id,
TensorSlotName slot_name) -> DynamicValueAttrs {
return DynamicValueAttrs{
/*tensor_guid=*/dynamic_tensor_guid_t{parallel_tensor_guid_t{
KwargDataflowOutput{
Node{node_id},
slot_name,
},
}},
/*parallel_tensor_shape=*/std::nullopt,
/*create_grad=*/std::nullopt,
/*shard_coord=*/std::nullopt,
/*mapping=*/std::nullopt,
/*accessor=*/std::nullopt,
/*tensor_type=*/std::nullopt,
};
};

auto mk_slot = [](TensorSlotName slot_name) {
return DynamicTensorSlot{
/*slot_name=*/slot_name,
/*slot_tensor_role=*/std::nullopt,
/*task_shard=*/std::nullopt,
};
};

auto mk_node = [](size_t node_id) {
return DynamicNodeAttrs{
/*task_type=*/std::nullopt,
/*device_coord=*/std::nullopt,
/*mapping=*/std::nullopt,
/*op_attrs=*/
TrainingOperationAttrs{PCGOperatorAttrs{make_relu_attrs()}},
/*layer_guid=*/
dynamic_layer_guid_t{parallel_layer_guid_t{Node{node_id}}},
/*per_device_op_state=*/std::nullopt,
};
};

constexpr int num_invocations = 1000;
std::vector<DynamicValueAttrs> values =
transform(range_inclusive(num_invocations), [&](int idx) {
return mk_dynamic_value(idx, TensorSlotName::OUTPUT);
});

std::set<DynamicNodeInvocation> result =
set_of(transform(range(num_invocations), [&](int idx) {
return DynamicNodeInvocation{
/*inputs=*/std::map<DynamicTensorSlot, DynamicValueAttrs>{
{
mk_slot(TensorSlotName::INPUT),
values.at(idx),
},
},
/*node_attrs=*/mk_node(idx),
/*outputs=*/
std::map<DynamicTensorSlot, DynamicValueAttrs>{
{
mk_slot(TensorSlotName::OUTPUT),
values.at(idx + 1),
},
},
};
}));
return result;
}

void benchmark_make_empty_dynamic_open_dataflow_graph(bool dry_run) {
LOOP(10000, dry_run) {
make_empty_dynamic_open_dataflow_graph();
}
}

void benchmark_dynamic_open_dataflow_graph_from_invocation_set(bool dry_run) {
std::set<DynamicNodeInvocation> invocation_set =
create_benchmark_invocation_set();
LOOP(10, dry_run) {
dynamic_open_dataflow_graph_from_invocation_set(invocation_set);
}
}

void benchmark_dynamic_graph_get_id_for_invocation(bool dry_run) {
std::set<DynamicNodeInvocation> invocation_set =
create_benchmark_invocation_set();
DynamicOpenDataflowGraph dg =
dynamic_open_dataflow_graph_from_invocation_set(invocation_set);
DynamicNodeInvocation invocation =
at_idx(invocation_set, nonnegative_int{invocation_set.size() / 2});
LOOP(1000, dry_run) {
dynamic_graph_get_id_for_invocation(dg, invocation);
}
}

void benchmark_dynamic_graph_get_invocation_for_id(bool dry_run) {
std::set<DynamicNodeInvocation> invocation_set =
create_benchmark_invocation_set();
DynamicOpenDataflowGraph dg =
dynamic_open_dataflow_graph_from_invocation_set(invocation_set);
DynamicNodeInvocation invocation =
at_idx(invocation_set, nonnegative_int{invocation_set.size() / 2});
dynamic_invocation_id_t id =
dynamic_graph_get_id_for_invocation(dg, invocation);
LOOP(1000, dry_run) {
dynamic_graph_get_invocation_for_id(dg, id);
}
}

void benchmark_dynamic_graph_get_id_for_value(bool dry_run) {
std::set<DynamicNodeInvocation> invocation_set =
create_benchmark_invocation_set();
DynamicOpenDataflowGraph dg =
dynamic_open_dataflow_graph_from_invocation_set(invocation_set);
DynamicNodeInvocation invocation =
at_idx(invocation_set, nonnegative_int{invocation_set.size() / 2});
DynamicValueAttrs value = get_only(invocation.outputs).second;
LOOP(1000, dry_run) {
dynamic_graph_get_id_for_value(dg, value);
}
}

void benchmark_dynamic_graph_get_value_for_id(bool dry_run) {
std::set<DynamicNodeInvocation> invocation_set =
create_benchmark_invocation_set();
DynamicOpenDataflowGraph dg =
dynamic_open_dataflow_graph_from_invocation_set(invocation_set);
DynamicNodeInvocation invocation =
at_idx(invocation_set, nonnegative_int{invocation_set.size() / 2});
DynamicValueAttrs value = get_only(invocation.outputs).second;
dynamic_value_id_t id = dynamic_graph_get_id_for_value(dg, value);
LOOP(1000, dry_run) {
dynamic_graph_get_value_for_id(dg, id);
}
}

} // namespace FlexFlow
37 changes: 37 additions & 0 deletions lib/task-spec/benchmark/src/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "benchmark/task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"
#include "utils/benchmark_utils/benchmark_main.h"
#include <map>
#include <string>

using namespace ::FlexFlow;

int main(int argc, char **argv) {
std::map<std::string, std::function<void(bool)>> benchmarks = {
{
"make_empty_dynamic_open_dataflow_graph",
benchmark_make_empty_dynamic_open_dataflow_graph,
},
{
"dynamic_open_dataflow_graph_from_invocation_set",
benchmark_dynamic_open_dataflow_graph_from_invocation_set,
},
{
"dynamic_graph_get_id_for_invocation",
benchmark_dynamic_graph_get_id_for_invocation,
},
{
"dynamic_graph_get_invocation_for_id",
benchmark_dynamic_graph_get_invocation_for_id,
},
{
"dynamic_graph_get_id_for_value",
benchmark_dynamic_graph_get_id_for_value,
},
{
"dynamic_graph_get_value_for_id",
benchmark_dynamic_graph_get_value_for_id,
},
};

benchmark_main(argc, argv, benchmarks);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "task-spec/dynamic_graph/dynamic_node_attrs.dtg.h"
#include "task-spec/dynamic_graph/dynamic_node_invocation.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.dtg.h"
#include "task-spec/dynamic_graph/dynamic_open_dataflow_graph.h"
#include "task-spec/dynamic_graph/dynamic_slot_site.dtg.h"
#include "task-spec/dynamic_graph/dynamic_value_copy_info.dtg.h"
#include "task-spec/dynamic_graph/internal_dynamic_slot_site.dtg.h"
Expand Down

This file was deleted.

Loading
Loading