-
Notifications
You must be signed in to change notification settings - Fork 607
[TORCH] Modified fx_importer to support hop_while_loop #4338
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
base: main
Are you sure you want to change the base?
[TORCH] Modified fx_importer to support hop_while_loop #4338
Conversation
|
I'm working on resolving ci issues right now. Once that lands, I'll ping here to have you sync your branch with main and review. |
Sounds good, thanks. |
|
@keshavvinayak01 can you sync with main? |
Signed-off-by: Keshav Vinayak Jha <[email protected]>
3eb338f to
c8c711c
Compare
|
Should be synced. Had to force push. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some name inconsistencies, and even after resolving these, the generated IR does not lower out of torch dialect (some issue with the conversion to scf.while). I'd double-check the correctness of the generated prim loop, and possibly consider adding an e2e test
| for child_name, child_module in prog.graph.owning_module.named_children(): | ||
| if isinstance(child_module, GraphModule) and hasattr(child_module, 'graph'): | ||
| # Generate function name: parent_childname | ||
| child_func_name = f"{parent_name}_{child_name}_{id(child_module)}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not consistent with the _hop_while_loop callee names (hence the ci failure). Since you can't easily pass the parent name to this func, it would make sense to simply put the child name + an additional uniqueifier (I'm not a fan of id, since it will not be reproducible between runs).
You might be better off defining a mapping between graph modules and mlir func names as an attribute of the FxImporter, and handling name collisions as necessary there.
Signed-off-by: Keshav Vinayak Jha <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some more comments for now, thanks for addressing the earlier comments.
Please add an e2e test for this op and debug, since I wasn't able to lower the test output IR to linalg/tensor/scf (even with consistent naming).
Signed-off-by: Keshav Vinayak Jha <[email protected]>
Signed-off-by: Keshav Vinayak Jha <[email protected]>
|
I've addressed your comments, but specifically about the generated |
Signed-off-by: Keshav Vinayak Jha <[email protected]>
Signed-off-by: Keshav Vinayak Jha <[email protected]>
Change 1: Converts builtin tensors → Torch tensors when entering the loop body Change 2: Ensures Torch tensors → builtin tensors when yielding back to the loop condition Without these fixes, the conversion would fail when while loops carry tensor values Also modified basic_test.py FILECHECK statements. Signed-off-by: Keshav Vinayak Jha <[email protected]>
|
Had to modify |
That PR added tensor arg support for "for-like" loop conversion, but not "while-like" loop conversion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, but please add at least one e2e test in projects/pt1/python/torch_mlir_e2e_test/test_suite/control_flow.py. Let me know if you want some pointers on adding one of these.
This PR adds support for emitting graphs for Pytorch HOPs, beginning with
torch._higher_order_ops.while_loop.The proposed change is to modify the
import_programto call function_import_all_child_modules, which recursively imports the stateless graph for all the children modules.Since HOP operator graphs are stateless graphs with no mutation, it is correct to import them as stateless graphs, although the method
import_stateless_graphis marked as "deprecated".