Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
momo609 committed Aug 26, 2023
1 parent 89f6e34 commit 6d34074
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
10 changes: 5 additions & 5 deletions mmcv/ops/csrc/pytorch/npu/bbox_overlaps_npu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ void bbox_overlaps_npu(const Tensor bboxes1, const Tensor bboxes2, Tensor ious,
bboxesFP32 = bboxes1;
gtboxesFP32 = bboxes2;
}
if (bboxes2.scalar_type() != at::ScalarType::Float) {
if (bboxes2.scalar_type() != at::kFloat) {
// bboxesFP32 = NPUNativeFunctions::npu_dtype_cast(bboxesFP32, at::kFloat);
// gtboxesFP32 = NPUNativeFunctions::npu_dtype_cast(gtboxesFP32, at::kFloat);
bboxesFP32 = bboxesFP32.to(at::ScalarType::kFloat);
gtboxesFP32 = gtboxesFP32.to(at::ScalarType::kFloat);
bboxesFP32 = bboxesFP32.to(at::kFloat);
gtboxesFP32 = gtboxesFP32.to(at::kFloat);
}
c10::SmallVector<int64_t, SIZE> iousSize = {gtboxesFP32.size(0),
bboxesFP32.size(0)};
Expand All @@ -44,9 +44,9 @@ void bbox_overlaps_npu(const Tensor bboxes1, const Tensor bboxes2, Tensor ious,
.Attr("eps", (float)offset)
.Attr("aligned", aligned)
.Run();
if (bboxes2.scalar_type() != at::ScalarType::Float) {
if (bboxes2.scalar_type() != at::kFloat) {
// iousFP32 = NPUNativeFunctions::npu_dtype_cast(iousFP32, at::kHalf);
iousFP32 = iousFP32.to(at::ScalarType::kHalf);
iousFP32 = iousFP32.to(at::kHalf);
}
iousFP32 = swap_flag ? iousFP32.transpose(0, 1) : iousFP32;
ious.copy_(iousFP32);
Expand Down
12 changes: 6 additions & 6 deletions mmcv/ops/csrc/pytorch/npu/focal_loss_npu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void sigmoid_focal_loss_forward_npu(Tensor input, Tensor target, Tensor weight,
if (weight_size > 0) {
// weight_y = at_npu::native::NPUNativeFunctions::npu_broadcast(weight,
// input.sizes());
weight_y = at::npu_broadcast(weight, input.sizes());
weight_y = at::broadcast_to(weight, input.sizes());
}
OpCommand cmd;
string reduction = "none";
Expand Down Expand Up @@ -55,14 +55,14 @@ void sigmoid_focal_loss_backward_npu(Tensor input, Tensor target, Tensor weight,
}
// target_y =
// at_npu::native::NPUNativeFunctions::npu_dtype_cast(target_y, at::kInt);
target_y = target_y.to(at::ScalarType::kInt);
target_y = target_y.to(at::kInt);
at::Tensor grad_up = at::ones_like(input);
int64_t weight_size = weight.size(0);
at::Tensor weight_y = at::ones_like(input);
if (weight_size > 0) {
// weight_y = at_npu::native::NPUNativeFunctions::npu_broadcast(weight,
// input.sizes());
weight_y = at::npu_broadcast(weight, input.sizes());
weight_y = at::broadcast_to(weight, input.sizes());
}
OpCommand cmd;
string reduction = "none";
Expand Down Expand Up @@ -90,13 +90,13 @@ void softmax_focal_loss_forward_npu(Tensor input, Tensor target, Tensor weight,
// target_y =
// at_npu::native::NPUNativeFunctions::npu_dtype_cast(target_y, at::kInt);
target_y = at::one_hot(target, n_class);
target_y = target_y.to(at::ScalarType::kInt);
target_y = target_y.to(at::kInt);
int64_t weight_size = weight.size(0);
at::Tensor weight_y = at::ones_like(input);
if (weight_size > 0) {
// weight_y = at_npu::native::NPUNativeFunctions::npu_broadcast(weight,
// input.sizes());
weight_y = at::npu_broadcast(weight, input.sizes());
weight_y = at::broadcast_to(weight, input.sizes());
}
at::Tensor op_output = at::ones_like(input);
OpCommand cmd;
Expand Down Expand Up @@ -133,7 +133,7 @@ void softmax_focal_loss_backward_npu(Tensor input, Tensor target, Tensor weight,
// target_y =
// at_npu::native::NPUNativeFunctions::npu_dtype_cast(target_y, at::kInt);
target_y = at::one_hot(target, n_class);
target_y = target_y.to(at::ScalarType::kInt);
target_y = target_y.to(at::kInt);
at::Tensor grad_up = at::ones_like(input);
int64_t weight_size = weight.size(0);
at::Tensor weight_y = at::ones_like(input);
Expand Down
2 changes: 1 addition & 1 deletion mmcv/ops/csrc/pytorch/npu/fused_bias_leakyrelu_npu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Tensor fused_bias_leakyrelu_npu(const Tensor &input, const Tensor &bias,
at::Tensor bias_tmp = at::reshape(bias, input_size_tmp);
// at::Tensor bias_ = at_npu::native::NPUNativeFunctions::npu_broadcast(
// bias_tmp, input.sizes());
bias_ = at::npu_broadcast(bias_tmp, input.sizes());
at::Tensor bias_ = at::broadcast_to(bias_tmp, input.sizes());
OpCommand cmd;
cmd.Name("FusedBiasLeakyRelu")
.Input(input)
Expand Down
7 changes: 3 additions & 4 deletions mmcv/ops/csrc/pytorch/npu/nms_npu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Tensor nms_npu(Tensor boxes, Tensor scores, float iou_threshold, int offset) {
// .fill_(0);
at::Tensor iou_threshold_y = at::empty({}, boxes.options().dtype(at::kFloat)).fill_(iou_threshold);
at::Tensor scores_threshold_y = at::empty({}, boxes.options().dtype(at::kFloat)).fill_(0);
at::Tensor max_outputsize_y = at::empty({}, boxes.options().dtype(at::kInt)).fill_(boxes.size(0));

// at::Tensor max_outputsize_y = at_npu::native::OpPreparation::ApplyTensor(
// {}, boxes.options().dtype(at::kInt), boxes)
Expand All @@ -37,12 +36,12 @@ Tensor nms_npu(Tensor boxes, Tensor scores, float iou_threshold, int offset) {
.Output(output)
.Run();
auto outputsizeBool = at::gt(output, -1);
auto outputsizeInt = outputsizeBool.to(at::ScalarType::Int);
auto countLen = at::sum(outputsizeInt, at::ScalarType::Int);
auto outputsizeInt = outputsizeBool.to(at::kInt);
auto countLen = at::sum(outputsizeInt, at::kInt);
at::Tensor actual_output = output.slice(0, 0, countLen.item().toLong());
// actual_output = at_npu::native::NPUNativeFunctions::npu_dtype_cast(
// actual_output, at::kLong);
actual_output = actual_output.to(at::ScalarType::kLong);
actual_output = actual_output.to(at::kLong);
return actual_output;
}

Expand Down
8 changes: 4 additions & 4 deletions mmcv/ops/csrc/pytorch/npu/nms_rotated_npu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Tensor nms_rotated_npu(const Tensor dets, const Tensor scores,
auto originDtype = dets.scalar_type();
at::Tensor detsCast = dets;
at::Tensor scoresCast = scores;
if (originDtype != at::ScalarType::Float) {
if (originDtype != at::kFloat) {
// detsCast = NPUNativeFunctions::npu_dtype_cast(dets, at::kFloat);
// scoresCast = NPUNativeFunctions::npu_dtype_cast(scores, at::kFloat);
detsCast = detsCast.to(at::ScalarType::kFloat);
scoresCast = scoresCast.to(at::ScalarType::kFloat);
detsCast = detsCast.to(at::kFloat);
scoresCast = scoresCast.to(at::kFloat);
}
c10::SmallVector<int64_t, SIZE> selectedIndexSize = {dets.size(0)};
// at::Tensor selectedBox = OpPreparation::ApplyTensor(dets);
Expand All @@ -33,6 +33,6 @@ Tensor nms_rotated_npu(const Tensor dets, const Tensor scores,
.Attr("iou_threshold", (float)iou_threshold)
.Run();
// selectedIndex = NPUNativeFunctions::npu_dtype_cast(selectedIndex, at::kLong);
selectedIndex = selectedIndex.to(at::ScalarType::kLong);
selectedIndex = selectedIndex.to(at::kLong);
return selectedIndex;
}

0 comments on commit 6d34074

Please sign in to comment.