Skip to content

请问一下topk算子的sorted参数 #71019

Closed
@houj04

Description

@houj04

请提出你的问题 Please ask your question

文档中是这样写的:

https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/topk_cn.html

sorted (bool,可选) - 控制返回的结果是否按照有序返回,默认为 True。在 GPU 上总是返回有序的结果。

https://www.paddlepaddle.org.cn/documentation/docs/en/develop/api/paddle/topk_en.html

sorted (bool, optional) – controls whether to return the elements in sorted order, default value is True. In gpu device, it always return the sorted value.

按照上面的说明,我理解是这样:不管这个参数传进来的是true还是false,内部一律当做true处理,即,返回的结果始终是有序的。

但是看代码实现,内部似乎根据sorted这个参数,进行了判断,并不是直接忽略这个参数。
https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/phi/kernels/gpu/top_k_kernel.cu
Image

想问一下这个是符合预期的吗?

我之所以要问这个问题,背景是:我在实现某个硬件设备上的topk算子。当sorted参数为true的时候,语义很明确,排序之后输出即可。但是当sorted参数为false的时候,我应该如何输出呢?是可以仍然按照排序之后的输出,还是必须打乱顺序输出?直观上感觉是,不管是否sorted,都按照排序之后的输出即可。所以想确认一下。

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions