2.4K Star 8.2K Fork 4.4K

GVPMindSpore / mindspore

 / 详情

[Bug] Unstable results in sin/arcsin/arccos calls

VALIDATION
Bug-Report
创建于  
2024-04-11 16:50
name about labels
Bug Report Use this template for reporting a bug kind/bug

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

I once reproduced a bug in Pytroch, and when I converted the Pytroch method to the mindspore method, I found that the problem still existed. This problem was identified as a bug in Pytroch.
I get unstable results when sin, arcsin, arccos are called sequentially. sin followed by arcsin should give by the same value, however the calculation is not exactly the same and we get unstable results after arccos: 0.00034527 on CPU and nan on GPU.

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

  • Hardware Environment(Ascend/GPU/CPU) / 硬件环境:

Please delete the backend not involved / 请删除不涉及的后端:
/device GPU/CPU

  • Software Environment / 软件环境 (Mandatory / 必填):
    -- MindSpore version (e.g., 1.7.0.Bxxx) : 2.2.13
    -- Python version (e.g., Python 3.7.5) : 3.8.10
    -- OS platform and distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 22.04
    -- GCC/Compiler version (if compiled from source): 7.5.0

  • Excute Mode / 执行模式 (Mandatory / 必填)(PyNative/Graph):

Please delete the mode not involved / 请删除不涉及的模式:
/mode pynative
/mode graph

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

from mindspore import set_context
import mindspore.ops as ops

set_context(device_target="CPU")
x = ops.ones(2)
y = ops.sin(x)
y = ops.arcsin(y) 
y = ops.arccos(y)
print(y)  # gives [0.00034527 0.00034527]

set_context(device_target="GPU")
y1 = ops.sin(x)
y1 = ops.arcsin(y1) 
y1 = ops.arccos(y1)
print(y1) # gives [nan nan] should be [0,0]

输入图片说明

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

[0,0]

评论 (7)

Redempt1onzzZZ 创建了Bug-Report

Please assign maintainer to check this issue.
请为此issue分配处理人。
@fangwenyi @chengxiaoli @Shawny

感谢您的提问,您可以评论//mindspore-assistant更快获取帮助:

  1. 如果您刚刚接触MindSpore,或许您可以在教程找到答案
  2. 如果您是资深Pytorch用户,您或许需要:
  1. 如果您遇到动态图问题,可以设置set_context(pynative_synchronize=True)查看报错栈协助定位
  2. 模型精度调优问题可参考官网调优指南
  3. 如果您反馈的是框架BUG,请确认您在ISSUE中提供了MindSpore版本、使用的后端类型(CPU、GPU、Ascend)、环境、训练的代码官方链接以及可以复现报错的代码的启动方式等必要的定位信息
  4. 如果您已经定位出问题根因,欢迎提交PR参与MindSpore开源社区,我们会尽快review
i-robot 添加了
 
github
标签
Shawny 负责人设置为gaoshuanglong
Shawny 关联项目设置为MindSpore Issue Assistant
Shawny 计划开始日期设置为2024-04-11
Shawny 计划截止日期设置为2024-05-11
Shawny 添加了
 
mindspore-assistant
标签
Shawny 添加了
 
sig/ops
标签

@Redempt1onzzZZ
Thanks for your report, I don't think it's a problem in mindspore.
I suggest you replace float32 dtype with float64 dtype and the problem will be solved.
This is the result of float64:
输入图片说明

I analyzed the root cause of the problem: The precision of float32 affects the calculation result.
when your input dtype is float32,
step1: sin([1., 1.]) output is [0.841471 0.841471], there's a reasonable floating point error here(If you use a higher precision type float64, the output is [0.84147098 0.84147098]).
You can also use a high-precision calculator to verify:
输入图片说明
step2: arcsin([0.841471 0.841471]) output is [1.0000001 1.0000001]. The calculation result of step2 is > 1 due to step1 reasonable error.
setp3: arccos([1.0000001 1.0000001]) output is [nan nan]. When arccos input > 1, return 'nan' is correct.

i-robot 添加了
 
foruda
标签
i-robot 添加了
 
foruda
标签
gaoshuanglong 任务状态TODO 修改为ACCEPTED
gaoshuanglong 任务状态ACCEPTED 修改为WIP
gaoshuanglong 任务状态WIP 修改为VALIDATION

Thank you for your reply!

您好,由于问题单没有回复,我们后续会关闭,如您仍有疑问,可以反馈下具体信息,并将ISSUE状态修改为WIP,我们这边会进一步跟踪,谢谢

您好,由于问题单没有回复,我们后续会关闭,如您仍有疑问,可以反馈下具体信息,并将ISSUE状态修改为WIP,我们这边会进一步跟踪,谢谢

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(3)
14289818 redempt1onzz 1712823588
Python
1
https://gitee.com/mindspore/mindspore.git
git@gitee.com:mindspore/mindspore.git
mindspore
mindspore
mindspore

搜索帮助

344bd9b3 5694891 D2dac590 5694891