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

Call BranchMorpher after dw deduplication #331

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kaushikcfd
Copy link
Collaborator

Some timings on the graphs (~36k nodes) implemented in https://github.com/illinois-ceesd/drivers_y2-isolator:

With this patch:

$ time python -O -m mpi4py isolator_injection_run.py -i run_params_combustion.yaml -r restart_data/isolator_init-000000 --log --lazy
real    2m48.997s
user    2m51.500s
sys     0m10.912s

Without this patch:

$ time python -O -m mpi4py isolator_injection_run.py -i run_params_combustion.yaml -r restart_data/isolator_init-000000 --log --lazy                                                                                                                                                                                                                                             
real    3m20.631s                                                                                                                                                                                                                              
user    3m22.686s                                                                                                      
sys     0m11.08

pytato/transform/__init__.py Outdated Show resolved Hide resolved
pytato/transform/__init__.py Outdated Show resolved Hide resolved
pytato/transform/__init__.py Outdated Show resolved Hide resolved
pytato/transform/__init__.py Outdated Show resolved Hide resolved

class EqualBranchesReuser(CopyMapper):
"""
A mapper that replaces equal segments of graphs with identical objects.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more context to the docstring, contrastng with CachedMapper and specifically mentioning that this is about equality after the mapper applies, and describe the resulting complexity reduction.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Owner

@inducer inducer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A few more notes/thoughts below.

Comment on lines +1718 to +1578
A mapper that reuses the same object instances for equal segments of
graphs.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A mapper that reuses the same object instances for equal segments of
graphs.
A mapper that reuses the same object instances for segments of
graphs that become equal after processing by subclasses of this mapper,
where the equality test happens immediately after a new node is created.

:class:`pytato.Array` nodes. However, they differ at the point where
two array expressions are compared. :class:`CopyMapper` compares array
expressions before the expressions are mapped i.e. repeatedly comparing
equal array expressions but unequal instances, and because of this it
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
equal array expressions but unequal instances, and because of this it
different instances representing equal array expressions, and, because of this, it

hand, :class:`PostMapEqualNodeReuser` has linear complexity in the
number of nodes in the number of array expressions as the larger mapped
expressions already contain same instances for the predecessors,
resulting in a cheaper equality comparison overall.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you want to say instead here is that this avoids building potentially large repeated subexpexpressions in the first place, rather than having to (expensively) merge them after the fact.

return array_or_names
# many paths in the DAG might be semantically equivalent after DWs are
# deduplicated => morph them
return PostMapEqualNodeReuser()(array_or_names)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, wait. If it's used like this, I would argue that that's equivalent to just using a CopyMapper. I figured the data-wrapper-deduplicator should inherit from this to avoid building large identical subtrees in the first place.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_post_map_equal_node_reuser_intestine to investigate whether this is equivalent to a CopyMapper, and at least in that example, it appears to be. It remains to figure out where the difference in execution time comes from.

@@ -1782,8 +1829,11 @@ def cached_data_wrapper_if_present(ary: ArrayOrNames) -> ArrayOrNames:
len(data_wrapper_cache),
data_wrappers_encountered - len(data_wrapper_cache))

return array_or_names
# many paths in the DAG might be semantically equivalent after DWs are
# deduplicated => morph them
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still: "morph" isn't good terminology.

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

Successfully merging this pull request may close these issues.

None yet

2 participants