Skip to content
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

[fp16] suppot fp16 in diagflat #50945

Merged
merged 4 commits into from
Mar 1, 2023
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
23 changes: 23 additions & 0 deletions python/paddle/fluid/tests/unittests/test_diagflat.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ def test_gpu(self):
with paddle.static.program_guard(Program()):
self.run_static(use_gpu=True)

def test_fp16_with_gpu(self, use_gpu=False):
if paddle.fluid.core.is_compiled_with_cuda():
place = paddle.CUDAPlace(0)
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
input = np.random.random([10, 10]).astype("float16")
x = paddle.static.data(
name="x", shape=[10, 10], dtype="float16"
)

y = paddle.diagflat(x)
expected = np.diagflat(input)

exe = paddle.static.Executor(place)
res = exe.run(
paddle.static.default_main_program(),
feed={
"x": input,
},
fetch_list=[y],
)


if __name__ == "__main__":
unittest.main()
7 changes: 5 additions & 2 deletions python/paddle/tensor/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ def diagflat(x, offset=0, name=None):
If ``offset`` < 0, it is subdiagonal.

Args:
x (Tensor): The input tensor. It can be any shape. Its data type should be float32, float64, int32, int64.
x (Tensor): The input tensor. It can be any shape. Its data type should be float16, float32, float64, int32, int64.
offset (int, optional): The diagonal offset. A positive value represents superdiagonal, 0 represents the main diagonal, and a negative value represents subdiagonal. Default: 0 (main diagonal).
name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Expand Down Expand Up @@ -1577,7 +1577,10 @@ def diagflat(x, offset=0, name=None):
padding_value = 0
check_type(x, 'x', (Variable), 'diagflat')
check_dtype(
x.dtype, 'x', ['float32', 'float64', 'int32', 'int64'], 'diagflat'
x.dtype,
'x',
['float16', 'float32', 'float64', 'int32', 'int64'],
'diagflat',
)
check_type(offset, 'offset', (int), 'diagflat')

Expand Down