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

Refactor optimizer/evaluator.py and visitor.py to not use _legacy_ir #1436

Closed
titaiwangms opened this issue Apr 23, 2024 · 5 comments
Closed
Assignees
Labels
topic: IR Intermediate representation topic: optimizer

Comments

@titaiwangms
Copy link
Contributor

titaiwangms commented Apr 23, 2024

Optimizer relies on graph analysis to fold constant.

class IRContext(Protocol):

We should either extend the current IR to analyze graph, or develop/keep IRContext, but detach it with StaticValueInfo in _legacy_ir folder.

Lack of: StaticValueInfo.symbolic_value

@dataclasses.dataclass
class StaticValueInfo:
name: str
value: ConcreteValue = NotConstant
type: onnx.TypeProto | None = None
symbolic_value: SymbolicValue | None = None

The usages:

def process_function_outputs(self, function: onnx.FunctionProto) -> bool:
# Resolve copy for function subgraph output.
# Avoid copy of function subgraph input, because it is illegal for a direct edge
# from function input to function output.
prohibited_value_set = set(function.input)
updated = False
for i, output_name in enumerate(function.output):
output = self.lookup(output_name)
if (
output is not None
and output.is_copy()
and output.symbolic_value not in prohibited_value_set
):
old_value = self.lookup_or_create(output.name)
assert isinstance(output.symbolic_value, str)
new_value = self.lookup_or_create(output.symbolic_value)
new_value.identity_merge_from(old_value)
function.output[i] = output.symbolic_value
updated = True
return updated

cc @gramalingam @justinchuby

@titaiwangms titaiwangms added topic: rewriter topic: IR Intermediate representation labels Apr 23, 2024
@titaiwangms
Copy link
Contributor Author

Related #1324

@justinchuby
Copy link
Collaborator

@titaiwangms
Copy link
Contributor Author

Related

@justinchuby
Copy link
Collaborator

Do we want to create something similar to the interpreter in fx as a simplified visitor for general use?

@titaiwangms
Copy link
Contributor Author

Do we want to create something similar to the interpreter in fx as a simplified visitor for general use?

We can discuss offline if you have an idea.

For this issue, do you think IRContext is something that we can merge into IR after having symbolic_value? Looks like visitor.py also needs a huge refactor..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: IR Intermediate representation topic: optimizer
Projects
None yet
Development

No branches or pull requests

3 participants