Skip to content

Conversation

@paddle-bot
Copy link

paddle-bot bot commented Oct 30, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请检查PR提交格式和内容是否完备,具体请参考示例模版
Your PR has been submitted. Thanks for your contribution!
Please check its format and content. For this, you can refer to Template and Demo.

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.

整体方案 OK,顺师傅太牛了!


```

在 `BuildExtension` 类中添加了 `_generate_python_api_file` 和 `custom_write_stub` 方法之后,实际上 `extension_utils.py` 中的 `bootstrap_context` 已经不需要了,因为每次 `BuildExtension` 都会执行构建,但是建议先保留 `bootstrap_context` 以防其他兼容性问题 (比如外部用户使用等):
Copy link
Member

Choose a reason for hiding this comment

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

走不到的逻辑建议还是清理一下吧,按我理解现在是不走 bdist_egg 了是么?

Copy link
Contributor Author

@megemini megemini Nov 8, 2025

Choose a reason for hiding this comment

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

嗯~ 我测试是不需要了~ 因为 BuildExtension 的 _generate_python_api_file 会主动调用 custom_write_stub ~ 而 extension_utils.py 中的


@contextmanager
def bootstrap_context():
    """
    Context to manage how to write `__bootstrap__` code in .egg
    """
    origin_write_stub = bdist_egg.write_stub
    bdist_egg.write_stub = custom_write_stub
    yield

    bdist_egg.write_stub = origin_write_stub

也没看到其他地方有用到 ~

总结:

- 增加兼容 `pip install .` 的方式安装
- 增加兼容 `pip install .` 的方式安装之后,实际上已经解决了 setuptools 版本的兼容性问题,不需要针对 setuptools 的版本再进行判断
Copy link
Member

Choose a reason for hiding this comment

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

合理的方案,之前我也在考虑同时维护两套总是会有冗余的代码


```

改动之后,测试用例中需要修改 `len(custom_egg_path) == 2` 。
Copy link
Member

@SigureMo SigureMo Nov 7, 2025

Choose a reason for hiding this comment

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

我看了下前后的目录结构,目前认为是合理的

修改前,setuptools 79:

`-- mix_relu_extension-0.0.0-py3.10-linux-x86_64.egg
    |-- EGG-INFO
    |   |-- PKG-INFO
    |   |-- SOURCES.txt
    |   |-- dependency_links.txt
    |   |-- native_libs.txt
    |   |-- not-zip-safe
    |   `-- top_level.txt
    |-- mix_relu_extension.py
    |-- mix_relu_extension_pd_.so
    `-- version.txt

修改后,无论 setuptools 79 还是 80 都生成如下结构的代码

|-- mix_relu_extension
|   |-- __init__.py
|   `-- mix_relu_extension_pd_.so
`-- mix_relu_extension-0.0.0-py3.10.egg-info
    |-- PKG-INFO
    |-- SOURCES.txt
    |-- dependency_links.txt
    |-- not-zip-safe
    `-- top_level.txt

修改前相当于一个目录既包含包信息也包含包实现,修改后两者分成两个目录了,都是合理的

这部分说明我觉得可以补充在 RFC 里

## 可行性分析

1. **技术可行性**:方案基于 setuptools 的标准扩展机制,技术上完全可行
2. **兼容性风险**:通过条件判断确保兼容 80.0- 的 Setuptools
Copy link
Member

Choose a reason for hiding this comment

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

这里应该不需要判断了?

这里可以说明下是否影响已经生成的算子的加载,加载链路里的包结构与之前一致,应该不影响

另一方面是写好的代码是否需要修改构建系统(setup.py)以及是否需要修改算子注册逻辑,这里也是不影响的

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 🐾

@luotao1 luotao1 merged commit 647869c into PaddlePaddle:master Nov 17, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants