Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backends/npu/kernels/scale_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ template <typename T, typename Context>
void ScaleKernel(const Context& dev_ctx,
const phi::DenseTensor& x,
const phi::Scalar& in_scale,
float bias,
const phi::Scalar& in_bias,
bool bias_after_scale,
phi::DenseTensor* out) {
auto scale = in_scale.to<float>();
auto bias = in_bias.to<float>();
auto stream = dev_ctx.stream();
float power = 1.0;
VLOG(4) << "scale:" << scale << ", bias:" << bias
Expand Down
27 changes: 16 additions & 11 deletions backends/npu/tests/unittests/test_expand_v2_op_npu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

from tests.op_test import OpTest
import paddle.base as base
from paddle.base import Program, program_guard
from paddle.framework import in_pir_mode
from paddle.pir_utils import test_with_pir_api
import paddle

paddle.enable_static()
Expand Down Expand Up @@ -262,18 +263,22 @@ def setUp(self):


class TestExpandV2Error(unittest.TestCase):
@test_with_pir_api
def test_errors(self):
with program_guard(Program(), Program()):
x1 = base.create_lod_tensor(
np.array([[-1]]), [[1]], paddle.CustomPlace("npu", 0)
)
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
shape = [2, 2]
self.assertRaises(TypeError, paddle.tensor.expand, x1, shape)
x2 = paddle.static.data(name="x2", shape=[-1, 2], dtype="uint8")
self.assertRaises(TypeError, paddle.tensor.expand, x2, shape)
x3 = paddle.static.data(name="x3", shape=[-1, 2], dtype="bool")
x3.stop_gradient = False
self.assertRaises(ValueError, paddle.tensor.expand, x3, shape)
if not in_pir_mode():
x1 = base.create_lod_tensor(
np.array([[-1]]), [[1]], paddle.CustomPlace("npu", 0)
)
self.assertRaises(TypeError, paddle.tensor.expand, x1, shape)
x2 = paddle.static.data(name="x2", shape=[-1, 4], dtype="bool")
x2.stop_gradient = False
self.assertRaises(ValueError, paddle.tensor.expand, x2, shape)
x2.stop_gradient = True
self.assertRaises(TypeError, paddle.tensor.expand, x2, 1)


# Test python API
Expand Down
1 change: 1 addition & 0 deletions backends/npu/tests/unittests/test_transpose_op_npu.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def test_api_dygraph(self):
x_grad_expect = x.grad

# fwd and bwd with storage format
paddle.base.set_flags({"FLAGS_use_stride_kernel": False})
x_format = paddle.incubate._npu_identity(x, self.format)
x_format.stop_gradient = False
out_format = paddle.transpose(x_format, axis)
Expand Down