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

Do magpy support print in compiled model? #46

Open
hanwen-sun opened this issue Nov 5, 2024 · 1 comment
Open

Do magpy support print in compiled model? #46

hanwen-sun opened this issue Nov 5, 2024 · 1 comment

Comments

@hanwen-sun
Copy link

Hello, I want to know whether magpy support side effect function like print. Dynamo will break the graph when meeting print. I write a simple demo to test magpy, but it seems that magpy do not support print.
The test demo is:

import torch
from frontend.compile import compile

def builtin_function(x):
    x = x * 2
    print(x)
    x = x / 2

    return x

x = torch.randn(1024)
compiled = compile(builtin_function)
y = compiled(x)
print(y)

And the output is:

(<built-in function print>, [tensor([-1.2829,  2.9794, -3.1826,  ...,  0.3809,  0.3648, -0.0356])], {}) <class 'NotImplementedError'>
Traceback (most recent call last):
  File "/root/shw/graph_capture/MAGPY/MagPy/examples/magpy_test_builtin_functions.py", line 14, in <module>
    y = compiled(x)
  File "/root/shw/graph_capture/MAGPY/MagPy/frontend/compile.py", line 77, in _fn
    raise e
  File "/root/shw/graph_capture/MAGPY/MagPy/frontend/compile.py", line 74, in _fn
    return fn(*args, **kwargs)
  File "/root/shw/graph_capture/MAGPY/MagPy/examples/magpy_test_builtin_functions.py", line 7, in builtin_function
    print(x)
  File "/root/shw/graph_capture/MAGPY/MagPy/examples/magpy_test_builtin_functions.py", line 7, in builtin_function
    print(x)
  File "/root/shw/graph_capture/MAGPY/MagPy/frontend/tracer.py", line 58, in trace_func
    raise e
  File "/root/shw/graph_capture/MAGPY/MagPy/frontend/tracer.py", line 34, in trace_func
    record(frame, frame_id)
  File "/root/shw/graph_capture/MAGPY/MagPy/frontend/guard_tracker.py", line 2827, in record
    trackers[-1].record(frame, frame_id)
  File "/root/shw/graph_capture/MAGPY/MagPy/frontend/guard_tracker.py", line 979, in record
    raise e
  File "/root/shw/graph_capture/MAGPY/MagPy/frontend/guard_tracker.py", line 974, in record
    getattr(self, inst.opname)(inst)
  File "/root/shw/graph_capture/MAGPY/MagPy/frontend/guard_tracker.py", line 2318, in CALL_FUNCTION
    self.call_function(func, args, kwargs)
  File "/root/shw/graph_capture/MAGPY/MagPy/frontend/guard_tracker.py", line 1996, in call_function
    raise NotImplementedError(func, args, kwargs)
NotImplementedError: (<built-in function print>, [tensor([-1.2829,  2.9794, -3.1826,  ...,  0.3809,  0.3648, -0.0356])], {})

There's no graph and guard function output.

@heheda12345
Copy link
Owner

This error indicates that MagPy detects print has side effect, and throws an error to generate graph break. But the handling of graph break in the middle of user code is not very stable.
You can try this flag to fall back to pure pytorch execution without compilation when MagPy meets some problem

"enable_fallback": False,

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

No branches or pull requests

2 participants