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

ValReplacementMutator fails to mutate an expression even when its output is mutated #2554

Open
naoyam opened this issue Mar 7, 2023 · 1 comment
Labels

Comments

@naoyam
Copy link
Collaborator

naoyam commented Mar 7, 2023

class ValReplacementMutator : private OptOutMutator {

I don't have a failing case with devel, but encountered a problem with #2480.

ValReplacementMutator traverses all fusion vals and exprs from inputs to outputs. For an expression, mutate is called for its inputs, and then mutate is called for the expression itself, and then finally it's called for the outputs. This means that when mutating an expression, its outputs are not yet mutated. However, in OptOutMutator::mutate(Expr*), it seems it assumes the outputs are already mutated:

std::vector<Val*> mutated_outputs;
  mutated_outputs.reserve(op->outputs().size());
  for (auto output : op->outputs()) {
    mutated_outputs.emplace_back(maybeMutated(output));
  }

https://github.com/csarofeen/pytorch/blob/devel/third_party/nvfuser/csrc/mutator.cpp#L131

Since they are not yet mutated, maybeMutated should always just return the original (unmutated) output, even when they may eventually be mutated when mutate is called for them. This could obviously result in inconsistent states. For example, if an output is indeed mutated, its defining expression may not be created since when mutating the expression it may determine nothing is mutated.

I encountered some strange error due to this when ValReplacementMutator was used by replaceSymbolicSizes.

I think ValReplacementMutator should first visit all vals and mutate them as needed, and then visit all exprs.

@naoyam naoyam added the bug label Mar 7, 2023
@zasdfgbnm
Copy link
Collaborator

I think ValReplacementMutator should first visit all vals and mutate them as needed, and then visit all exprs.

This makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants