-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add type inference #252
Add type inference #252
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,7 +336,7 @@ def _expand_reduction( | |
# Add GetResult nodes for the corresponding dimensions | ||
reduction.graph.inserting_after(reduction.fx_node) | ||
new_node = GetResult(reduction.fx_node, len(new_output_args)) | ||
new_node.add_to_graph(reduction.graph) | ||
new_node.add_to_graph(reduction.graph, arg.type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious what/why is the regular GetResult get_infer_type not working for this case? Can we add a comment to explain a bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure I can add that. The short summary is that it would require us to find the output node to get the right type since this is during expansion and the init_args have not been set yet. So since we have access to arg, we just use that instead. |
||
new_node.fx_node.name = get_expanded_name(new_node, dims) | ||
context[ | ||
(reduction, get_indexed_dims(dims, expand_dims), arg_idx) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2024 The IREE Authors | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
from ..ops.wave_ops import * | ||
from .._support.tracing import CapturedTrace | ||
import torch.fx as fx | ||
from ...support.logging import get_logger | ||
|
||
logger = get_logger("turbine.wave.type_inference") | ||
|
||
|
||
def infer_types(trace: CapturedTrace | fx.Graph): | ||
# Infer and set the types for all nodes in the graph. | ||
for subgraph in trace.region_graph.subgraphs.values(): | ||
for node in subgraph.nodes: | ||
custom = get_custom(node) | ||
custom.infer_type() | ||
logger.debug(f"Setting type for {custom.fx_node} = {custom.type}") |
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.
maybe we can raise NotImplemented here?
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.
Good question. So the idea is that most operators will implement infer_types except for Placeholders, etc. For those operators, since they already have a type, we want this to just pass through instead of throwing an error.