Skip to content

Conversation

@roll-away
Copy link
Contributor

PR Category

Feature Enhancement

Description

Unittest: add graph_net/torch/unittest/test_ast_renamer.py

@paddle-bot
Copy link

paddle-bot bot commented Dec 24, 2025

Thanks for your contribution!

Comment on lines +13 to +34
self.test_root = Path(tempfile.mkdtemp())
self.src_repo = self.test_root / "src_repo"
self.dst_workspace = self.test_root / "workspace"
self.src_repo.mkdir()
self.dst_workspace.mkdir()

self.rel_model_path = "samples/demo_model"
self.full_src_path = self.src_repo / self.rel_model_path
self.full_src_path.mkdir(parents=True)

(self.full_src_path / "model.py").write_text(
textwrap.dedent(
"""
import torch
class GraphModule(torch.nn.Module):
def forward(self, x_data, L__self___weight):
res = x_data + L__self___weight
L__self___weight = None
return res
"""
)
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里搞复杂了。你直接在旁边目录里整一个小样本就行。

Comment on lines +82 to +85
self.assertIn("in_0", new_code, "x_data 应该被识别为 in_0")
self.assertIn("w_0", new_code, "L__self___weight 应该被识别为 w_0")
self.assertIn("tmp_0", new_code, "中间变量 res 应该被重命名为 tmp_0")
self.assertNotIn("None", new_code, "权重清理语句应被 AST 转换器删除")
Copy link
Collaborator

Choose a reason for hiding this comment

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

这地方都搞复杂了,应该用非常简单的file check。读取两个文件,然后一对比。

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.

2 participants