Repository navigation
[Auto Parallel] Add spmd rule No.12 for label_smooth and label_smooth ops. #72845
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
Merged
luotao1
merged 13 commits into
PaddlePaddle:develop
from
ooooo-create:add_spmd_label_smooth
Jun 13, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
49fdb36
add spmd_rule for label_smooth
ooooo-create ed9f3aa
update
ooooo-create d008da5
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
ooooo-create e630d42
fix bugs
ooooo-create 6451b3b
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
ooooo-create bedf595
apply review
ooooo-create 0d54227
revert due to https://github.com/PaddlePaddle/Paddle/pull/72753
ooooo-create eaf3c5c
revert change for expand_as
ooooo-create 1993a9e
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
ooooo-create 624db84
Add more tests
ooooo-create 6cb63c2
apply review
ooooo-create a319fdd
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
ooooo-create 96dd4a4
refine code
ooooo-create 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. */ | ||
|
|
||
| #include "paddle/phi/infermeta/spmd_rules/label_smooth.h" | ||
| #include "glog/logging.h" | ||
| #include "paddle/phi/core/distributed/auto_parallel/dist_attr.h" | ||
| #include "paddle/phi/core/distributed/auto_parallel/dist_meta_tensor.h" | ||
| #include "paddle/phi/core/distributed/type_defs.h" | ||
| #include "paddle/phi/infermeta/spmd_rules/elementwise.h" | ||
| #include "paddle/phi/infermeta/spmd_rules/spmd_rule_macro_define.h" | ||
| #include "paddle/phi/infermeta/spmd_rules/utils.h" | ||
|
|
||
| namespace phi { | ||
| namespace distributed { | ||
|
|
||
| std::vector<int64_t> ReplicateWithExcludeAxes( | ||
| const std::vector<int64_t>& x, const std::vector<int64_t>& exclude_axes) { | ||
| std::vector<int64_t> res(x); | ||
| for (size_t i = 0; i < x.size(); ++i) { | ||
| if (res[i] == -1) { | ||
| continue; | ||
| } | ||
|
|
||
| if (std::find(exclude_axes.begin(), exclude_axes.end(), res[i]) != | ||
| exclude_axes.end()) { | ||
| res[i] = -1; | ||
| } | ||
| } | ||
| return res; | ||
| } | ||
|
|
||
| SpmdInfo LabelSmoothInferSpmd(const DistMetaTensor& label, | ||
| const DistMetaTensor& prior_dist, | ||
| float epsilon) { | ||
| if (prior_dist.initialized()) { | ||
| const auto& label_dims_attr = label.dist_attr(); | ||
| const auto& prior_dims_attr = prior_dist.dist_attr(); | ||
| const auto& label_dims_mapping = label_dims_attr.dims_mapping(); | ||
| const auto& prior_dims_mapping = prior_dims_attr.dims_mapping(); | ||
| size_t label_rank = label.dims().size(); | ||
| size_t prior_rank = prior_dist.dims().size(); | ||
|
|
||
| if (label_rank > prior_rank) { | ||
| size_t extra_dims_count = label_rank - prior_rank; | ||
| std::vector<std::int64_t> extra_dims_mapping_values; | ||
| extra_dims_mapping_values.reserve(extra_dims_count); | ||
| for (size_t i = 0; i < extra_dims_count; ++i) { | ||
| extra_dims_mapping_values.push_back(label_dims_mapping[i]); | ||
| } | ||
| const auto& new_prior_dims_mapping = ReplicateWithExcludeAxes( | ||
| prior_dims_mapping, extra_dims_mapping_values); | ||
| TensorDistAttr new_prior_dist_attr = prior_dims_attr; | ||
| new_prior_dist_attr.set_dims_mapping(new_prior_dims_mapping); | ||
| DistMetaTensor modified_prior_dist(prior_dist.dims(), | ||
| new_prior_dist_attr); | ||
| VLOG(4) << "LabelSmoothInferSpmd call ElementwiseBinaryInferSpmd:"; | ||
| return ElementwiseBinaryInferSpmd(label, modified_prior_dist); | ||
| } | ||
| VLOG(4) << "LabelSmoothInferSpmd call ElementwiseBinaryInferSpmd:"; | ||
| return ElementwiseBinaryInferSpmd(label, prior_dist); | ||
| } | ||
| VLOG(4) << "LabelSmoothInferSpmd call ElementwiseUnaryInferSpmd:"; | ||
| SpmdInfo unary_spmd_info = ElementwiseUnaryInferSpmd(label); | ||
| unary_spmd_info.first.push_back(TensorDistAttr()); | ||
| return unary_spmd_info; | ||
| } | ||
|
|
||
| SpmdInfo LabelSmoothGradInferSpmd(const DistMetaTensor& out_grad, | ||
| float epsilon) { | ||
| VLOG(4) << "LabelSmoothGradInferSpmd call ElementwiseUnaryGradInferSpmd:"; | ||
| return ElementwiseUnaryGradInferSpmd(out_grad); | ||
| } | ||
| } // namespace distributed | ||
| } // namespace phi |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "paddle/phi/core/distributed/auto_parallel/dist_meta_tensor.h" | ||
| #include "paddle/phi/core/distributed/type_defs.h" | ||
|
|
||
| namespace phi { | ||
| namespace distributed { | ||
|
|
||
| SpmdInfo LabelSmoothInferSpmd(const DistMetaTensor& label, | ||
| const DistMetaTensor& prior_dist, | ||
| float epsilon); | ||
|
|
||
| SpmdInfo LabelSmoothGradInferSpmd(const DistMetaTensor& out_grad, | ||
| float epsilon); | ||
|
|
||
| } // namespace distributed | ||
| } // namespace phi |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
216 changes: 216 additions & 0 deletions
216
test/auto_parallel/spmd_rules/test_label_smooth_rule.py
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import unittest | ||
| from collections import OrderedDict | ||
|
|
||
| from paddle.distributed.auto_parallel.static.dist_attribute import ( | ||
| DistTensorSpec, | ||
| TensorDistAttr, | ||
| ) | ||
| from paddle.distributed.fleet import auto | ||
| from paddle.framework import core | ||
|
|
||
|
|
||
| class TestLabelSmoothSPMDRule(unittest.TestCase): | ||
| def setUp(self): | ||
| label_shape = [16, 16, 16] | ||
| out_shape = [16, 16, 16] | ||
| prior_dist_shape = [1, 16] | ||
| process_mesh = auto.ProcessMesh(mesh=[[0, 1], [2, 3]]) | ||
|
|
||
| label_tensor_dist_attr = TensorDistAttr() | ||
| label_tensor_dist_attr.dims_mapping = [-1, -1, -1] | ||
| label_tensor_dist_attr.process_mesh = process_mesh | ||
|
|
||
| self.label_dist_tensor_spec = DistTensorSpec( | ||
| label_shape, label_tensor_dist_attr | ||
| ) | ||
| prior_dist_tensor_dist_attr = TensorDistAttr() | ||
| prior_dist_tensor_dist_attr.dims_mapping = [-1, -1] | ||
| prior_dist_tensor_dist_attr.process_mesh = process_mesh | ||
|
|
||
| self.prior_dist_dist_tensor_spec = DistTensorSpec( | ||
| prior_dist_shape, prior_dist_tensor_dist_attr | ||
| ) | ||
|
|
||
| out_tensor_dist_attr = TensorDistAttr() | ||
| out_tensor_dist_attr.dims_mapping = [-1, -1, -1] | ||
| out_tensor_dist_attr.process_mesh = process_mesh | ||
| self.out_dist_tensor_spec = DistTensorSpec( | ||
| out_shape, out_tensor_dist_attr | ||
| ) | ||
|
|
||
| self.rule = core.get_phi_spmd_rule("label_smooth") | ||
| self.attrs = OrderedDict() | ||
| self.attrs['epsilon'] = 0.1 | ||
|
|
||
| def test_label_smooth_forward(self): | ||
| # [0, 1, -1], [Fake] --> [0, 1, -1], [Fake], [0, 1, -1] | ||
| self.label_dist_tensor_spec.set_dims_mapping([0, 1, -1]) | ||
|
|
||
| result_dist_attrs = self.rule.infer_forward( | ||
| self.label_dist_tensor_spec, | ||
| DistTensorSpec(), | ||
| self.attrs['epsilon'], | ||
| ) | ||
|
|
||
| self.assertEqual(len(result_dist_attrs), 2) | ||
| inferred_input_dist_attrs = result_dist_attrs[0] | ||
| inferred_output_dist_attrs = result_dist_attrs[1] | ||
|
|
||
| self.assertEqual(len(inferred_input_dist_attrs), 2) | ||
| self.assertEqual(len(inferred_output_dist_attrs), 1) | ||
|
|
||
| self.assertEqual(inferred_input_dist_attrs[0].dims_mapping, [0, 1, -1]) | ||
| self.assertEqual(inferred_input_dist_attrs[1], TensorDistAttr()) | ||
| self.assertEqual(inferred_output_dist_attrs[0].dims_mapping, [0, 1, -1]) | ||
|
|
||
| # shape: [16, 16, 16], [1, 16]. [0, 1, -1], [-1, -1] --> [0, 1, -1], [-1, -1], [0, 1, -1] | ||
| self.prior_dist_dist_tensor_spec.set_dims_mapping([-1, -1]) | ||
| result_dist_attrs = self.rule.infer_forward( | ||
| self.label_dist_tensor_spec, | ||
| self.prior_dist_dist_tensor_spec, | ||
| self.attrs['epsilon'], | ||
| ) | ||
|
|
||
| self.assertEqual(len(result_dist_attrs), 2) | ||
| inferred_input_dist_attrs = result_dist_attrs[0] | ||
| inferred_output_dist_attrs = result_dist_attrs[1] | ||
|
|
||
| self.assertEqual(len(inferred_input_dist_attrs), 2) | ||
| self.assertEqual(len(inferred_output_dist_attrs), 1) | ||
|
|
||
| self.assertEqual(inferred_input_dist_attrs[0].dims_mapping, [0, 1, -1]) | ||
| self.assertEqual(inferred_input_dist_attrs[1].dims_mapping, [-1, -1]) | ||
| self.assertEqual(inferred_output_dist_attrs[0].dims_mapping, [0, 1, -1]) | ||
|
|
||
| # shape: [16, 16, 16], [1, 16]. [0, 1, -1], [-1, 1] --> [0, 1, -1], [-1, -1], [0, 1, -1] | ||
| self.prior_dist_dist_tensor_spec.set_dims_mapping([-1, 1]) | ||
| result_dist_attrs = self.rule.infer_forward( | ||
| self.label_dist_tensor_spec, | ||
| self.prior_dist_dist_tensor_spec, | ||
| self.attrs['epsilon'], | ||
| ) | ||
| self.assertEqual(len(result_dist_attrs), 2) | ||
| inferred_input_dist_attrs = result_dist_attrs[0] | ||
| inferred_output_dist_attrs = result_dist_attrs[1] | ||
| self.assertEqual(len(inferred_input_dist_attrs), 2) | ||
| self.assertEqual(len(inferred_output_dist_attrs), 1) | ||
| self.assertEqual(inferred_input_dist_attrs[0].dims_mapping, [0, 1, -1]) | ||
| self.assertEqual(inferred_input_dist_attrs[1].dims_mapping, [-1, -1]) | ||
| self.assertEqual(inferred_output_dist_attrs[0].dims_mapping, [0, 1, -1]) | ||
|
|
||
| # shape: [16, 16, 16], [1, 16]. [0, 1, -1], [-1, 0] --> [0, 1, -1], [-1, -1], [0, 1, -1] | ||
| self.prior_dist_dist_tensor_spec.set_dims_mapping([-1, 0]) | ||
| result_dist_attrs = self.rule.infer_forward( | ||
| self.label_dist_tensor_spec, | ||
| self.prior_dist_dist_tensor_spec, | ||
| self.attrs['epsilon'], | ||
| ) | ||
| self.assertEqual(len(result_dist_attrs), 2) | ||
| inferred_input_dist_attrs = result_dist_attrs[0] | ||
| inferred_output_dist_attrs = result_dist_attrs[1] | ||
| self.assertEqual(len(inferred_input_dist_attrs), 2) | ||
| self.assertEqual(len(inferred_output_dist_attrs), 1) | ||
| self.assertEqual(inferred_input_dist_attrs[0].dims_mapping, [0, 1, -1]) | ||
| self.assertEqual(inferred_input_dist_attrs[1].dims_mapping, [-1, -1]) | ||
| self.assertEqual(inferred_output_dist_attrs[0].dims_mapping, [0, 1, -1]) | ||
|
|
||
| # shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, 1] --> [0, -1, 1], [-1, 1], [0, -1, 1] | ||
| self.label_dist_tensor_spec.set_dims_mapping([0, -1, 1]) | ||
| self.prior_dist_dist_tensor_spec.set_dims_mapping([-1, 1]) | ||
| result_dist_attrs = self.rule.infer_forward( | ||
| self.label_dist_tensor_spec, | ||
| self.prior_dist_dist_tensor_spec, | ||
| self.attrs['epsilon'], | ||
| ) | ||
| self.assertEqual(len(result_dist_attrs), 2) | ||
| inferred_input_dist_attrs = result_dist_attrs[0] | ||
| inferred_output_dist_attrs = result_dist_attrs[1] | ||
| self.assertEqual(len(inferred_input_dist_attrs), 2) | ||
| self.assertEqual(len(inferred_output_dist_attrs), 1) | ||
| self.assertEqual(inferred_input_dist_attrs[0].dims_mapping, [0, -1, 1]) | ||
| self.assertEqual(inferred_input_dist_attrs[1].dims_mapping, [-1, 1]) | ||
| self.assertEqual(inferred_output_dist_attrs[0].dims_mapping, [0, -1, 1]) | ||
|
|
||
| # shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, 0] --> [0, -1, 1], [-1, 1], [0, -1, 1] | ||
| self.prior_dist_dist_tensor_spec.set_dims_mapping([-1, 0]) | ||
| result_dist_attrs = self.rule.infer_forward( | ||
| self.label_dist_tensor_spec, | ||
| self.prior_dist_dist_tensor_spec, | ||
| self.attrs['epsilon'], | ||
| ) | ||
| self.assertEqual(len(result_dist_attrs), 2) | ||
| inferred_input_dist_attrs = result_dist_attrs[0] | ||
| inferred_output_dist_attrs = result_dist_attrs[1] | ||
| self.assertEqual(len(inferred_input_dist_attrs), 2) | ||
| self.assertEqual(len(inferred_output_dist_attrs), 1) | ||
| self.assertEqual(inferred_input_dist_attrs[0].dims_mapping, [0, -1, 1]) | ||
| self.assertEqual(inferred_input_dist_attrs[1].dims_mapping, [-1, 1]) | ||
| self.assertEqual(inferred_output_dist_attrs[0].dims_mapping, [0, -1, 1]) | ||
|
|
||
| # shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, -1] --> [0, -1, 1], [-1, 1], [0, -1, 1] | ||
| self.prior_dist_dist_tensor_spec.set_dims_mapping([-1, -1]) | ||
| result_dist_attrs = self.rule.infer_forward( | ||
| self.label_dist_tensor_spec, | ||
| self.prior_dist_dist_tensor_spec, | ||
| self.attrs['epsilon'], | ||
| ) | ||
| self.assertEqual(len(result_dist_attrs), 2) | ||
| inferred_input_dist_attrs = result_dist_attrs[0] | ||
| inferred_output_dist_attrs = result_dist_attrs[1] | ||
| self.assertEqual(len(inferred_input_dist_attrs), 2) | ||
| self.assertEqual(len(inferred_output_dist_attrs), 1) | ||
| self.assertEqual(inferred_input_dist_attrs[0].dims_mapping, [0, -1, 1]) | ||
| self.assertEqual(inferred_input_dist_attrs[1].dims_mapping, [-1, 1]) | ||
| self.assertEqual(inferred_output_dist_attrs[0].dims_mapping, [0, -1, 1]) | ||
|
|
||
| # shape: [16, 16, 16], [16, 16, 16]. [0, 1, -1], [0, -1, 1] --> [0, 1, -1], [0, 1, -1], [0, 1, -1] | ||
| self.label_dist_tensor_spec.set_dims_mapping([0, 1, -1]) | ||
| self.prior_dist_dist_tensor_spec.shape = [16, 16, 16] | ||
| self.prior_dist_dist_tensor_spec.set_dims_mapping([0, -1, 1]) | ||
| result_dist_attrs = self.rule.infer_forward( | ||
| self.label_dist_tensor_spec, | ||
| self.prior_dist_dist_tensor_spec, | ||
| self.attrs['epsilon'], | ||
| ) | ||
| self.assertEqual(len(result_dist_attrs), 2) | ||
| inferred_input_dist_attrs = result_dist_attrs[0] | ||
| inferred_output_dist_attrs = result_dist_attrs[1] | ||
| self.assertEqual(len(inferred_input_dist_attrs), 2) | ||
| self.assertEqual(len(inferred_output_dist_attrs), 1) | ||
| self.assertEqual(inferred_input_dist_attrs[0].dims_mapping, [0, 1, -1]) | ||
| self.assertEqual(inferred_input_dist_attrs[1].dims_mapping, [0, 1, -1]) | ||
| self.assertEqual(inferred_output_dist_attrs[0].dims_mapping, [0, 1, -1]) | ||
|
|
||
| def test_label_smooth_backward(self): | ||
| # shape: [16, 16 ,16]. [0, -1, 1] --> [0, -1, 1], [0, -1, 1] | ||
| self.out_dist_tensor_spec.set_dims_mapping([0, -1, 1]) | ||
| result_dist_attrs = self.rule.infer_backward( | ||
| self.out_dist_tensor_spec, | ||
| self.attrs['epsilon'], | ||
| ) | ||
|
|
||
| self.assertEqual(len(result_dist_attrs), 2) | ||
| inferred_input_dist_attrs = result_dist_attrs[0] | ||
| inferred_output_dist_attrs = result_dist_attrs[1] | ||
| self.assertEqual(len(inferred_input_dist_attrs), 1) | ||
| self.assertEqual(len(inferred_output_dist_attrs), 1) | ||
| self.assertEqual(inferred_input_dist_attrs[0].dims_mapping, [0, -1, 1]) | ||
| self.assertEqual(inferred_output_dist_attrs[0].dims_mapping, [0, -1, 1]) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Oops, something went wrong.
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.
we need more unit test case to check:
if
# shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, 1], what result should beif
# shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, 0], what result should beif
# shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, -1], what result should beThere 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.
In the second station
# shape: [16, 16, 16], [1, 16]. [0, -1, 1], [-1, 0]Because of reuse the
ElementwiseBinaryInferSpmd, now it will cause error now when meet 1 and 0 with same axes (due to theShardingMergeForAxis).The following error is below, and I check the error now rather than implement it
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.
According to the calculation logic of this operator, if
# shape: [16, 16, 16], [1, 16]anddims_mapping: [0, -1, 1], [-1, 0]the result of dims_mapping should be[0, -1, 1], [-1, 1], [0, -1, 1]? if so, we should add some necessary checks and modifications to dims_mapping of prior_dist before callingElementwiseBinaryInferSpmd?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.
Yes. If
# shape: [16, 16, 16], [1, 16]and dims_mapping:[0, -1, 1], [-1, 0]the result of dims_mapping should be[0, -1, 1], [-1, 1], [0, -1, 1]If label's rank is greater than prior_dist's axis. It has an extra_dims_mapping. When prior_dist's dims_mappin in it, replicate it to
-1first. It will work better than before.(In addition, I think in the future
ElementwiseBinaryInferSpmdalso should deal with this station