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

Supporting obj is not an object. #621

Merged
merged 2 commits into from
Feb 5, 2024
Merged

Supporting obj is not an object. #621

merged 2 commits into from
Feb 5, 2024

Conversation

ccssu
Copy link
Contributor

@ccssu ccssu commented Feb 4, 2024

测试:

from onediff.infer_compiler.transform import torch2oflow
import torch 
mod = torch.nn.Linear 
# Convert to oneflow
of_mod = torch2oflow(mod)
print(of_mod) # <class 'oneflow.nn.modules.linear.Linear'>
x = 9 
print(f'{isinstance(x, type)=}') # isinstance(x, type)=False

Comment on lines +155 to +160
@torch2oflow.register
def _(mod: type):
if not is_need_mock(mod):
return mod
return proxy_class(mod)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

支持 obj 不是对象,就是一个 torch 的 class

@@ -162,7 +173,7 @@ def init(self):
for k, _ in obj.__dict__.items():
attr = getattr(obj, k)
self.__dict__[k] = torch2oflow(attr)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

来自 black 格式化,black.version '24.1.1

@ccssu ccssu requested a review from strint February 4, 2024 09:31
@strint strint merged commit 8a52a7e into main Feb 5, 2024
3 of 5 checks passed
@strint strint deleted the fix_torch2oflow_type branch February 5, 2024 06:44
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