-
Notifications
You must be signed in to change notification settings - Fork 88
Open
Description
我能理解这个项目是通过AST以及Matcher的机制来实现
但其实目前而言这种转换的话,我觉得直接通过AI来实现可能会更加的实际
还可以尽可能的避免转换中出现的问题,包括减少需要自行调整的情况
`import paddle
class MyNet(paddle.nn.Layer):
test = "str"
def __init__(self, num_classes=10):
super(MyNet, self).__init__()
# 将 mmcv.cnn.ConvModule(4, 6, (3, 3)) 替换为等价的 Conv2D
# ConvModule 在未指定 norm/act 时等价于一个裸 conv
self._conv = paddle.nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3, 3))
self._pool = paddle.nn.MaxPool2D(kernel_size=2, stride=1)
# 线性层保持一致
self._fc1 = paddle.nn.Linear(in_features=6 * 25 * 25, out_features=120)
self._fc2 = paddle.nn.Linear(in_features=120, out_features=84)
self._fc3 = paddle.nn.Linear(in_features=84, out_features=num_classes)
def forward(self, x):
x = self._conv(x)
x = self._pool(x)
x = self._fc1(paddle.flatten(x=x, start_axis=1))
x = self._fc2(x)
x = self._fc3(x)
y = paddle.add(x=x, y=x)
return y
net = MyNet()
sgd = paddle.optimizer.SGD(parameters=net.parameters(), learning_rate=0.01, weight_decay=0.0)
tmp_lr = paddle.optimizer.lr.MultiStepDecay(milestones=[2, 4, 6], gamma=0.8, learning_rate=sgd.get_lr())
sgd.set_lr_scheduler(tmp_lr)
lr = tmp_lr
for i in range(10):
x = paddle.rand(shape=[8, 4, 28, 28])
out = net(x).sum()
sgd.clear_gradients(set_to_zero=False)
out.backward()
sgd.step()`
这是使用github上的copilot实现的转换,对比之下没有任何的问题
Metadata
Metadata
Assignees
Labels
No labels