siliconflow / onediff

OneDiff: An out-of-the-box acceleration library for diffusion models.
https://github.com/siliconflow/onediff/wiki
Apache License 2.0
1.61k stars 99 forks source link

oneflow compile error #880

Closed nono-Sang closed 2 months ago

nono-Sang commented 4 months ago

存在的问题:当 torch module 对象动态添加函数属性后,oneflow_compile 会失败。

例如:

class OneFlowModel(flow.nn.Module): def init(self): super().init() self.linear = flow.nn.Linear(2, 3)

def forward(self, x):
    return self.linear(x)

cls_key = transform_mgr.get_transformed_entity_name(PyTorchModel) transform_mgr.update_class_proxies({cls_key: OneFlowModel})

device = torch.device("cuda" if torch.cuda.is_available() else "cpu") pytorch_model = PyTorchModel().to(device)

of_model = oneflow_compile(pytorch_model)

x = torch.randn(1, 2).to(device) y_pt = pytorch_model(x) y_of = of_model(x)


* 添加一个函数属性后,失败。
```py
def torch_func():
    pass

pytorch_model.func = torch_func  ## 添加函数属性
of_model = oneflow_compile(pytorch_model)

x = torch.randn(1, 2).to(device)
y_pt = pytorch_model(x)
y_of = of_model(x)

本质是 ProxySubmodule 以及 torch2oflow 导致的,具体分析在:https://github.com/siliconflow/sd-team/issues/384

strint commented 2 months ago

是的,动态添加属性还没支持。