You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "Lunderberg (via GitHub)" <gi...@apache.org> on 2024/03/27 12:53:10 UTC

[PR] [Relax] Allow DeadCodeElimination within ApplyPassToFunction [tvm]

Lunderberg opened a new pull request, #16801:
URL: https://github.com/apache/tvm/pull/16801

   The `tvm.ir.transform.ApplyPassToFunction` allows a transform to be applied selectively to some portions of a `IRModule`, without applying to the entire `IRModule`.  For example, to apply an optimization pass (e.g. `relax.transform.ExpandMatmulOfSum`) or an interface-altering pass (e.g. `relax.transform.BundleModelParams`) to specific functions.  It does so by generating an intermediate `IRModule` containing only the functions specified, applying the transform to that intermediate, then merging the results.
   
   When using `ApplyPassToFunction` to apply `DeadCodeElimination`, or a pipeline containing `DeadCodeElimination`, this intermediate `IRModule` may contain calls to `GlobalVar` instances that are not within the intermediate `IRModule`.  Prior to this commit, this resulted in an error being thrown when collecting the call graph. This commit updates `DeadCodeElimination` to instead handle incomplete call-graph collection.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Relax] Allow DeadCodeElimination within ApplyPassToFunction [tvm]

Posted by "Lunderberg (via GitHub)" <gi...@apache.org>.
Lunderberg merged PR #16801:
URL: https://github.com/apache/tvm/pull/16801


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Relax] Allow DeadCodeElimination within ApplyPassToFunction [tvm]

Posted by "slyubomirsky (via GitHub)" <gi...@apache.org>.
slyubomirsky commented on PR #16801:
URL: https://github.com/apache/tvm/pull/16801#issuecomment-2030958916

   Hmmm. This approach seems fine for the specific case of DCE, but I wonder if the design of `ApplyPassToFunction` needs further thought, since the fact that it can output malformed modules could be an issue for other passes as well. Maybe the pass infrastructure/interfaces could try to accommodate the case of not processing the entire module? A shorter-term change might be ensuring that all module-level passes check whether a function is defined when looking up global vars (we could make it a helper function in the `ExprMutator` base, even, since the examples I found were using the `ExprMutator`'s `mod_` field for this purpose). Cursory search for other examples of directly calling `Lookup` on `mod_`: `BindSymbolicVars`, `FuseTIR`, `RewriteCudaGraph`, `MergeCompositeFunctions`, `LambdaLift`, `DetectRecursion` (analysis), with a few others that are related to training or autotuning.
   
   We should be careful about introducing another possible pitfall to pass design (in this case having to accommodate a violated invariant).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Relax] Allow DeadCodeElimination within ApplyPassToFunction [tvm]

Posted by "Lunderberg (via GitHub)" <gi...@apache.org>.
Lunderberg commented on PR #16801:
URL: https://github.com/apache/tvm/pull/16801#issuecomment-2032356395

   Agreed, it would be good to avoid having too many special cases.  The intent was to allow optimization passes, or API-altering passes, to be part of an end-to-end pipeline while only impacting a few functions within the module.  (e.g. Applying `LazyGetInput` to the result of `LiftTransformParams`, but not to any of the inference functions.)
   
   If it requires more special cases in general, I think the `ApplyPassToFunction` could be improved by replacing all non-matching functions with `relax::ExternFunc`, rather than filtering them out altogether.  That way, the inner transform could operate on a well-formed `IRModule`, but wouldn't be able to mutate other functions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org