[Relax][PyTorch] Fix segfault in from_exported_program when model uses index_put_ with tuple output#19488
Open
cchung100m wants to merge 10 commits intoapache:mainfrom
Open
[Relax][PyTorch] Fix segfault in from_exported_program when model uses index_put_ with tuple output#19488cchung100m wants to merge 10 commits intoapache:mainfrom
cchung100m wants to merge 10 commits intoapache:mainfrom
Conversation
…s index_put_ with tuple output
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces support for in-place index_put_ operations in the Torch FX translator by updating the environment with the operation's result. It also adds a _flatten_output_args utility to the ExportedProgram translator to handle nested output structures that could cause FFI issues. Feedback indicates that the flattening utility is currently defined but not invoked, and suggests a more robust approach for extracting target names from FX nodes to handle cases where the target is a string.
Preserve explicit None outputs by appending Relax null objects.
Flatten output arguments before further processing.
Remove assertion for 3D tensor shape in frontend test.
Add regression test for M4D module's index_put behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Committers,
This PR is trying to fix issues #18363. Any suggestions would be appreciated if you are available.
Root Cause
_translate_fx_graph()passes the raw nested structure directly to the Relax FFI Tuple constructor.expr.cc.Solution
_flatten_output_args()that recursively walks any Pythontuple/list, collects onlyrelax.Exprleaves, and preserve explicit None outputs as Relax null objects.assert isinstance(output_args, tuple | relax.Tuple)guard with a call to_flatten_output_args(), producing a clean flat tuple ofrelax.Exprbefore FFI construction._index_put(), after emitting therelax.op.index_put(...)call, added an env alias update:self.env[source_node] = outputwhen the target op name starts withindex_put_, preserving correct in-place mutation semantics for downstream FX nodes.