昇腾社区首页
中文
注册

aclnnMultiScaleDeformableAttentionGrad

支持的产品型号

  • Atlas A2训练系列产品/Atlas 800I A2推理产品。

接口原型

每个算子分为undefined,必须先调用“aclnnMultiScaleDeformableAttentionGradGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnMultiScaleDeformableAttentionGrad”接口执行计算。

  • aclnnStatus aclnnMultiScaleDeformableAttentionGradGetWorkspaceSize(const aclTensor *value, const aclTensor *spatialShape, const aclTensor *levelStartIndex, const aclTensor *location, const aclTensor *attnWeight, const aclTensor *gradOutput, aclTensor *gradValue, aclTensor *gradLocation, aclTensor *gradAttnWeight, uint64_t *workspaceSize, aclOpExecutor **executor)
  • aclnnStatus aclnnMultiScaleDeformableAttentionGrad(void *workspace, uint64_t workspaceSize, aclOpExecutor *executor, aclrtStream stream)

功能描述

  • 功能描述: MultiScaleDeformableAttention正向算子功能主要通过采样位置(sample location)、注意力权重(attention weights)、映射后的value特征、多尺度特征起始索引位置、多尺度特征图的空间大小(便于将采样位置由归一化的值变成绝对位置)等参数来遍历不同尺寸特征图的不同采样点。而反向算子的功能为根据正向的输入对输出的贡献及初始梯度求出输入对应的梯度。

aclnnMultiScaleDeformableAttentionGradGetWorkspaceSize

  • 参数说明

    • value(aclTensor*, 计算输入):特征图的特征值,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,shape为(bs, spatial_size, mum_heads, channels),支持undefinedundefined支持ND
    • spatialShape(aclTensor*, 计算输入):存储每个尺度特征图的高和宽,Device侧的aclTensor,数据类型支持INT32、INT64,shape为(num_levels, 2),支持undefinedundefined支持ND
    • levelStartIndex(aclTensor*, 计算输入):每张特征图的起始索引,Device侧的aclTensor,数据类型支持INT32、INT64,shape为(num_levels,),支持undefinedundefined支持ND
    • location(aclTensor*, 计算输入):采样点位置tensor,存储每个采样点的坐标位置,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,shape为(bs, num_queries, num_heads, num_levels, num_points, 2),支持undefinedundefined支持ND
    • attnWeight(aclTensor, 计算输入):采样点权重tensor,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,shape为(bs, num_queries, num_heads, num_levels, num_points),支持undefinedundefined支持ND
    • gradOutput(aclTensor*, 计算输入):正向输出梯度,也是反向算子的初始梯度,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,shape为(bs, num_queries, num_heads, channels),支持undefinedundefined支持ND
    • gradValue(aclTensor, 计算输出):输入value对应的梯度,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,shape为(bs, spatial_size, mum_heads, channels),支持undefinedundefined支持ND
    • gradLocation(aclTensor*, 计算输出):输入location对应的梯度,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,shape为(bs, num_queries, num_heads, num_levels, num_points, 2),支持undefinedundefined支持ND
    • gradAttnWeight(aclTensor*, 计算输出):输入attnWeight对应的梯度,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,shape为(bs, num_queries, num_heads, num_levels, num_points),支持undefinedundefined支持ND
    • workspaceSize(uint64_t*, 出参):返回需要在Device侧申请的workspace大小。
    • executor(aclOpExecutor**, 出参):返回op执行器,包含了算子计算流程。
  • 返回值

    aclnnStatus:返回状态码,具体参见undefined

    [object Object]

aclnnMultiScaleDeformableAttentionGrad

  • 参数说明

    • workspace(void*, 入参):在Device侧申请的workspace内存地址。
    • workspaceSize(uint64_t, 入参):在Device侧申请的workspace大小,由第一段接口aclnnMultiScaleDeformableAttentionGradGetWorkspaceSize获取。
    • executor(aclOpExecutor*, 入参):op执行器,包含了算子计算流程。
    • stream(aclrtStream, 入参):指定执行任务的 AscendCL Stream流。
  • 返回值

    aclnnStatus:返回状态码,具体参见undefined

约束与限制

channels + num_points + num_level <= 512 channels % 8 == 0,且channels<=256 num_queries < 500000 num_level < 10 bs <= 32

调用示例

示例代码如下,仅供参考,具体编译和执行过程请参考undefined

[object Object]