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

Realm backend #1592

Draft
wants to merge 69 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
6adb290
temporary weight adjust index
reyna-abhyankar Aug 25, 2024
61697c2
Loss function
reyna-abhyankar Aug 27, 2024
b56c046
Add cuda test for loss function
reyna-abhyankar Aug 27, 2024
f75a3d4
Format
reyna-abhyankar Aug 27, 2024
f74711f
Refactor and build optimizer kernels, op
reyna-abhyankar Aug 27, 2024
40c6252
Finish optimizer local backing
reyna-abhyankar Aug 27, 2024
ad9b9ea
Format
reyna-abhyankar Aug 27, 2024
1ddfade
E2E update test
reyna-abhyankar Aug 27, 2024
dde9496
Format
reyna-abhyankar Aug 27, 2024
59635d8
Small fixes
reyna-abhyankar Sep 11, 2024
103ef07
Format
reyna-abhyankar Sep 11, 2024
f48f9ff
Fix test and small issues
reyna-abhyankar Sep 18, 2024
189c9c8
Format
reyna-abhyankar Sep 18, 2024
d93f464
Merge branch 'repo-refactor' into local-e2e-training
reyna-abhyankar Oct 1, 2024
b5647c8
Pass tests after merge
reyna-abhyankar Oct 1, 2024
f5ff91e
Fix input/weight differentiation
reyna-abhyankar Oct 1, 2024
7470e71
Fix signature to use unified rep
reyna-abhyankar Oct 1, 2024
deece1b
Fix model training instance abstraction
reyna-abhyankar Oct 1, 2024
1d3cc94
Change subcase test name
reyna-abhyankar Oct 1, 2024
3cf5d08
Quick fixes
reyna-abhyankar Oct 16, 2024
79ef4c9
Refactor training backing and instance
reyna-abhyankar Oct 22, 2024
a73b1c3
Expose op folders publicly
reyna-abhyankar Nov 13, 2024
c6fed29
Add tensor type, operate over reduced tensor
reyna-abhyankar Nov 13, 2024
0cdfb1a
Fixes
reyna-abhyankar Jan 7, 2025
9d252b3
Remove tensor lower
reyna-abhyankar Jan 15, 2025
895c117
Add tensor and task lowering scheme
reyna-abhyankar Jan 17, 2025
66d61eb
feat: add realm-backend subdir
chenzhuofu Jan 21, 2025
8d0cfec
Merge branch 'local-e2e-training' of github.com:reyna-abhyankar/FlexF…
chenzhuofu Jan 21, 2025
411017d
Build local exec
reyna-abhyankar Jan 22, 2025
759abdd
Merge branch 'local-e2e-training' of github.com:reyna-abhyankar/FlexF…
chenzhuofu Jan 22, 2025
bcd1408
chore: duplicate some files from local-execution
chenzhuofu Jan 22, 2025
5e11568
Merge branch 'master' of github.com:flexflow/flexflow-train into real…
chenzhuofu Jan 28, 2025
1c55cf7
Merge branch 'master' of github.com:flexflow/flexflow-train into real…
chenzhuofu Jan 28, 2025
b9144ad
chore: update legion
chenzhuofu Jan 30, 2025
66647a2
feat: add legion related code
chenzhuofu Jan 30, 2025
0128abb
Disaggregate local backend
reyna-abhyankar Feb 1, 2025
277f8c2
Update task binding interface and cost estimator
reyna-abhyankar Feb 1, 2025
377c6aa
Merge master into local execution
reyna-abhyankar Feb 4, 2025
6f689a4
feat: add Future wrapper for func result
chenzhuofu Feb 5, 2025
fe2bc21
feat: add realm-backend draft impl
chenzhuofu Feb 5, 2025
8efaec7
Build
reyna-abhyankar Feb 6, 2025
1dc1398
Format
reyna-abhyankar Feb 6, 2025
17ad5c8
Split task spec files
reyna-abhyankar Feb 6, 2025
639c2c1
Delete outdated sim environment file
reyna-abhyankar Feb 6, 2025
c408ebb
Merge branch 'local-e2e-training' of github.com:reyna-abhyankar/FlexF…
chenzhuofu Feb 8, 2025
a697044
Finish API
reyna-abhyankar Feb 13, 2025
187a8d5
Add tests for allocated and unallocated
reyna-abhyankar Feb 13, 2025
a0f8113
Fix nonnegative
reyna-abhyankar Feb 13, 2025
b1eab94
Format
reyna-abhyankar Feb 13, 2025
b532c50
Pass allocated-unallocated tests
reyna-abhyankar Feb 13, 2025
f28e5c2
Update task registry tests
reyna-abhyankar Feb 13, 2025
7887183
Merge branch 'local-e2e-training' of github.com:reyna-abhyankar/FlexF…
chenzhuofu Feb 16, 2025
9c16d76
feat: intial implementation of realm-backend
chenzhuofu Feb 19, 2025
89752fa
Move local tensor backing to dtgen
reyna-abhyankar Feb 22, 2025
aef8ad5
Remove lowered tensor source
reyna-abhyankar Feb 22, 2025
f0a4285
Loss and update tests
reyna-abhyankar Feb 24, 2025
9047edc
Merge master
reyna-abhyankar Feb 24, 2025
350babf
Passing tests after merge issues
reyna-abhyankar Feb 24, 2025
aef7c6e
Pass gpu tests
reyna-abhyankar Feb 25, 2025
6c84fb3
chore: fix typo
chenzhuofu Feb 26, 2025
d6aa7ad
chore: update realm allocator impl
chenzhuofu Feb 27, 2025
419cca8
chore: eliminate std::optional<float>
chenzhuofu Mar 3, 2025
2c0b573
feat: buildable realm-backend
chenzhuofu Mar 5, 2025
ebe06cf
Merge commit 'aef8ad58196f7b7f724fc7f0a1a65af24ee12acd' of github.com…
chenzhuofu Mar 5, 2025
062825e
chore: Move realm tensor backing to dtgen
chenzhuofu Mar 5, 2025
d82fa2a
Merge commit '350babf3584c3d99e76e4dc0f72a658aa0222afc' of github.com…
chenzhuofu Mar 5, 2025
7c53bb3
chore: minor
chenzhuofu Mar 5, 2025
403ec78
Merge commit 'aef7c6e3c3087f15b4c90792148f170da84f6f7c' of github.com…
chenzhuofu Mar 5, 2025
bf57d1d
chore: remove deprecated file
chenzhuofu Mar 5, 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
Prev Previous commit
Next Next commit
feat: intial implementation of realm-backend
  • Loading branch information
