-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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 unused node check for compile_dag_node #49382
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Lydia <wenqix3@uw.edu>
Signed-off-by: Lydia <wenqix3@uw.edu>
Signed-off-by: Lydia <wenqix3@uw.edu>
Signed-off-by: Lydia <wenqix3@uw.edu>
Signed-off-by: Lydia <wenqix3@uw.edu>
used_attributes = set() | ||
visited_nodes = set() | ||
stack = [output_node] |
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.
type annotations
"Ensure all input attributes are used and contribute " | ||
"to the computation of the Compiled Graph output.", | ||
): | ||
dag.experimental_compile() |
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.
Can you move this test to test_accelerated_dag.py
? test_input_node.py
is for general DAG, not necessarily compiled graph
def f(self, input): | ||
return input | ||
|
||
def combine(self, a, b): |
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.
nit: add
instead of combine
unused_attributes = self.find_unused_input_attributes( | ||
output_node, input_attributes | ||
) | ||
|
||
if unused_attributes: | ||
unused_attributes_str = ", ".join(str(key) for key in unused_attributes) | ||
input_attributes_str = ", ".join(str(key) for key in input_attributes) | ||
unused_phrase = "is unused" if len(unused_attributes) == 1 else "are unused" | ||
|
||
raise ValueError( | ||
"Compiled Graph expects input to be accessed " | ||
f"using all of attributes {input_attributes_str}, " | ||
f"but {unused_attributes_str} {unused_phrase}. " | ||
"Ensure all input attributes are used and contribute " | ||
"to the computation of the Compiled Graph output." | ||
) | ||
|
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.
The validation part can be moved into find_unused_input_attributes
and rename it as check_unused_input_attributes
Why are these changes needed?
This will optimize DAG execution by conserving memory through the release of unused resources. Additionally, it enhances error detection by providing immediate and clear feedback on unused inputs, enabling developers to debug and refine their DAGs more effectively.
We currently store all user-accessed keys from the
input.attribute_node
into the accessed_keys, then traverse backward from the DAG’s output node to find all user input (see below). An input is considered used if a path exists from that input node to output. Finally, we compareaccessed_keys
toused_keys
, and report errors for anyunused_keys
. Changes we did in compiled_dag_node.py can be quickly searched by cmd +f: “handle_unused_keys
”.Update: This is the latest version of #49268
Code Snippet
Related issue number
Closes #47165
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.