-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Dynamo graph break when using pyton module heapq
(manipulates with list
s), although succeeds when placing heapq.py
near the test script
#106885
Comments
Out of curiosity, have you seen heaps used in model code - curious what kinds of applications you're thinking of |
I have my own reimpl of selective search, which is an iterative graph merging procedure and has a kind of tight Python loop. So I was wondering if Dynamo can compile the whole thing and approach C++ in loop codegen :) Or you might want to have Dikjstra / Prim algorithms as well |
It seems that dynamo does not want to trace into Python stdlib's
If I download Important I commented at the bottom of the file # If available, use C implementation
#try:
# from _heapq import *
#except ImportError:
# pass
#try:
# from _heapq import _heapreplace_max
#except ImportError:
# pass
#try:
# from _heapq import _heapify_max
#except ImportError:
# pass
#try:
# from _heapq import _heappop_max
#except ImportError:
# pass
#
#
#if __name__ == "__main__":
#
# import doctest # pragma: no cover
# print(doctest.testmod()) # pragma: no cover How could we make the graph capture dynamic? E.g. so that
|
E.g. this at least not breaks in regular Python: import heapq
import torch
# @torch.compile(fullgraph=True)
def program(x):
h = []
heapq.heappush(h, x)
val = heapq.heappop(h)
return val * torch.randn(10)
program(torch.tensor(1)) import heapq
import torch
@torch.compile(fullgraph=True)
def program(x):
h = []
heapq.heappush(h, x)
val = heapq.heappop(h)
return val * torch.randn(10)
program(torch.tensor(1)) produces |
heapq
(manipulates with list
s)heapq
(manipulates with list
s), although succeeds when placing heapq.py
near the test script
any updates? does it work in eager mode? |
I'll check, but for scalars it should work, yeah (as comparisons should work). Even with torch.compile it seems that it might work if heapq.py is copied to be near the script. It breaks straight up if heapq is used from the system library - and this is strange... |
@anijain2305 I would say that this is still a |
I ran into this today while working on a PyTorch implementation of farthest-first traversal. |
馃悰 Describe the bug
OP: https://discuss.pytorch.org/t/is-heapq-module-supported-for-compilation-by-dynamo/185863:
heapq
is a standard python's module useful for priority queue loops for Dijkstra-like algos:@msaroufim: @voznesenskym on github might say this is a good dynamo starter task XD
Versions
N/A
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @kadeng @anijain2305 @ipiszy
The text was updated successfully, but these errors were encountered: