Skip to content

Conversation

@pengcheng888
Copy link
Contributor

@pengcheng888 pengcheng888 commented Nov 12, 2025

目标版本
main

功能描述
添加linear的实现,接口和测试

gpu测试
Screenshot from 2025-11-12 10-01-38

cpu测试
Screenshot from 2025-11-12 10-01-31

@pengcheng888 pengcheng888 self-assigned this Nov 12, 2025
@pengcheng888 pengcheng888 linked an issue Nov 12, 2025 that may be closed by this pull request
@pengcheng888 pengcheng888 changed the title issue/581 - 添加linear的实现,接口和测试 issue/581 - 添加python的linear的实现,接口和测试 Nov 12, 2025

Tensor linear(Tensor input,
Tensor weight,
pybind11::object bias) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

bias 不在外部转tensor吗

Copy link
Contributor Author

@pengcheng888 pengcheng888 Nov 14, 2025

Choose a reason for hiding this comment

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

Pyorch的接口中, bias可能是None 或 Tensor。 为了向pytorch那样,只使用一个函数处理这两种情况。 就使用object类作为类型了, 再c++中判断是否是None,再转换

Copy link
Contributor Author

Choose a reason for hiding this comment

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

回来修改: 从include中移除 pybind的头文件, 再加一个中间的函数处理none的情况

@Ceng23333
Copy link
Collaborator

可以把nn::module::Linear里的compute_linear替换成这个实现


def torch_operator(self, input, weight, bias, out=None, **kwargs):
"""PyTorch linear implementation"""
result = torch.nn.functional.linear(input, weight, bias)
Copy link
Collaborator

Choose a reason for hiding this comment

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

按照最新的写法改一下

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改


namespace py = pybind11;

namespace infinicore::ops::linear {
Copy link
Collaborator

Choose a reason for hiding this comment

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

不用再起一个namespace了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

@pengcheng888 pengcheng888 force-pushed the issue/581 branch 2 times, most recently from e6b047c to d11927b Compare November 17, 2025 04:49
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.

[DEV] 添加linear的实现和python接口

3 participants