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

Split value prop #189

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft

Split value prop #189

wants to merge 25 commits into from

Conversation

neNasko1
Copy link

@neNasko1 neNasko1 commented Nov 6, 2024

Fixes #187 by making the current user-facing Var be a wrapper around a helper class VarInfo, where Var is a pair (VarInfo, PropValue).

The idea is to have VarInfo be the object that is passed around inside of all functions and be pointed to by all Node-s, so concrete propagated values can be garbage collected correctly.

Checklist for implementation

  • Provide better typing around input_prop_values dictionary
  • Fix adapt_node
  • Fix documentation
  • Add a CHANGELOG.rst entry
  • Fix Var-s passed to manual inference
  • Make tests passing

Breaking changes checklist

  • Examine the performance implications?
  • Examine downstream repos, does the change brake anything we rely on?

Copy link
Collaborator

@cbourjau cbourjau left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on and great work to already make the tests pass! I am trying to grok the details of the implementation. While doing so I already left a few high-level comments. I am not quite convinced that the use of a meta class is buying us much with respect to the introduced complexity/scariness of it. Would you mind adding type hints for its use and/or point out where it would provide a mypy-testable benefit compared to a simpler/dynamic structure such as a dict[str, Var]s?

src/spox/_exceptions.py Outdated Show resolved Hide resolved
)
)
out_values = self.propagate_values(input_prop_values)
return self.outputs._propagate_vars(out_values)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is a bit of a pitty that we don't have any output type here. Having a type such as dict[str, Var] would be better than nothing. I'm not sure how we could type this properly using the TypeBaseVars. If we lose the type information already here, is the TypeBaseVars-complexity really worth the effort?

src/spox/_node.py Outdated Show resolved Hide resolved
src/spox/_fields.py Outdated Show resolved Hide resolved
src/spox/opset/ai/onnx/ml/v3.py Outdated Show resolved Hide resolved
src/spox/_node.py Outdated Show resolved Hide resolved
src/spox/_node.py Outdated Show resolved Hide resolved
@jbachurski
Copy link
Collaborator

jbachurski commented Nov 9, 2024

Are you sure there isn’t a cleaner way of doing this? Or perhaps some simpler hack. It feels like a significant change.
I wonder if your standpoint on value propagation changed, Christian @cbourjau - it was mostly intended as an experimental side-feature to improve experimentation back when I added it, not something that should be relied on in live systems. So I’m not sure a large change is worth it to improve the GC behaviour.
I’m afraid I won’t be able to help review this as I’m pretty starved on time.

@cbourjau
Copy link
Collaborator

cbourjau commented Nov 9, 2024

Thanks for your feedback @jbachurski ! Let me provide a little more context.

I wonder if your standpoint on value propagation changed, Christian ?

Yes, it did indeed! ndonnx makes it very easy to try out NumPy code with constant arrays. So much so that it is perfectly reasonable to quickly convert large NumPy arrays into ndonnx ones and to throw them at our code. While technically still a "debugging" feature, it is now used very commonly during development and on very large graphs. The value propagation in ndonnx is currently re-implemented there, but I believe it would be cleaner to do it properly here in Spox on the operator level.

@jbachurski
Copy link
Collaborator

While technically still a "debugging" feature, it is now used very commonly during development and on very large graphs. The value propagation in ndonnx is currently re-implemented there, but I believe it would be cleaner to do it properly here in Spox on the operator level.

Curious. Yes, I noticed that it was early on and found it surprising, but I didn't want to question it :)
I imagine it would be cleaner like so indeed – good luck 🍀

I'll let you know in case I come up with something accidentally but yeah, it's unfortunately an extremely busy period for me to think over this design aspect.

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.

Value propagation produces a large memory footprint
3 participants