Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix set model attr #678

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

fix set model attr #678

wants to merge 11 commits into from

Conversation

ccssu
Copy link
Contributor

@ccssu ccssu commented Feb 27, 2024

来源: #675

  • use_graph=False
  • use_graph=True
test.py
import torch 
from torch.nn import Module
import oneflow as flow
from onediff.infer_compiler import oneflow_compile
from onediff.infer_compiler.transform import register

class Demo(Module):
    def __init__(self):
        super(Demo, self).__init__()
        self.value = 0

    def forward(self, x):
        return x * self.value
    
    def set_value(self, value):
        self.value = value

class Demo2(flow.nn.Module):
    def __init__(self):
        super(Demo2, self).__init__()
        self.value = 0

    def forward(self, x):
        return x * self.value
    
    def set_value(self, value):
        self.value = value

register(torch2oflow_class_map={Demo: Demo2})

model = Demo()
of_model = oneflow_compile(model, use_graph=False)
input_data = torch.tensor([1.0])

model.set_value(1.0)
of_output = of_model(input_data)
pt_output = model(input_data)

print("OneFlow Output:", of_output)
print("PyTorch Output:", pt_output)
# OneFlow Output: tensor([1.])
# PyTorch Output: tensor([1.])

@ccssu ccssu marked this pull request as draft February 27, 2024 12:02
@ccssu ccssu marked this pull request as ready for review February 28, 2024 09:43
@ccssu ccssu marked this pull request as draft February 28, 2024 10:41
@ccssu ccssu marked this pull request as ready for review March 2, 2024 05:04
@ccssu ccssu marked this pull request as draft March 2, 2024 08:38
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.

None yet

1 participant