Oneflow-Inc / one-fx

A toolkit for developers to simplify the transformation of nn.Module instances. It's now corresponding to Pytorch.fx.
Other
13 stars 1 forks source link

readme中给的usage例子跑不通 #22

Open Rickustc opened 1 year ago

Rickustc commented 1 year ago

`import oneflow import onefx

import onefx as fx

class MyModule(oneflow.nn.Module): def init(self, do_activation : bool = False): super().init() self.do_activation = do_activation self.linear = oneflow.nn.Linear(512, 512)

def forward(self, x):
    x = self.linear(x)
    x = oneflow.relu(x)
    y = oneflow.ones([2, 3])

    if self.do_activation:
        x = oneflow.relu(x)
    return y

without_activation = MyModule(do_activation=False) with_activation = MyModule(do_activation=True)

traced_without_activation = onefx.symbolic_trace(without_activation) print(traced_without_activation.code) """ def forward(self, x): linear = self.linear(x); x = None return linear """

traced_with_activation = onefx.symbolic_trace(with_activation) print(traced_with_activation.code) """ wrap("oneflow._oneflow_internal._C.relu")

def forward(self, x): linear = self.linear(x); x = None relu = oneflow._oneflow_internal._C.relu(linear); linear = None return relu """` 报错: Traceback (most recent call last): File "/home/wrq/oneflow/oneflow_fx.py", line 23, in traced_without_activation = onefx.symbolic_trace(without_activation) File "/home/wrq/anaconda3/envs/quant/lib/python3.9/site-packages/onefx/_symbolic_trace.py", line 1236, in symbolic_trace graph = tracer.trace(root, concrete_args) File "/home/wrq/anaconda3/envs/quant/lib/python3.9/site-packages/onefx/_symbolic_trace.py", line 811, in trace (self.create_arg(fn(*args)),), File "/home/wrq/oneflow/oneflow_fx.py", line 14, in forward y = oneflow.ones([2, 3]) File "/home/wrq/anaconda3/envs/quant/lib/python3.9/site-packages/oneflow/nn/modules/constant.py", line 237, in ones_op return Ones(size, dtype, device, placement, sbp, requires_grad)() File "/home/wrq/anaconda3/envs/quant/lib/python3.9/site-packages/onefx/_symbolic_trace.py", line 780, in module_call_wrapper return self.call_module(mod, forward, args, kwargs) File "/home/wrq/anaconda3/envs/quant/lib/python3.9/site-packages/onefx/_symbolic_trace.py", line 495, in call_module module_qualified_name = self.path_of_module(m) File "/home/wrq/anaconda3/envs/quant/lib/python3.9/site-packages/onefx/_symbolic_trace.py", line 450, in path_of_module raise NameError("module is not installed as a submodule") NameError: module is not installed as a submodule

环境: oneflow 0.9.0 onefx 0.0.3 torch 2.0.1