Skip to content

Conversation

@DrRyanHuang
Copy link
Contributor

@DrRyanHuang DrRyanHuang commented Aug 22, 2025

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

torch 的 cumsum 函数,dtype 不为 None 时,会指定输出类型

import torch

x_int32 = torch.randint(1, 20, (10,)).int()
y = torch.cumsum(x_int32, dim=0, dtype=torch.int)
print(y.dtype) # torch.int32

#74625 引入后,导致 dtype 非 None 时,只要输入是 int (及其衍生类型),便会自动转化为 int64,显然不合理
导致 FastDeploy 运行 ERNIE 4.5 Turbo 系列模型全部挂掉

if dtype is not None and x.dtype != convert_np_dtype_to_dtype_(dtype):
x = cast(x, dtype)
elif isinstance(x, paddle.Tensor) and x.dtype in [
paddle.uint8,
paddle.int8,
paddle.int16,
paddle.int32,
]:
x = cast(x, "int64")

Paddle 测试代码:

import paddle
from paddle.framework import convert_np_dtype_to_dtype_

seq_lens_this_time = paddle.randint(1, 128, (3,), dtype="int32")
cum_offsets_now = paddle.cumsum(128 - seq_lens_this_time, dtype='int32')

int32_type = convert_np_dtype_to_dtype_("int32")
assert cum_offsets_now.dtype == int32_type

@DrRyanHuang DrRyanHuang requested a review from SigureMo August 22, 2025 03:03
@paddle-bot
Copy link

paddle-bot bot commented Aug 22, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加一下单测

@DrRyanHuang DrRyanHuang requested a review from SigureMo August 22, 2025 08:26
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@2f156c7). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #74830   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         1           
  Lines              ?         6           
  Branches           ?         0           
===========================================
  Hits               ?         6           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

@SigureMo SigureMo merged commit 144df30 into PaddlePaddle:develop Aug 23, 2025
52 of 53 checks passed
@SigureMo SigureMo deleted the fix_cumsum branch August 23, 2025 08:38
Luckycheng222 pushed a commit to Luckycheng222/Paddle that referenced this pull request Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants