Skip to content

Caching error between C and CVM linkers #1670

@ricardoV94

Description

@ricardoV94

Description

This is a weird one, it showed up when I tried to benchmark the same Scan with CVM vs C linker.

import numpy as np
import pytensor
import pytensor.tensor as pt
from pytensor.compile.mode import Mode
from pytensor.graph.basic import NominalVariable

x1 = NominalVariable(0, pt.vector("x", shape=(10,)).type)
y1 = NominalVariable(1, pt.vector("y", shape=(10,)).type)
const1 = np.arange(10)
out = x1 + const1 * y1

fn = pytensor.function([x1, y1], [pytensor.Out(out, borrow=True)], mode=Mode(linker="c", optimizer="fast_run"))
fn(np.zeros(10), np.zeros(10))

fn = pytensor.function([x1, y1], [pytensor.Out(out, borrow=True)], mode=Mode(linker="cvm", optimizer="fast_run"))
fn(np.zeros(10), np.zeros(10))  # ValueError: expected an ndarray, not None

Compiling the first function with borrow=True, with a fresh cache, causes the other to fail (regardless of which one is first). It only works with NominalVariables and borrow=True. I suspect the C code between the two linkers is getting mixed up due to having the same hash.

Without NominalVariables I get two compiled C-files with hashes:

C-vm linker hash: me15b4d900f6d9189f2af261d5e6d9ac30f6ce6b9a0ae40b3ec2ab81e097b6c69
C-linker hash: m1a6dcbffbd7ed86f7db9c47290cd9ba06bd840fe2681c1fb1be255908078682f

But with NominalVariables, only the first gets built, suggesting it is being reused for the second linker incorrectly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions