-
Notifications
You must be signed in to change notification settings - Fork 145
Fix C-cache bug related to input order of nominal variables #1673
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
base: main
Are you sure you want to change the base?
Conversation
e3668de
to
593038b
Compare
593038b
to
3b3c110
Compare
PS I don't love the shared baseclass of Constant and NominalVariables as "atomics". They are more like root variables (always required) than constants. The only difference between nominal and generic root variables is that they evaluate equal based on the "position / type" instead of id. from pytensor.graph.basic import NominalVariable
from pytensor.tensor.type import TensorType
ScalarType = TensorType(dtype="float64", shape=())
n1 = NominalVariable(0, ScalarType)
n2 = NominalVariable(0, ScalarType)
n3 = NominalVariable(1, ScalarType)
t1 = ScalarType()
t2 = ScalarType()
assert n1 == n2 != n3 and t1 != t2 That's however tangential to the bug here. It could be emulated just with regular variables and constants, as in the first test |
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (75.00%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1673 +/- ##
=======================================
Coverage 81.63% 81.63%
=======================================
Files 242 242
Lines 53569 53569
Branches 9451 9451
=======================================
Hits 43732 43732
- Misses 7360 7362 +2
+ Partials 2477 2475 -2
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a C-cache bug related to the input order of nominal variables in PyTensor's C linker. The issue occurred when compiling variants of the same graph with different orders of atomic inputs, which led to incorrect cache key generation and potential runtime errors.
Key changes:
- Modified the
in_sig
function inCLinker.cmodule_key_
to properly handle nominal variables that appear in the inputs list - Added comprehensive test cases covering both constant and nominal variable scenarios with different input orderings
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
pytensor/link/c/basic.py | Fixed cache key generation logic to correctly identify and handle nominal/constant variables in input lists |
tests/link/c/test_basic.py | Added regression tests for input order variations and C/CVM linker compatibility with nominal variables |
# While the CVMLinker will call the CLinker on its one Op with all inputs (required and constants) | ||
# This difference in input signature used to be ignored by the cache key, | ||
# but the generated code cared about the number of explicit inputs. | ||
# Changing the order of inputs is a smoke thest to make sure we pay attention to the input signature. |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'thest' to 'test'.
# Changing the order of inputs is a smoke thest to make sure we pay attention to the input signature. | |
# Changing the order of inputs is a smoke test to make sure we pay attention to the input signature. |
Copilot uses AI. Check for mistakes.
) | ||
@pytest.mark.parametrize("atomic_type", ["constant", "nominal"]) | ||
def test_clinker_atomic_inputs(linker, atomic_type): | ||
"""Test that compiling variants of the same graph with different order of atomic inputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentence fragment. That that compiling variants does what?
Closes #1670
📚 Documentation preview 📚: https://pytensor--1673.org.readthedocs.build/en/1673/