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

Local execution e2e training #1472

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions lib/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ file(GLOB_RECURSE SRC
LIST_DIRECTORIES False
src/*.cc
src/cuda/cuda_helper.cu
src/cuda/loss_function_kernels.cu
src/cuda/optimizer_kernels.cu
src/cuda/ops/*.cu
)

Expand Down
20 changes: 14 additions & 6 deletions lib/kernels/include/kernels/array_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ namespace FlexFlow {
struct ArrayShape {
public:
ArrayShape() = delete;
ArrayShape(size_t *dims, size_t num_dims);
ArrayShape(TensorShape const &shape);
ArrayShape(std::vector<std::size_t> const &);
explicit ArrayShape(size_t *dims, size_t num_dims);
explicit ArrayShape(TensorShape const &shape);
explicit ArrayShape(std::vector<std::size_t> const &);
explicit ArrayShape(LegionTensorDims const &);

/**
* @brief Alias of ArrayShape::num_elements for compatibility with
Expand All @@ -42,9 +43,16 @@ struct ArrayShape {
std::optional<std::size_t> at_maybe(legion_dim_t) const;
std::optional<std::size_t> at_maybe(ff_dim_t) const;

ArrayShape
sub_shape(std::optional<std::variant<ff_dim_t, legion_dim_t>> start,
std::optional<std::variant<ff_dim_t, legion_dim_t>> end) const;
ArrayShape sub_shape(legion_dim_t start, ff_dim_t end) const;

ArrayShape sub_shape(std::optional<ff_dim_t> start,
std::optional<ff_dim_t> end) const;

ArrayShape sub_shape(std::optional<legion_dim_t> start,
std::optional<legion_dim_t> end) const;

bool operator==(ArrayShape const &) const;
bool operator!=(ArrayShape const &) const;

public:
LegionTensorDims dims;
Expand Down
3 changes: 3 additions & 0 deletions lib/kernels/include/kernels/legion_dim.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ legion_dim_t add_to_legion_dim(legion_dim_t legion_dim, int value);

legion_dim_t legion_dim_from_ff_dim(ff_dim_t, int num_dimensions);

std::optional<legion_dim_t> legion_dim_from_ff_dim(std::optional<ff_dim_t>,
int num_dimensions);

template <typename T>
using LegionOrdered = DimOrdered<legion_dim_t, T>;

Expand Down
9 changes: 7 additions & 2 deletions lib/kernels/include/kernels/optimizer_kernels.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef _FLEXFLOW_KERNELS_INCLUDE_KERNELS_OPTIMIZER_KERNELS_H
#define _FLEXFLOW_KERNELS_INCLUDE_KERNELS_OPTIMIZER_KERNELS_H

#include "device.h"
#include "kernels/device.h"
#include "kernels/ff_handle.h"

namespace FlexFlow {

Expand All @@ -20,7 +21,8 @@ void sgd_nccl_update_task_gpu(ffStream_t,
float lr,
float momentum,
bool nesterov,
float weight_decay PerDeviceFFHandle const &,
float weight_decay,
PerDeviceFFHandle const &,
float const *weight_grad_ptr,
size_t size,
float *weight_ptr,
Expand All @@ -32,6 +34,8 @@ void adam_ps_update_task_gpu(ffStream_t,
float beta2,
float weight_decay,
float epsilon,
size_t size,
int num_replicas,
float const *weight_grad_ptr,
float *adam_m_ptr,
float *adam_v_ptr,
Expand All @@ -43,6 +47,7 @@ void adam_nccl_update_task_gpu(ffStream_t,
float beta2,
float weight_decay,
float epsilon,
size_t size,
PerDeviceFFHandle const &,
float const *weight_grad_ptr,
float *adam_m_ptr,
Expand Down
2 changes: 1 addition & 1 deletion lib/kernels/src/allocation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void Allocator::deallocate(void *ptr) {
GenericTensorAccessorW
Allocator::allocate_tensor(TensorShape const &tensor_shape) {
void *ptr = this->allocate(get_size_in_bytes(tensor_shape));
return {tensor_shape.data_type, tensor_shape, ptr};
return {tensor_shape.data_type, ArrayShape{tensor_shape}, ptr};
}

} // namespace FlexFlow
33 changes: 29 additions & 4 deletions lib/kernels/src/array_shape.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "kernels/array_shape.h"
#include "op-attrs/dim_ordered/slice.h"
#include "utils/containers/product.h"

namespace FlexFlow {
Expand All @@ -19,6 +20,9 @@ ArrayShape::ArrayShape(TensorShape const &shape)
ArrayShape::ArrayShape(std::vector<std::size_t> const &input_dims)
: dims(input_dims) {}

ArrayShape::ArrayShape(LegionTensorDims const &legion_tensor_dims)
: dims(legion_tensor_dims) {}

std::size_t ArrayShape::get_volume() const {
return this->num_elements();
}
Expand Down Expand Up @@ -50,10 +54,23 @@ std::size_t ArrayShape::at(ff_dim_t idx) const {
return dims.at(legion_dim_from_ff_dim(idx, this->num_dims()));
}

ArrayShape ArrayShape::sub_shape(
std::optional<std::variant<ff_dim_t, legion_dim_t>> start,
std::optional<std::variant<ff_dim_t, legion_dim_t>> end) const {
NOT_IMPLEMENTED();
ArrayShape ArrayShape::sub_shape(legion_dim_t start, ff_dim_t end) const {
legion_dim_t legion_end = legion_dim_from_ff_dim(end, num_dims());
return this->sub_shape(start, legion_end);
}

ArrayShape ArrayShape::sub_shape(std::optional<ff_dim_t> start,
std::optional<ff_dim_t> end) const {
std::optional<legion_dim_t> legion_start =
legion_dim_from_ff_dim(start, num_dims());
std::optional<legion_dim_t> legion_end =
legion_dim_from_ff_dim(end, num_dims());
return this->sub_shape(legion_start, legion_end);
}

ArrayShape ArrayShape::sub_shape(std::optional<legion_dim_t> start,
std::optional<legion_dim_t> end) const {
return ArrayShape{slice(this->dims, start, end)};
}

std::optional<std::size_t> ArrayShape::at_maybe(legion_dim_t index) const {
Expand All @@ -77,6 +94,14 @@ TensorShape get_tensor_shape(ArrayShape const &shape, DataType dtype) {
dtype};
}

bool ArrayShape::operator==(ArrayShape const &other) const {
return this->dims == other.dims;
}

bool ArrayShape::operator!=(ArrayShape const &other) const {
return this->dims != other.dims;
}

std::string format_as(ArrayShape const &x) {
std::ostringstream oss;
oss << "<ArrayShape";
Expand Down
4 changes: 2 additions & 2 deletions lib/kernels/src/cuda/cuda_helper.cu
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ cudaError_t get_legion_stream(cudaStream_t *stream) {
#error "Unknown device, please make sure if CUDA is enabled"
#endif

__global__ void scale_kernel(float *ptr, coord_t size, float a, float b) {
__global__ void scale_kernel(float *ptr, size_t size, float a, float b) {
CUDA_KERNEL_LOOP(i, size) {
ptr[i] = (b - a) * ptr[i] + a;
}
}

__global__ void ones_kernel(float *ptr, coord_t size) {
__global__ void ones_kernel(float *ptr, size_t size) {
CUDA_KERNEL_LOOP(i, size) {
ptr[i] = 1.0f;
}
Expand Down
Loading