Skip to content

Remove test_value functionality#1972

Merged
ricardoV94 merged 3 commits into
pymc-devs:v3from
ricardoV94:no_more_tag_test_value
Mar 18, 2026
Merged

Remove test_value functionality#1972
ricardoV94 merged 3 commits into
pymc-devs:v3from
ricardoV94:no_more_tag_test_value

Conversation

@ricardoV94
Copy link
Copy Markdown
Member

@ricardoV94 ricardoV94 commented Mar 14, 2026

Grunt work done by Claude

Closes #447
Closes #831

Get a clean cut with v3, instead of trying FutureWarning which was too onerous as seen in #831

As a reminder, the reason this is bad is that it permeates too many places. It's easy enough to setup a helper optimizer / graph walker that does this if someone needs it. I haven't personally ever used tag.test_values for debugging.

code diff: The hardest part to review on a skim is tests that insisted putting test values in the tag, to later extract and evaluate. I've been trying to remove these (numba backend used this non-stop in the past), but as you can see there were still a lot. The rest is just pure deletions

@ricardoV94
Copy link
Copy Markdown
Member Author

ricardoV94 commented Mar 16, 2026

A small can of worms showed up when we refactored some tests that were using tags to actually use the compilation pathway (which should be what we tested in the first place).

We were asserting the following shape behavior:

  • pt.shape(NoneTypeT()()).eval() == (). Numpy does this, fine, but so does it do for many other types it cannot understand. Doesn't seem useful.
  • pt.shape(TypedListT()()).eval() == np.asarray(typed_list_value).shape. Which works only when the list contains homogeneous values (not a requirement in TypedList at all), and probably fails with other types (like list of RNG).

Now those just fail. Shape.make_node always calls as_tensor_variable on the input. If PyTensor doesn't understand this conversion and it fails (which it does for both types), we don't let numpy run loose with it at runtime either.

Also removed shape/ndim argument from TypedList. This isn't used anywhere and it isn't an obvious design decision. Should it be vector, none (opaque object), whatever it contains +1. Let's leave it for when we actually need it.

@ricardoV94 ricardoV94 force-pushed the no_more_tag_test_value branch from 086ae7b to d726ccc Compare March 16, 2026 21:48
Before:
shape(NoneType) -> np.shape(None) -> ()  (numpy tends to do this for things it doesn't understand)
shape(TypedLists) -> shape(np.asarray(TypedList)) -> either converts or fails. Now TypedList are considered vectors / 1d like python lists
@ricardoV94 ricardoV94 force-pushed the no_more_tag_test_value branch from d726ccc to 2d3f6f9 Compare March 16, 2026 23:23
Copy link
Copy Markdown
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

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

love it


"""

dtype = property(lambda self: self.ttype)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this instead of

@property
def dtype(self) -> TypeT:
    return self.ttype

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

python 2 legacy if I had to guess

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

claude tells me it's idiomatic for single variable delegation and that others do the same

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

who am i to argue then

Copy link
Copy Markdown
Member Author

@ricardoV94 ricardoV94 Mar 18, 2026

Choose a reason for hiding this comment

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

If it makes you feel better, it probably prefaced it with: "That's an insightful question"

assert np.array_equal(res.data, [1, 1])

# A test for a non-`TensorType`
class MyType(Type):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes please omg can we make removing all the MyType MyOp MyVar a blocker for v3

Copy link
Copy Markdown
Member Author

@ricardoV94 ricardoV94 Mar 18, 2026

Choose a reason for hiding this comment

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

These simple Ops and types in tests are good, they make sure we don't overcommit to tensors. But shape is a tensor Op, why should it accept arbitrary types?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok but can we rename them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, just not in this PR

Comment thread doc/extending/creating_a_numba_jax_op.rst Outdated
Comment thread tests/tensor/random/test_basic.py Outdated
def test_dirichlet_infer_shape(M, size):
def test_dirichlet_infer_shape(make_args):
M_pt = iscalar("M")
test_values = {M_pt: 3}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like overkill

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

simplified

Comment thread tests/tensor/random/test_basic.py Outdated
*rv_shape_val, rv_val = pytensor_fn(
*[
i.tag.test_value
test_values[i]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: using i to represent a non-counter

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

simplified a bunch of these tests in the last commit

@ricardoV94 ricardoV94 force-pushed the no_more_tag_test_value branch from 2d3f6f9 to ab3439f Compare March 18, 2026 22:01
@ricardoV94 ricardoV94 force-pushed the no_more_tag_test_value branch from ab3439f to 77ff77e Compare March 18, 2026 22:35
@ricardoV94 ricardoV94 merged commit 0a10de2 into pymc-devs:v3 Mar 18, 2026
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecate test_value machinery

2 participants