-
Notifications
You must be signed in to change notification settings - Fork 826
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
LogicalSliceAssign support full slice sbp #8344
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
92e2a18
feat(SliceOp): slice ops support 2d sbp
wyg1997 deaa871
Merge branch 'master' into feat-slice_ops_support_2d_sbp
wyg1997 f0ee0ed
fix(SliceOp): fix [B, P] 2d sbp bug
wyg1997 1572353
refine error message
wyg1997 1e11873
Merge remote-tracking branch 'origin/feat-slice_ops_support_2d_sbp' i…
wyg1997 36c2093
fix bug in parallel_num == 1
wyg1997 c3f617b
add comment
wyg1997 64cb1c9
add warning and format
wyg1997 cca0ad9
add NOLINT for boxing check
wyg1997 61ebf3e
Merge branch 'master' into feat-slice_ops_support_2d_sbp
wyg1997 5a56356
Merge branch 'master' into feat-slice_ops_support_2d_sbp
mergify[bot] 38eb61c
Merge branch 'master' into feat-slice_ops_support_2d_sbp
wyg1997 d724598
Merge branch 'master' into feat-slice_ops_support_2d_sbp
hjchen2 0afbab7
Merge branch 'master' into feat-slice_ops_support_2d_sbp
wyg1997 f138436
feat(LogicalSliceOps): support all nd_sbp
wyg1997 266ebb3
feat(LogicalSlice): support nd_sbp
wyg1997 e8ca7d0
Merge remote-tracking branch 'origin/master' into feat-slice_ops_supp…
wyg1997 797a6ca
add error message
wyg1997 4de5066
fix(AutoTest): fix auto_test bug in module.parameter pass
wyg1997 3787d87
auto format by CI
oneflow-ci-bot 44e7230
fix(LogicalSliceAssign): skip test when 1n1d
wyg1997 cbda49b
Merge branch 'feat-slice_ops_support_2d_sbp' of github.com:Oneflow-In…
wyg1997 4f9f1f3
Merge remote-tracking branch 'origin/feat-slice_ops_support_2d_sbp' i…
wyg1997 63abe10
Merge branch 'master' into feat-logical_slice_ops_support_all_sbp
wyg1997 8284bb3
fix SliceParams memset error
wyg1997 e20e423
Merge branch 'master' into feat-logical_slice_ops_support_all_sbp
mergify[bot] 97f356f
remove memset
wyg1997 9b2c4ff
add CHECK_JUST
wyg1997 9f52bcb
fix(*): make sure split_axis >= 0 or equal to SPLIT_AXIS_FOR_NON_SPLIT
wyg1997 8d0b8d0
Merge branch 'master' into feat-logical_slice_ops_support_all_sbp
mergify[bot] 85a2f60
Merge branch 'master' into feat-logical_slice_ops_support_all_sbp
wyg1997 d343539
remove memset
wyg1997 f5a6b68
fix spilit_info.axis bug
wyg1997 75e0e1b
feat(LogicalSliceOps): support grad
wyg1997 750b4af
add logical_slice gradient_funcs
wyg1997 1b964e8
Merge remote-tracking branch 'origin/master' into feat-logical_slice_…
wyg1997 2a4cd88
feat(LogicalSliceAssign): LogicalSliceAssign support full slice sbp
wyg1997 677059d
Merge remote-tracking branch 'origin/master' into feat-logical_slice_…
wyg1997 4d97ac1
Merge branch 'master' into feat-logical_slice_assign_support_full_slice
wyg1997 4115a75
Merge branch 'master' into feat-logical_slice_assign_support_full_slice
wyg1997 4e339ee
Merge branch 'master' into feat-logical_slice_assign_support_full_slice
wyg1997 aa0a5c5
auto format by CI
oneflow-ci-bot a209d19
test(LogicalSlice): fix logical_slice dims
wyg1997 4570728
Merge branch 'master' into feat-logical_slice_assign_support_full_slice
wyg1997 1188cc0
Merge branch 'master' into feat-logical_slice_assign_support_full_slice
wyg1997 1d69560
Merge branch 'master' into feat-logical_slice_assign_support_full_slice
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,30 +329,6 @@ DEFINE_STATIC_SWITCH_FUNC( | |
)); | ||
#undef MAKE_WRITE_SLICE_SWITCH_ENTRY | ||
|
||
std::shared_ptr<user_op::OpKernelCache> CreateSliceCache(user_op::KernelCacheContext* ctx, | ||
const std::string& large_tensor_name) { | ||
SliceContext slice_ctx; | ||
if (ctx->parallel_ctx().parallel_num() == 1) { | ||
// split_axis == SPLIT_AXIS_FOR_NON_SPLIT means the sbp attribute is not 'split' | ||
CHECK_JUST(slice_ctx.PushSplitInfo(SPLIT_AXIS_FOR_NON_SPLIT, 0, 0, 0)); | ||
} else { | ||
const NdSbp& in_nd_sbp = ctx->NdSbp4ArgNameAndIndex(large_tensor_name, 0); | ||
const Shape& parallel_hierarchy = *ctx->parallel_desc().hierarchy(); | ||
const Shape& logical_shape = | ||
ctx->LogicalTensorDesc4ArgNameAndIndex(large_tensor_name, 0)->shape(); | ||
const int64_t parallel_id = ctx->parallel_ctx().parallel_id(); | ||
const TensorSliceView& slice_view = | ||
GetTensorSliceView4ParallelId(parallel_hierarchy, in_nd_sbp, logical_shape, parallel_id); | ||
for (int i = 0; i < logical_shape.NumAxes(); ++i) { | ||
const Range& range = slice_view.At(i); | ||
if (range.begin() != 0 || range.end() != logical_shape.At(i)) { | ||
CHECK_JUST(slice_ctx.PushSplitInfo(i, range.begin(), range.end(), logical_shape.At(i))); | ||
} | ||
} | ||
} | ||
return std::make_shared<OpKernelCacheWrapper<SliceContext>>(slice_ctx); | ||
} | ||
|
||
template<typename T> | ||
class LogicalSliceKernel final : public user_op::OpKernel { | ||
public: | ||
|
@@ -361,7 +337,25 @@ class LogicalSliceKernel final : public user_op::OpKernel { | |
|
||
std::shared_ptr<user_op::OpKernelCache> InitOpKernelCache( | ||
user_op::KernelCacheContext* ctx) const override { | ||
return CreateSliceCache(ctx, "x"); | ||
SliceContext slice_ctx; | ||
if (ctx->parallel_ctx().parallel_num() == 1) { | ||
// split_axis == SPLIT_AXIS_FOR_NON_SPLIT means the sbp attribute is not 'split' | ||
CHECK_JUST(slice_ctx.PushSplitInfo(SPLIT_AXIS_FOR_NON_SPLIT, 0, 0, 0)); | ||
} else { | ||
const NdSbp& in_nd_sbp = ctx->NdSbp4ArgNameAndIndex("x", 0); | ||
const Shape& parallel_hierarchy = *ctx->parallel_desc().hierarchy(); | ||
const Shape& logical_shape = ctx->LogicalTensorDesc4ArgNameAndIndex("x", 0)->shape(); | ||
const int64_t parallel_id = ctx->parallel_ctx().parallel_id(); | ||
const TensorSliceView& slice_view = | ||
GetTensorSliceView4ParallelId(parallel_hierarchy, in_nd_sbp, logical_shape, parallel_id); | ||
for (int i = 0; i < logical_shape.NumAxes(); ++i) { | ||
const Range& range = slice_view.At(i); | ||
if (range.begin() != 0 || range.end() != logical_shape.At(i)) { | ||
CHECK_JUST(slice_ctx.PushSplitInfo(i, range.begin(), range.end(), logical_shape.At(i))); | ||
} | ||
} | ||
} | ||
return std::make_shared<OpKernelCacheWrapper<SliceContext>>(slice_ctx); | ||
} | ||
|
||
private: | ||
|
@@ -388,15 +382,39 @@ class LogicalSliceAssignKernel final : public user_op::OpKernel { | |
|
||
std::shared_ptr<user_op::OpKernelCache> InitOpKernelCache( | ||
user_op::KernelCacheContext* ctx) const override { | ||
if (ctx->parallel_ctx().parallel_num() > 1) { | ||
const NdSbp& value_nd_sbp = ctx->NdSbp4ArgNameAndIndex("value", 0); | ||
CHECK(std::all_of(value_nd_sbp.sbp_parallel().begin(), value_nd_sbp.sbp_parallel().end(), | ||
[](const SbpParallel& sbp) { | ||
return sbp.has_partial_sum_parallel() || sbp.has_broadcast_parallel(); | ||
})) | ||
<< "value's sbp must be broadcast or partial_sum"; | ||
SliceContext slice_ctx; | ||
if (ctx->parallel_ctx().parallel_num() == 1) { | ||
// split_axis == SPLIT_AXIS_FOR_NON_SPLIT means the sbp attribute is not 'split' | ||
CHECK_JUST(slice_ctx.PushSplitInfo(SPLIT_AXIS_FOR_NON_SPLIT, 0, 0, 0)); | ||
} else { | ||
const Shape& parallel_hierarchy = *ctx->parallel_desc().hierarchy(); | ||
NdSbp ref_nd_sbp = ctx->NdSbp4ArgNameAndIndex("ref", 0); | ||
{ | ||
const NdSbp value_nd_sbp = ctx->NdSbp4ArgNameAndIndex("value", 0); | ||
// If ref and value both split in the same axis(full slice), | ||
// we can consider the physical tensor is broadcast in this axis. | ||
for (int i = 0; i < parallel_hierarchy.NumAxes(); ++i) { | ||
const SbpParallel& ref_sbp = ref_nd_sbp.sbp_parallel(i); | ||
const SbpParallel& value_sbp = value_nd_sbp.sbp_parallel(i); | ||
if (ref_sbp.has_split_parallel() && value_sbp.has_split_parallel()) { | ||
CHECK_EQ(ref_sbp.split_parallel().axis(), value_sbp.split_parallel().axis()); | ||
ref_nd_sbp.mutable_sbp_parallel(i)->clear_split_parallel(); | ||
ref_nd_sbp.mutable_sbp_parallel(i)->mutable_broadcast_parallel(); | ||
} | ||
} | ||
Comment on lines
+393
to
+404
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段是这次改动的核心,如果是 FullSlice,这个维度的 SbpParallel 按 Broadcast 来处理 |
||
} | ||
const Shape& logical_shape = ctx->LogicalTensorDesc4ArgNameAndIndex("ref", 0)->shape(); | ||
const int64_t parallel_id = ctx->parallel_ctx().parallel_id(); | ||
const TensorSliceView& slice_view = | ||
GetTensorSliceView4ParallelId(parallel_hierarchy, ref_nd_sbp, logical_shape, parallel_id); | ||
for (int i = 0; i < logical_shape.NumAxes(); ++i) { | ||
const Range& range = slice_view.At(i); | ||
if (range.begin() != 0 || range.end() != logical_shape.At(i)) { | ||
CHECK_JUST(slice_ctx.PushSplitInfo(i, range.begin(), range.end(), logical_shape.At(i))); | ||
} | ||
} | ||
} | ||
return CreateSliceCache(ctx, "ref"); | ||
return std::make_shared<OpKernelCacheWrapper<SliceContext>>(slice_ctx); | ||
} | ||
|
||
private: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段不能通用了,LogicalSlice 和 LogicalSliceAssign 的 Cache 分开推导