-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[Hackathon No.5] tril_indices OP #41639
Conversation
merge tril_indices cpu op
resolve conflict
add tril_indices test
cpu tril_indices version
✅ This PR's description meets the template requirements! |
你的PR提交成功,感谢你对开源项目的贡献! |
modify english document modify english document modify document modify document
paddle/phi/infermeta/nullary.cc
Outdated
void TrilIndicesInferMeta( | ||
int rows, int cols, int offset, DataType dtype, MetaTensor* out) { | ||
// number of elements in the first row of the tril,bounded by [0, cols] | ||
auto m_first_row = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use n_first_row
is better? the form of variable name is unified with n_row_all
and n_row_trapezoid
below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
paddle/phi/infermeta/nullary.cc
Outdated
auto m_first_row = | ||
offset > 0 ? std::min<int64_t>(cols, 1 + offset) : rows + offset > 0; | ||
// number of elements in the last row of the tril, bounded by [0, cols] | ||
auto m_last_row = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use n_last_row
is better? the form of variable name is unified with n_row_all
and n_row_trapezoid
below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
python/paddle/tensor/creation.py
Outdated
@@ -1739,3 +1739,92 @@ def complex(real, imag, name=None): | |||
attrs = {} | |||
helper.append_op(type=op_type, inputs=inputs, attrs=attrs, outputs=outputs) | |||
return out | |||
|
|||
|
|||
def tril_indices(rows, cols, offset=0, dtype='int64'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里参数名用单数稍好一些,rows -> row, cols -> col
复数一般用来表示列表,比如,slice这个api中,axes, starts, ends都是用来接受列表的输入
https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/slice_cn.html#slice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
expected_result = np.tril_indices(4, 2) | ||
self.assertEqual((out.numpy() == expected_result).all(), True) | ||
|
||
def test_default_CPU(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测默认值就不分CPU和GPU吧,节省一点case时间,目前有单测超时的可能(15s)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改,但是对测试总时间影响不大
with paddle.static.program_guard(paddle.static.Program(), | ||
paddle.static.Program()): | ||
data1 = paddle.tril_indices(4, 4, -1) | ||
exe1 = paddle.static.Executor(place) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
每个case测一个值就可以,或者静态图 为 正offset,动态图为 负offset,节省一些单测时间
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看下超时能不能过吧,如果还超时,那就需要再继续减少case了,目前不允许单测超过15s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New features
PR changes
OPs
Describe
add tril_indices CPU kernel python API and unit test
fix issue:#40330
RFC https://github.com/PaddlePaddle/community/blob/master/rfcs/APIs/20220323_api_design_for_tril_indices.md
中文文档PR PaddlePaddle/docs#4599