-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
【PIR OpTest Fix No.14】 fix test_nce #60255
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a333e1e
fix test_nce
xingmingyyj d780bc3
fix test_nce
xingmingyyj bfa83bf
Update ops.yaml
xingmingyyj 59d4818
fix
xingmingyyj b614ba2
Merge branch 'develop' into fix_test_nce
xingmingyyj 92988b8
Merge branch 'develop' into fix_test_nce
xingmingyyj e97d113
Update utils.cc
xingmingyyj 7b87b28
Merge branch 'PaddlePaddle:develop' into fix_test_nce
xingmingyyj c17b4d8
Update ops.yaml
xingmingyyj 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
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
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
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 |
---|---|---|
|
@@ -3181,6 +3181,97 @@ void MultiplexInferMeta(const std::vector<const MetaTensor*>& ins, | |
out->set_dtype(ins[0]->dtype()); | ||
} | ||
|
||
void NceInferMeta(const MetaTensor& input, | ||
const MetaTensor& label, | ||
const MetaTensor& weight, | ||
const MetaTensor& bias, | ||
const MetaTensor& sample_weight, | ||
const MetaTensor& custom_dist_probs, | ||
const MetaTensor& custom_dist_alias, | ||
const MetaTensor& custom_dist_alias_probs, | ||
int num_total_classes, | ||
const std::vector<int>& custom_neg_classes, | ||
int num_neg_samples, | ||
int sampler, | ||
int seed, | ||
bool is_sparse, | ||
bool remote_prefetch, | ||
bool is_test, | ||
MetaTensor* cost, | ||
MetaTensor* sample_logits, | ||
MetaTensor* sample_labels, | ||
MetaConfig config) { | ||
auto x_dims = input.dims(); | ||
auto label_dims = label.dims(); | ||
if (config.is_runtime || (x_dims[0] > 0 && label_dims[0] > 0)) { | ||
PADDLE_ENFORCE_EQ( | ||
x_dims[0], | ||
label_dims[0], | ||
phi::errors::InvalidArgument( | ||
"The first dimension of Input(Input) and Input(Label) should be " | ||
"equal in runtime. But received: Input(Input)'s shape = [%s] " | ||
"with 1st dim = %d, Input(Label)'s shape = [%s] with 1st dim = " | ||
"%d.", | ||
x_dims, | ||
x_dims[0], | ||
label_dims, | ||
label_dims[0])); | ||
} | ||
int num_true_classes = | ||
static_cast<int>(label_dims.size() == 2 ? label_dims[1] : 1); | ||
if (bias) { | ||
PADDLE_ENFORCE_EQ( | ||
weight.dims()[0], | ||
bias.dims()[0], | ||
phi::errors::InvalidArgument( | ||
"The first dimension of Input(Weight) and Input(Bias) " | ||
"should be equal. But received: Input(Weight)'s shape = [%s] " | ||
"with 1st dim = %d, and Input(Bias)'s shape = [%s] with 1st dim " | ||
"= %d.", | ||
weight.dims(), | ||
weight.dims()[0], | ||
bias.dims(), | ||
bias.dims()[0])); | ||
} | ||
|
||
PADDLE_ENFORCE_EQ( | ||
num_total_classes, | ||
weight.dims()[0], | ||
phi::errors::InvalidArgument( | ||
"The number of total classes should be equal to the first " | ||
"dimension of Input(Weight). But received: Attr(num_total_classes) " | ||
"= %d, Input(Weight)'s shape = [%s] with 1st dim = %d.", | ||
num_total_classes, | ||
weight.dims(), | ||
weight.dims()[0])); | ||
if (custom_neg_classes.size() > 0) { | ||
PADDLE_ENFORCE_EQ( | ||
custom_neg_classes.size(), | ||
static_cast<size_t>(num_neg_samples), | ||
phi::errors::InvalidArgument( | ||
"The size of Attr(custom_neg_classes) should be equal " | ||
"to the number of negative samples. But received: " | ||
"custom_neg_classes.size() = %d, num_neg_samples = %d.", | ||
custom_neg_classes.size(), | ||
num_neg_samples)); | ||
} | ||
// set dims of output(Out) | ||
std::vector<int64_t> out_dims; | ||
out_dims.push_back(x_dims[0]); | ||
out_dims.push_back(1); | ||
cost->set_dims(common::make_ddim(out_dims)); | ||
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. 同上 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. 已设置 |
||
|
||
if (!is_test) { | ||
// set dims of output(SampleOut) | ||
std::vector<int64_t> sample_out_dims; | ||
sample_out_dims.push_back(x_dims[0]); | ||
sample_out_dims.push_back( | ||
(num_true_classes == -1) ? -1 : (num_neg_samples + num_true_classes)); | ||
sample_logits->set_dims(common::make_ddim(sample_out_dims)); | ||
sample_labels->set_dims(common::make_ddim(sample_out_dims)); | ||
} | ||
} | ||
|
||
void PsroiPoolInferMeta(const MetaTensor& x, | ||
const MetaTensor& rois, | ||
const MetaTensor& rois_num, | ||
|
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.
dtype 也设置下
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.
已设置