Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions paddle/phi/infermeta/binary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ void GatherInferMeta(const MetaTensor& x,
} else {
if (axis.FromTensor() || axis_v == 0) {
// decrease the output dimension
std::vector<int> out_dim_vec;
std::vector<int64_t> out_dim_vec;
for (int i = 1; i < input_dim.size(); ++i) {
out_dim_vec.emplace_back(input_dim[i]);
}
Expand All @@ -2076,7 +2076,7 @@ void GatherInferMeta(const MetaTensor& x,
out->set_dtype(x.dtype());
out->share_lod(x);
} else {
std::vector<int> out_dim_vec;
std::vector<int64_t> out_dim_vec;
for (int i = 0; i < axis_v; i++) {
out_dim_vec.push_back(input_dim[i]); // NOLINT
}
Expand All @@ -2092,7 +2092,7 @@ void GatherInferMeta(const MetaTensor& x,
} else {
if (axis.FromTensor() || axis_v == 0) {
// if axis.FromTensor(), we can not obtain correct shape of output
int batch_size = static_cast<int>(index_dims[0]);
int64_t batch_size = static_cast<int64_t>(index_dims[0]);
if (index_dims.size() == 2 && index_dims[1] == 0) {
batch_size = 0;
}
Expand All @@ -2102,11 +2102,11 @@ void GatherInferMeta(const MetaTensor& x,
out->set_dtype(x.dtype());
out->share_lod(x);
} else {
int index_size = static_cast<int>(index_dims[0]);
int64_t index_size = static_cast<int64_t>(index_dims[0]);
if (index_dims.size() == 2 && index_dims[1] == 0) {
index_size = 0;
}
std::vector<int> out_dim_vec;
std::vector<int64_t> out_dim_vec;
for (int i = 0; i < axis_v; i++) {
out_dim_vec.push_back(input_dim[i]); // NOLINT
}
Expand Down
19 changes: 11 additions & 8 deletions python/paddle/nn/functional/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4167,14 +4167,17 @@ def multi_margin_loss(
f"but received weight's shape[0]: {weight.shape[0]} and input's shape[1]: {input.shape[1]}"
)
weight = paddle.gather(weight, label, axis=0).reshape((-1, 1))
loss = paddle.mean(
weight
* paddle.pow(
paddle.clip((margin - index_sample + input), min=0.0),
p,
),
axis=1,
) - weight * (margin**p / paddle.shape(input)[1])
loss = (
paddle.mean(
weight
* paddle.pow(
paddle.clip((margin - index_sample + input), min=0.0),
p,
),
axis=1,
)
- (weight * (margin**p / paddle.shape(input)[1])).squeeze()
)
else:
loss = (
paddle.mean(
Expand Down