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

Introduce _VarInfo internally to reduce memory footprint in value propagation #189

Merged
merged 46 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
539ca29
Init
neNasko1 Oct 27, 2024
b6aa765
Run linter
neNasko1 Oct 29, 2024
1d6bcbc
Changes
neNasko1 Oct 31, 2024
3c8e9b1
Fix ml
neNasko1 Nov 1, 2024
096a4f4
Fix some tests
neNasko1 Nov 4, 2024
e29a920
Fix some tests
neNasko1 Nov 4, 2024
bfaed79
Fix more tests
neNasko1 Nov 4, 2024
49e366c
Add some proper typing
neNasko1 Nov 4, 2024
f5af5d9
More initializers
neNasko1 Nov 5, 2024
27c562e
Fix passing
neNasko1 Nov 5, 2024
50e828b
Minor fixes and linter
neNasko1 Nov 5, 2024
d6b59ca
Change initializers name to input_prop_values
neNasko1 Nov 6, 2024
340d4c2
Make tests passing
neNasko1 Nov 6, 2024
3d77a87
Hacky fix mypy
neNasko1 Nov 6, 2024
9060d12
Correctly codegen
neNasko1 Nov 6, 2024
6aa1bf4
Comments after code review
neNasko1 Nov 15, 2024
07f9676
Improve type checking
neNasko1 Nov 18, 2024
df0bee9
Pre-commit enable
neNasko1 Nov 18, 2024
02e36ac
Update documentation
neNasko1 Nov 18, 2024
9488f6a
Fix adapt node
neNasko1 Nov 19, 2024
c23086b
Fix function inputs passing
neNasko1 Nov 19, 2024
1aebc1a
Fix opset generation
neNasko1 Nov 19, 2024
67d5b3b
Hint that _VarInfo is private
neNasko1 Nov 20, 2024
c9de7ec
Merge branch 'main' into split-value-prop
neNasko1 Nov 22, 2024
3f25d7e
Fix jinja
neNasko1 Nov 22, 2024
a8cebe2
Fix variadic input value propagation
neNasko1 Nov 26, 2024
63be89b
Comments after code review
neNasko1 Nov 28, 2024
0d5e2c8
Move validation to after propagation
neNasko1 Nov 28, 2024
d14e300
Fix diff
neNasko1 Nov 28, 2024
e33b00e
Fix diffs
neNasko1 Nov 28, 2024
b9f922c
Merge branch 'main' into split-value-prop
neNasko1 Dec 4, 2024
fdf81a3
Improve type-hinting information
neNasko1 Dec 4, 2024
cfae394
Remove unneded functions
neNasko1 Dec 4, 2024
19d7ebb
Init
neNasko1 Dec 6, 2024
b9cb099
fix
neNasko1 Dec 6, 2024
756f274
Final fixes
neNasko1 Dec 9, 2024
ac8807e
Add test for propagation of optional var
neNasko1 Dec 9, 2024
e5c311f
Unify logic around VarInfos -> Var
neNasko1 Dec 9, 2024
7f87559
Add comment
neNasko1 Dec 9, 2024
1b03440
Merge with main
neNasko1 Dec 9, 2024
8e5d25a
Improve qol
neNasko1 Dec 9, 2024
4215495
Update CHANGELOG.rst
neNasko1 Dec 9, 2024
fdb89cf
Fix tools/generate
neNasko1 Dec 9, 2024
07a8f91
Update CHANGELOG.rst
neNasko1 Dec 10, 2024
6360d61
Merge branch 'main' into split-value-prop
neNasko1 Dec 10, 2024
40b8b87
Comments after code-review
neNasko1 Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions src/spox/_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,10 @@ def _not_impl(self, *_):

class VarInfo:
"""
Abstraction for a single ONNX value - like a tensor - that can be passed around in Python code.

A ``VarInfo`` represents some output of an operator.
This operator is stored internally to allow reproducing the graph.

The ``type`` field is inferred and checked by operators.
It may be ``None`` if type inference failed, in which case it is unknown and should pass all type checks.
However, untyped ``VarInfo`` objects may not be used in some contexts.
Keep in mind that the types themselves may have some information missing.
For instance, tensors allow missing rank and shape information.

There is an implicit value propagation mechanism, powered by the ONNX reference implementation.
Values may be propagated if a ``VarInfo`` always has a known and constant value at runtime.
This is used for type & shape inference. For instance, Reshape to a constant shape can have the shape inferred.
Internal information about a ``Var``. Should be mainly inaccessible for most uses of ``spox``.
neNasko1 marked this conversation as resolved.
Show resolved Hide resolved

``VarInfo`` should be treated as strictly immutable.
If a ``VarInfo`` or any of its fields are modified, the behaviour is undefined and the produced graph may be invalid.

Protected fields are to be treated as internal.
Useful data is also shown by the string representation, but it should be treated as debug information.

Should not be constructed directly - the main source of ``VarInfo`` objects are operator constructors.
"""

type: Optional[_type_system.Type]
Expand Down Expand Up @@ -131,9 +113,11 @@ class Var:
"""
Abstraction for a single ONNX value - like a tensor - that can be passed around in Python code.

A ``VarInfo`` represents some output of an operator.
A ``Var`` represents some output of an operator.
This operator is stored internally to allow reproducing the graph.

The ``VarInfo`` class holds all relevant information about a ``Var`` - like the ``type``.

The ``type`` field is inferred and checked by operators.
It may be ``None`` if type inference failed, in which case it is unknown and should pass all type checks.
However, untyped ``VarInfo`` objects may not be used in some contexts.
Expand All @@ -144,8 +128,8 @@ class Var:
Values may be propagated if a ``VarInfo`` always has a known and constant value at runtime.
This is used for type & shape inference. For instance, Reshape to a constant shape can have the shape inferred.

``VarInfo`` should be treated as strictly immutable.
If a ``VarInfo`` or any of its fields are modified, the behaviour is undefined and the produced graph may be invalid.
``Var`` should be treated as strictly immutable.
If a ``Var`` or any of its fields are modified, the behaviour is undefined and the produced graph may be invalid.

Protected fields are to be treated as internal.
Useful data is also shown by the string representation, but it should be treated as debug information.
Expand Down
Loading