Skip to content

Deprecate ExternalCOp#2292

Merged
ricardoV94 merged 2 commits into
pymc-devs:mainfrom
ricardoV94:remove_external_c_op
Jul 13, 2026
Merged

Deprecate ExternalCOp#2292
ricardoV94 merged 2 commits into
pymc-devs:mainfrom
ricardoV94:remove_external_c_op

Conversation

@ricardoV94

@ricardoV94 ricardoV94 commented Jul 13, 2026

Copy link
Copy Markdown
Member
  • Inline DimShuffle C code as a plain COp
  • Deprecate ExternalCOp

DimShuffle was the only one, and it paid the price. Every instantiaton READ FROM DISK! For the most common glue Op that's just outrageous.

import pytensor.tensor as pt

x = pt.tensor3("x")

def nest_expand_dims(x, n=20):
    out = x
    for _ in range(n):
        out = pt.expand_dims(out, 0)
    return out

%timeit nest_expand_dims(x)
# before (b264b264f): 8.61 ms ± 975 µs per loop
# after  (f31c4372f): 1.73 ms ± 78.6 µs per loop

It also penalized the C-backend because the generated function stayed polymorphic. Cherry picked (with some opinionated changes of mine) from #2218. Was too pissed to wait.

Deprecated the ExternalCOp. According to the bot once it's out for good roughly two-thirds of the pytensor/link/c/op.py module (~415 of 647 lines) goes away with it.

jessegrabowski and others added 2 commits July 13, 2026 16:15
Make DimShuffle a plain COp that emits per-node specialized C from the
static permutation and shape, replacing the runtime-spec dimshuffle.c
kernel. ExternalCOp read and re-parsed that file on every DimShuffle
instantiation (~200-400us per instance, paid throughout graph
construction and rewriting); construction is now ~5us.

C implementation adapted from the DimShuffle migration in pymc-devs#2218.
@ricardoV94
ricardoV94 force-pushed the remove_external_c_op branch from 301a58a to 49563d5 Compare July 13, 2026 14:15
@jessegrabowski

Copy link
Copy Markdown
Member

nice, i really like #2218, happy to see parts of it going in.

@ricardoV94
ricardoV94 merged commit d9abf1b into pymc-devs:main Jul 13, 2026
66 checks passed
@ricardoV94
ricardoV94 deleted the remove_external_c_op branch July 13, 2026 15:16
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.

2 participants