Remove deprecated PyTensor function functionality and reduce overhead#1351
Remove deprecated PyTensor function functionality and reduce overhead#1351ricardoV94 wants to merge 3 commits intopymc-devs:v3from
Conversation
0dc3147 to
782bc2d
Compare
9f026c7 to
4c1f269
Compare
a15d0e5 to
482cded
Compare
482cded to
b5b538f
Compare
2e801bc to
aaf2419
Compare
aaf2419 to
7033561
Compare
|
@ricardoV94 What is this |
|
Something that changed name in #1993 probably, let me find and rerun |
|
Ah dropped during rebase, it was new to this PR?... |
7033561 to
a6fd083
Compare
|
Re-introduced |
d37fd8f to
dc5ad26
Compare
This is actually slower than just not specifying it
dc5ad26 to
867f8b3
Compare
|
Did you mean to add the |
|
Those Ops relied on special casing of inputs being None at runtime (but not typed as such at definition time) which required a general extra |
|
|
||
| # Function.__call__ is responsible for updating the inputs, unless the vm promises to do it itself | ||
| self.update_input_storage: tuple[int, Container] = () | ||
| self._update_input_storage: tuple[int, Container] = () |
There was a problem hiding this comment.
This is a tuple[tuple[int, Container], ...]
There was a problem hiding this comment.
Yeah, I always get tripped by this
|
I understood most of it (not all) and it looks mostly okay to me, except in a couple of places where I have doubts |
jessegrabowski
left a comment
There was a problem hiding this comment.
-1.2k, you love to see it
| """ | ||
|
|
||
| __slots__ = ( | ||
| # Created inside __init__ |
| @@ -391,20 +401,11 @@ def __init__( | |||
| tuple elements are used only by Kits, which are deprecated. | |||
There was a problem hiding this comment.
What are Kits? Should we clean up this stuff as part of this PR?
| for i in inputs | ||
| ): | ||
| raise ValueError( | ||
| "Inputs with default values were deprecated. Use `functools.partial` instead." |
There was a problem hiding this comment.
| "Inputs with default values were deprecated. Use `functools.partial` instead." | |
| "Inputs with default values are deprecated. Use `functools.partial` instead." |
| # Wrap them in In or Out instances if needed. | ||
| inputs = [self.wrap_in(i) for i in inputs] | ||
|
|
||
| # Remove this after a while |
There was a problem hiding this comment.
Mark with TODO or something so we can find this? It's not a super useful comment.
| def __call__(self, *args, output_subset=None, **kwargs): | ||
| # Check if inputs are missing, or if inputs were set more than once, or | ||
| # if we tried to provide inputs that are supposed to be implicit. | ||
| for arg_container in input_storage: |
There was a problem hiding this comment.
it seems like we should be able to do this book-keeping along the way so we don't need another loop over the inputs. But it's just a one-time cost so whatever.
There was a problem hiding this comment.
This mixes info collected from args and kwargs, so we can only know if something is missing or provided multiple times if there are no kwargs?
| f(1, 2) | ||
| assert f[s] == 2 | ||
| assert g[s] == 2 | ||
| assert f._finder[s].value == 2 |
There was a problem hiding this comment.
we could implement __getitem__ for function as return self._finder[idx] ?
There was a problem hiding this comment.
I don't want __getitem__ for function, it's not at all obvious why there should be one
|
|
||
| assert result[0] == 47.0 | ||
| assert result[1] == 420.0 | ||
| with pytest.raises(ValueError, match="output_keys was deprecated"): |
There was a problem hiding this comment.
is it even worth testing this?
| def test_pickle_class_with_functions(self): | ||
| blah = SomethingToPickle() | ||
| assert blah.f2.container[blah.s].storage is blah.f1.container[blah.s].storage | ||
| assert blah.f2._finder[blah.s].storage is blah.f1._finder[blah.s].storage |
There was a problem hiding this comment.
does the variable have to be called blah?
There was a problem hiding this comment.
clearly, blue would be too confusing
Removing all the deprecated stuff that nobody uses
I think after this there's not much more fat to trim. We could try to avoid the input/output list thing with linkers that don't need it but we still need to sort them/ recognize kwargs which is pretty much what's left.
The C part of the call takes 100ns, so the "overhead" in this case is 200-250ns.
For reference, calling
numpy.zeros(100)takes like ~250ns, and a python identity function is ~20ns.Results of the new benchmark
Before
After
I also removed the strict zip, because passing
strict=Falseis more than 100ns slower than not specifying it at all. Check out with this snippet:Closes #1332
Does the same as and closes #1976
📚 Documentation preview 📚: https://pytensor--1351.org.readthedocs.build/en/1351/