chenzhuofu committed Feb 19, 2025
commit 9c16d7682543092fdfa67dc104066779fc32442b
30 changes: 30 additions & 0 deletions lib/realm-backend/include/realm-backend/allocated_tensors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef _FLEXFLOW_LOCAL_EXECUTION_ALLOCATED_TENSORS_H
#define _FLEXFLOW_LOCAL_EXECUTION_ALLOCATED_TENSORS_H

#include "realm-backend/allocated_tensors.dtg.h"
#include "pcg/computation_graph.h"

namespace FlexFlow {

bool are_allocated_forward_tensors_valid(
AllocatedTensors const &,
std::unordered_map<tensor_guid_t, TensorAttrs> const &);
bool are_allocated_gradient_tensors_valid(
AllocatedTensors const &,
std::unordered_map<tensor_guid_t, TensorAttrs> const &);
bool are_allocated_optimizer_tensors_valid(
AllocatedTensors const &,
std::unordered_map<tensor_guid_t, TensorAttrs> const &);

bool are_allocated_tensors_valid(
AllocatedTensors const &,
std::unordered_map<tensor_guid_t, TensorAttrs> const &);

bool is_allocated_tensor_backing_valid(
TensorTypeVariant const &,
std::unordered_map<TensorTypeVariant, GenericTensorAccessorW> const &,
ArrayShape const &);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace = "FlexFlow"
name = "AllocatedTensors"
features = [
"eq",
"fmt",
"hash",
]

includes = [
"task-spec/tensor_type_t.dtg.h",
"kernels/accessor.h",
"realm-backend/realm_allocator.h"
]

src_includes = [
"utils/hash/unordered_map.h",
"utils/fmt/unordered_map.h",
"utils/hash/vector.h",
"utils/fmt/vector.h"
]

[[fields]]
name = "tensor_type_backings"
type = "std::unordered_map<::FlexFlow::TensorTypeVariant, std::pair<::FlexFlow::RealmRegion,::FlexFlow::TensorShape>>"

[[fields]]
name = "gradient_mapping"
type = "std::unordered_map<::FlexFlow::tensor_guid_t, ::FlexFlow::gradient_tensor_t>"

[[fields]]
name = "optimizer_mapping"
type = "std::unordered_map<::FlexFlow::tensor_guid_t, std::vector<::FlexFlow::optimizer_tensor_t>>"
19 changes: 8 additions & 11 deletions lib/realm-backend/include/realm-backend/model_training_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,23 @@ using PerLayerElapsedTime =
std::unordered_map<layer_guid_t, std::optional<float>>;

struct ModelTrainingInstance {
ModelTrainingInstance(ComputationGraph const &,
RuntimeArgConfig const &,
LossAttrs const &,
ModelTrainingInstance(RealmTrainingBacking const &,
tensor_guid_t const &logit_tensor,
loss_tensor_t const &label_tensor,
TensorShape const &label_tensor_shape,
LossAttrs const &,
OptimizerAttrs const &);

void execute_init();
PerLayerElapsedTime execute_forward();
PerLayerElapsedTime execute_backward();
void execute_update();

ComputationGraph computation_graph;
RealmTrainingBacking training_backing;
LossAttrs loss_attrs;
tensor_guid_t logit_tensor;
loss_tensor_t label_tensor;
LossAttrs loss_attrs;
OptimizerAttrs optimizer_attrs;
};

PerLayerElapsedTime forward(ModelTrainingInstance &);
PerLayerElapsedTime backward(ModelTrainingInstance &);
void update(ModelTrainingInstance &);

} // namespace FlexFlow

#endif
34 changes: 17 additions & 17 deletions lib/realm-backend/include/realm-backend/realm_args_backing.h
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
#ifndef _FLEXFLOW_REALM_BACKEND_REALM_ARGS_BACKING_H
#define _FLEXFLOW_REALM_BACKEND_REALM_ARGS_BACKING_H

#include "local-execution/op_task_invocation.h"
#include "local-execution/per_device_op_state.h"
#include "local-execution/runtime_arg_config.h"
#include "local-execution/task_invocation.dtg.h"
#include "pcg/computation_graph.h"
#include "pcg/layer_guid_t.dtg.h"
#include "realm-backend/realm_task_argument_accessor.h"
#include "realm-backend/task_result.h"
#include "task-spec/op_task_invocation.h"
#include "task-spec/per_device_op_state.h"
#include "task-spec/runtime_arg_config.h"
#include "task-spec/task_invocation.dtg.h"

namespace FlexFlow {

struct RealmArgsBacking {
RealmArgsBacking(RuntimeArgConfig const &);

public:
void add_per_device_op_state(layer_guid_t const &,
Future<DeviceSpecificDeviceStates> &&);

ArgSlotsBacking construct_arg_slots_backing(TaskBinding const &) const;

ConcreteArgSpec lower_to_concrete_arg_spec(RuntimeArgRefSpec const &) const;
ConcreteArgSpec lower_to_concrete_arg_spec(OpArgRefSpec const &,
ComputationGraph const &,
layer_guid_t const &) const;
RealmArgsBacking(RuntimeArgConfig const &,
std::unordered_map<layer_guid_t, DeviceSpecificDeviceStates> const &);

public:
// arguments
RuntimeArgConfig runtime_arg_config;
std::unordered_map<layer_guid_t, DeviceSpecificDeviceStates>
per_device_op_states;
RuntimeArgConfig runtime_arg_config;
};

RealmArgsBacking
make_args_backing_with_empty_device_states(RuntimeArgConfig const &);

std::optional<DeviceSpecificDeviceStates>
get_per_device_op_state_if_exists(RealmArgsBacking const &,
layer_guid_t const &);

ArgSlotsBacking construct_arg_slots_backing(TaskBinding const &,
RuntimeArgConfig const &);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef _FLEXFLOW_REALM_BACKEND_REALM_TASK_ARGUMENT_ACCESSOR_H
#define _FLEXFLOW_REALM_BACKEND_REALM_TASK_ARGUMENT_ACCESSOR_H

#include "local-execution/slot_tensor_type_id.dtg.h"
#include "local-execution/task_argument_accessor.h"
#include "realm-backend/realm_allocator.h"
#include "task-spec/slot_tensor_type_id.dtg.h"
#include <unordered_map>
#include <variant>

Expand All @@ -14,7 +15,7 @@ using TensorSlotsBacking = std::unordered_map<
using ArgSlotsBacking = std::unordered_map<slot_id_t, ConcreteArgSpec>;

struct RealmTaskArgumentAccessor : public ITaskArgumentAccessor {
RealmTaskArgumentAccessor(Allocator const &allocator,
RealmTaskArgumentAccessor(RealmAllocator const &allocator,
TensorSlotsBacking const &tensor_slots_backing,
ArgSlotsBacking const &arg_slots_backing);

Expand All @@ -23,18 +24,18 @@ struct RealmTaskArgumentAccessor : public ITaskArgumentAccessor {

ConcreteArgSpec const &get_concrete_arg(slot_id_t) const override;

GenericTensorAccessor get_tensor(slot_id_t slot,
Permissions priv,
GenericTensorAccessor get_tensor(slot_id_t slot, Permissions priv,
TensorType tensor_type) const override;
VariadicGenericTensorAccessor get_variadic_tensor(
slot_id_t slot, Permissions priv, TensorType tensor_type) const override;
VariadicGenericTensorAccessor
get_variadic_tensor(slot_id_t slot, Permissions priv,
TensorType tensor_type) const override;

Allocator get_allocator() const override;

size_t get_device_idx() const override;

private:
Allocator allocator;
RealmAllocator allocator;
TensorSlotsBacking tensor_slots_backing;
ArgSlotsBacking arg_slots_backing;
};
Expand All @@ -45,8 +46,8 @@ using TensorSlotsBackingWithoutAddresses = std::unordered_map<
std::vector<std::pair<ArrayShape, DataType>>>>;

TensorSlotsBackingWithoutAddresses
get_slots_backing_without_tensor_allocation_addresses(
TensorSlotsBacking const &);
get_slots_backing_without_tensor_allocation_addresses(
TensorSlotsBacking const &);

CHECK_RC_COPY_VIRTUAL_COMPLIANT(RealmTaskArgumentAccessor);

Expand Down
82 changes: 47 additions & 35 deletions lib/realm-backend/include/realm-backend/realm_tensor_backing.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,70 @@
#define _FLEXFLOW_REALM_BACKEND_REALM_TENSOR_BACKING_H

#include "kernels/accessor.h"
#include "realm-backend/realm_task_argument_accessor.h"
#include "realm-backend/realm_allocator.h"
#include "local-execution/task_invocation.dtg.h"
#include "local-execution/tensor_role.dtg.h"
#include "local-execution/lowered_tensor_t.dtg.h"
#include "local-execution/gradient_tensor_source.h"
#include "local-execution/loss_tensor_source.h"
#include "local-execution/lowered_tensor_source.h"
#include "local-execution/optimizer_tensor_t.dtg.h"
#include "local-execution/loss_tensor_t.dtg.h"
#include "local-execution/optimizer_tensor_source.h"
#include "pcg/computation_graph.dtg.h"
#include "pcg/tensor_guid_t.dtg.h"
#include "pcg/layer_guid_t.dtg.h"
#include "pcg/optimizer_attrs.dtg.h"
#include "realm-backend/allocated_tensors.dtg.h"
#include "realm-backend/realm_allocator.h"
#include "realm-backend/realm_task_argument_accessor.h"
#include "realm-backend/unallocated_tensors.dtg.h"
#include "task-spec/lowered_tensor_t.dtg.h"
#include "task-spec/task_invocation.dtg.h"
#include "task-spec/tensor_role.dtg.h"

namespace FlexFlow {

using TensorRegionMap =
std::unordered_map<lowered_tensor_t, RealmRegion>;
using TensorShapeMap =
std::unordered_map<lowered_tensor_t, TensorShape>;
using TensorBackingMap = std::unordered_map<lowered_tensor_t, std::pair<RealmRegion, TensorShape>>;

struct RealmTensorBacking {
RealmTensorBacking();
RealmTensorBacking(AllocatedTensors const &, UnallocatedTensors const &,
RealmAllocator const &);

public:
void allocate_layer_tensors(layer_guid_t const &,
ComputationGraph const &,
RealmAllocator &);
void allocate_tensors_by_role(TensorRole const &,
layer_guid_t const &,
ComputationGraph const &,
RealmAllocator &);
void allocate_optimizer_tensors(tensor_guid_t const &,
std::vector<optimizer_tensor_t> const &,
RealmAllocator &);
TensorSlotsBacking
construct_tensor_slots_backing(TaskBinding const &) const;

GenericTensorAccessorW const &
get_tensor_backing(lowered_tensor_t const &) const;

bool is_tensor_allocated(lowered_tensor_t const &) const;
GenericTensorAccessorW get_tensor(TensorTypeVariant const &) const;

public:
// tensors
TensorRegionMap tensor_regions;
TensorShapeMap tensor_shapes;
TensorBackingMap tensor_backings;

std::unordered_map<tensor_guid_t, lowered_tensor_t> tensor_lowering_mapping;
std::unordered_map<tensor_guid_t, lowered_tensor_t> gradient_tensor_lowering_mapping;
std::unordered_map<optimizer_tensor_t, lowered_tensor_t> optimizer_tensor_lowering_mapping;
std::unordered_map<loss_tensor_t, lowered_tensor_t> loss_tensor_lowering_mapping;
std::unordered_map<gradient_tensor_t, lowered_tensor_t>
gradient_tensor_lowering_mapping;
std::unordered_map<optimizer_tensor_t, lowered_tensor_t>
optimizer_tensor_lowering_mapping;
std::unordered_map<loss_tensor_t, lowered_tensor_t>
loss_tensor_lowering_mapping;

std::unordered_map<tensor_guid_t, gradient_tensor_t> tensor_gradient_mapping;
std::unordered_map<tensor_guid_t, std::vector<optimizer_tensor_t>>
tensor_optimizer_mapping;

RealmAllocator allocator;

private:
lowered_tensor_t insert_tensor(TensorTypeVariant const &);
LoweredTensorSource lowered_tensor_source;
};

GenericTensorAccessorW wrappup_tensor_accessor(std::pair<RealmRegion, TensorShape> const &);

UnallocatedTensors generate_unallocated_tensors(
AllocatedTensors const &,
std::unordered_map<tensor_guid_t, TensorAttrs> const &,
GradientTensorSource &);

UnallocatedTensors generate_unallocated_tensors_with_optimizer(
AllocatedTensors const &,
std::unordered_map<tensor_guid_t, TensorAttrs> const &,
GradientTensorSource &, OptimizerTensorSource &, OptimizerAttrs const &);

TensorSlotsBacking construct_tensor_slots_backing(RealmTensorBacking const &,
TaskBinding const &);

} // namespace FlexFlow

#endif
Loading
Loading