Closed
[Bug-Report|缺陷反馈]: lrelu 参数转发、异常源码位置清理、历史目录保留及 argsort 默认值文档问题 #3685
AidenAdd on  Oct 28Closed at  29 days ago
Aiden
Aiden
Oct 28 Create

Describe the current behavior / 问题描述 (Mandatory / 必填)

1. Tensor.lrelu 参数转发及输入参数名不一致

python/pypto/tensor.py 中的成员方法多声明了 other,并将三个位置参数转发给只接收两个参数的 pypto.lrelu:

def lrelu(self, other: 'Tensor', negative_slope=0.01):
    return pypto.lrelu(self, other, negative_slope)

默认调用缺少必填的 other;传入位置斜率时又会向底层传递多余参数,成员方法无法正常使用。

python/pypto/op/math.py 中 pypto.lrelu 首参数名为 other,中文文档为 input,docstring 为 a。按文档使用 input= 关键字会失败,斜率默认值的注释也未准确表达 0.01。

2. 异常后源码位置状态未清理

op_wrapper 和 source_location 在 set_source_location() 与 clear_source_location() 之间没有使用 try/finally。被包装函数抛异常后,深度计数器未恢复,后续算子沿用旧 span,报错位置指向之前失败的调用点。

涉及 python/pypto/_op_wrapper.py、python/pypto/_utils.py。

3. 历史目录清理误删最新目录

framework/src/utils/file_utils.cpp 中 RemoveOldDirectories(path, prefix, kept) 按修改时间升序排列,再从下标 kept 开始删除,导致保留最旧的目录、删除最新的目录。

CreateRunDataDir 以 kept=127 调用;目录超过保留上限时,最近运行的 rundata 和 dump 数据可能被删除。

4. argsort 文档默认值与实现不一致

docs/zh/api/tensor_api/operation/pypto-argsort.md 将 descending 默认值写为 True,但 python/pypto/op/comparison.py 实现的默认值为 False。用户按文档理解默认降序,实际获得升序索引。

Environment / 环境信息 (Mandatory / 必填)

  • 硬件:Ascend 910C
  • PyPTO:0.3.0
  • CANN:9.2.0
  • Python:3.11.4
  • 操作系统:Ubuntu 20.04.5 LTS aarch64

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

  1. Tensor.lrelu 移除多余的 other 参数,仅向底层传递当前张量和 negative_slope。默认调用、位置参数调用及关键字参数调用均可正常使用;pypto.lrelu 输入参数名统一为 input,实现、docstring 和文档保持一致,默认斜率明确为 0.01。
  2. op_wrapper 和 source_location 均通过 try/finally 保证源码位置状态清理,异常正常向上传播。最外层调用结束后深度恢复为 0,后续算子使用自身调用位置。
  3. RemoveOldDirectories 保留修改时间最新的 kept 个匹配目录,删除较旧目录;不匹配前缀的目录及普通文件不受影响。正确处理 kept=0、等于目录数及大于目录数等边界情况。
  4. argsort 中文文档原型、参数说明和 Python docstring 均明确 descending=False,默认按升序返回索引。

Describe the expected behavior / 预期结果 (Mandatory / 必填)

  • Tensor.lrelu 移除多余的 other 参数,仅向底层传递当前张量和 negative_slope。默认调用、位置参数调用及关键字参数调用均可正常使用;pypto.lrelu 输入参数名统一为 input,实现、docstring 和文档保持一致,默认斜率明确为 0.01。
  • op_wrapper 和 source_location 均通过 try/finally 保证源码位置状态清理,异常正常向上传播。最外层调用结束后深度恢复为 0,后续算子使用自身调用位置。
  • RemoveOldDirectories 保留修改时间最新的 kept 个匹配目录,删除较旧目录;不匹配前缀的目录及普通文件不受影响。正确处理 kept=0、等于目录数及大于目录数等边界情况。
  • argsort 中文文档原型、参数说明和 Python docstring 均明确 descending=False,默认按升序返回索引。

1. lrelu 调用错误

TypeError: Tensor.lrelu() missing 1 required positional argument: 'other'
pypto.error.FeError: ErrCode: F00001

按照文档使用 input= 关键字调用:

TypeError: lrelu() got an unexpected keyword argument 'input'

2. 异常后源码位置状态残留

depth : 0
op span: 21
caught : simulated kernel failure
depth : 1
op span: 35

异常后深度由 0 变为 1,后续正常算子的 span 从自身调用行 21 变为失败调用行 35。

3. 历史目录清理结果

surviving rundata dirs : 127 (expected 127)
newest dir exists      : NO
newest marker exists   : NO
unrelated dir intact   : YES
plain file intact      : YES
VERDICT: BUG - kept the OLDEST 127 dirs and deleted the newest 3

4. argsort 默认值差异

文档:descending: bool=True
实现:descending: bool=False

Special notes for this issue/备注 (Optional / 选填)

对应修复 PR:#7206。

likedislike
AidenAiden
Oct 28 Associated pull request
袁野袁野Collaborators
Oct 29 Assign tsungl4 as responsible person
袁野袁野Collaborators
Oct 29 Assign chen_chenn as responsible person
袁野袁野Collaborators
Oct 29 Assign songle1 as responsible person
袁野
袁野Collaborators
Oct 29 Comments:

@tsungl4 @songle1 涉及API、公共框架以及文档,请关注并审核下,谢谢

likedislike
AidenAiden
29 days ago changed custom state from 进行中 to 已完成
AidenAiden
29 days ago Close issue
AidenAiden
29 days ago changed custom state from 已完成 to 已解决
CANN-robotCANN-robotCollaborators
29 days ago Added label: resolved