-
Notifications
You must be signed in to change notification settings - Fork 0
Fix int32 overflow issues for large tensor support in paddle/phi/kernels/impl #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ecision.…" (PaddlePaddle#75972) This reverts commit 945ea69.
…` and expose `IS_WINDOWS` to `paddle.utils.cpp_extension` (PaddlePaddle#75976)
* support md5 checksum * fix build * fix build * fix build * fix build * dump the md5 check sum to file * fix err * add switch and full support md5 * add flags to control precision and refine test * rm useless commit * add ut * add ut
* fix typo disable_loggling -> disable_logging * fix * fix
* clean get_cuda_version < 8100 * fix
…ient_attention.py (PaddlePaddle#75600) * clean get_cuda_version() < 11020 in test_variable_length_memory_efficient_attention.py * fix
… tests (PaddlePaddle#75948) - 在 test_tensorrt_engine_instruction.cc 里,原先直接用 TensorRT 的 `FullyConnected` 层,现在改成手工搭建 Shuffle → Constant → MatrixMultiply → ElementWise → Shuffle 的子网,等价地实现带 bias 的全连接。这样做主要是规避 TensorRT 里旧版 FC 层的限制,并能更清楚地控制动态形状和推理流程。 - 每一步都补充了更具体的 `PADDLE_ENFORCE_NOT_NULL` 抛错信息,比如提示 reshape、常量层、矩阵乘、加法等各环节可能失败的原因,便于在引擎生成失败时快速定位问题。 - 针对 TensorRT 8.6 之后 `ICudaEngine` API 的变化,新增了 `IS_TRT_VERSION_GE(8600)` 的分支,在新老版本之间分别检查 `getNbIOTensors()` 或 `getNbBindings()`,保证测试在不同 TensorRT 版本下都能正确校验。 - 动态 shape 的测试把 Shuffle 失败时的报错信息改得更精准,明确指出是运行时 shape 绑定的问题。 - 插件测试同样完善了插件创建、层加入失败时的提示,并加入了前述的 TensorRT 版本兼容检查,使调试自定义插件时的可诊断性更好。
* 1013 * 1015 * 1015 * 1015 * 1015 * 1015 * 1016 * 1016 * 1017
…dlePaddle#75937) * Revert test_activation_op.py to fix bug caused by commit deed9d3 * fix: Update max_relative_error in TestSigmoid_Complex64 to improve gradient checking accuracy
* 1012 * 1014 * 1014 * 1016 * 1016 * 1017 * 1017 * 1018 * 1018
* 1012 * 1012 * 1020
* add tensorrt 10 support int64 * fix
* clean pip3.8 in Dockerfile.develop.npu * fix * fix
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
|
@copilot 描述使用中文,并且加入TODO列表。对于部分没有条件支持bit tensor的地方,添加报错信息指明这里不支持。 |
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
已完成以下修改(提交 f1d21ba):
对于底层实现仍使用 示例验证检查: PADDLE_ENFORCE_LE(
N * C * H * W,
std::numeric_limits<int>::max(),
common::errors::InvalidArgument(
"The total number of elements (N*C*H*W = %ld) exceeds the maximum "
"value that int can represent (%d). LRN operation does not support "
"such large tensors yet.",
N * C * H * W,
std::numeric_limits<int>::max())); |
|
@copilot 继续完成impl文件夹下的内容 |
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
正在继续完成 impl 文件夹的修复工作。 已完成的进展(提交 91b6c2f, ef6cb1a, 80e2535): 已修复 27 个文件(占 impl 目录的 64%),共 72 处 int32 溢出问题: 最新修复的文件:
剩余工作(约 15 个文件,75 处修复):
继续修复中... |
Co-authored-by: zrr1999 <46243324+zrr1999@users.noreply.github.com>
修复 paddle/phi/kernels/impl 中的 int32 溢出问题以支持大张量
概述
本 PR 解决了
paddle/phi/kernels/impl目录中的 int32 溢出问题,以改进对大张量(超过 20 亿元素)的支持。这是修复 PaddlePaddle 代码库中 int32 溢出漏洞的系统性工作的第 3 阶段。背景
之前阶段已完成:
paddle/phi/kernels/funcs目录 ✓paddle/phi/kernels/gpu目录 ✓大张量可能在以下常见模式中导致整数溢出:
tensor.numel()返回int64_t,但赋值给int时会对超过 20 亿元素的张量进行截断blockIdx.x * blockDim.x可能溢出int32INT32_MAX(例如,具有 30 亿元素的 1D 张量的dims[0] = 30 亿)已完成的修改
在 30 个文件中修复了 85 处潜在的 int32 溢出,并添加了大张量验证检查:
已修改的文件
应用的修复模式
1. CUDA 线程索引
2. 张量元素计数
3. 维度访问
4. 函数签名
5. 大张量验证检查
TODO 列表
impl 目录(剩余 12 个文件,约 62 处修复)
复杂文件(需要仔细审查):
简单文件(仅 dims[] 模式):
cpu 目录(约 361 处修复)
其他子目录(约 868 处修复)
测试
范围
本 PR 完成了 impl 目录的 71%(42 个文件中的 30 个)。剩余工作包括:
paddle/phi/kernels/impl中的 12 个文件(约 62 处修复)paddle/phi/kernels/cpu目录(约 361 处修复)项目总范围:约 200 个文件中的约 1,376 处潜在修复
影响
这些更改使 PaddlePaddle 能够安全处理超过 20 亿元素的张量,而不会出现整数溢出错误或静默数据损坏。这些修复向后兼容,在扩展对大张量工作负载的支持的同时保持现有的 API 契约。
大张量支持限制
某些操作的底层实现(如 LRN GPU 内核)仍然使用
int参数。在这些情况下,已添加运行时验证检查,如果张量大小超过INT32_MAX,将抛出清晰的错误消息。这些检查标记为TODO(large-tensor),表示需要在未来更新底层实现以完全支持大张量。Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.