Cannot patch __call__ on an object with vectorcall defined
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
It appears that when the type of an object has JAX_TPFLAGS_HAVE_VECTORCALL set on tp_flags, then overrides to call from within python are ignored.
- PyObject_Call checks if vectorcall is available (which is only a property of the type), and if so, then does the vectorcall: https://github.com/python/cpython/blob/3.11/Objects/call.c#L328
- The implementation of vectorcall does not check for tp_call (is this where call ends up?) https://github.com/python/cpython/blob/3.11/Include/internal/pycore_call.h#L39
I encountered this bug when using the latest version of JAX, which introduced vectorcalls in https://github.com/tensorflow/tensorflow/commit/bf3eb110f49fe9628a31d8e2052951cd6d0082f0 :
import jax
g = jax.jit(lambda x: x + 1)
print(type(g))
# > <class 'google3.third_party.tensorflow.compiler.xla.python.xla_extension.CompiledFunction'>
print(g(5))
# > 6
type(g).__call__ = lambda *args: 0
print(g(5))
# > 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the JAX example, then read Objects/call.c around the PyObject_Call vectorcall check and Include/internal/pycore_call.h around vectorcall dispatch. Determine the expected interaction with a Python-level call override and add regression coverage showing the intended behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100