openvino icon indicating copy to clipboard operation
openvino copied to clipboard

【Hackathon 6th No.43】add paddle tril_triu

Open Asthestarsfalll opened this issue 2 years ago • 2 comments

Details:

add paddle tril and triu

Reference

Code: https://github.com/PaddlePaddle/Paddle/blob/release/2.6/python/paddle/tensor/creation.py#L1431 Support data type: int32, int64, float32, float64, float16, complex64, complex128 (openvino do not support float64, float16, complex64 complex128)

Python simulation code

import paddle

a = paddle.randn((3, 4))


def func(x, diagonal=0, mode='triu'):
    h, w = x.shape
    horizontal_range = paddle.arange(0, w)
    horizontal_range = paddle.unsqueeze(horizontal_range, 0)
    vertical_range = paddle.arange(0, h)
    vertical_range = paddle.unsqueeze(vertical_range, 1)
    if diagonal != 0:
        vertical_range += diagonal
    if mode == 'triu':
        mask = horizontal_range >= vertical_range
    else:
        mask = horizontal_range <= vertical_range
    print(mask)
    return paddle.where(mask, x, paddle.zeros_like(x))


def tril(x, diagonal=0):
    return func(x, diagonal, 'tril')

def triu(x, diagonal=0):
    return func(x, diagonal, 'triu')



b = paddle.tril(a, -1)
c = tril(a, -1)
print(b)
print(c)
print((b==c).mean())

Test

240411_19h35m47s_screenshot

waiting for:

  • https://github.com/openvinotoolkit/openvino/pull/23010

Asthestarsfalll avatar Apr 11 '24 12:04 Asthestarsfalll

@meiyang-intel Could you please take a look?

Asthestarsfalll avatar Apr 23 '24 07:04 Asthestarsfalll

@meiyang-intel @ilya-lavrenov Could you please take a look?

Asthestarsfalll avatar May 10 '24 07:05 Asthestarsfalll

@ilya-lavrenov , could you help build jenkins?

meiyang-intel avatar May 21 '24 10:05 meiyang-intel

build_jenkins

ilya-lavrenov avatar May 21 '24 14:05 ilya-lavrenov