Cannot patch __call__ on an object with vectorcall defined
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das JAX-Beispiel zu reproduzieren, und lies dann in Objects/call.c den Abschnitt um die PyObject_Call-Prüfung von vectorcall sowie in Include/internal/pycore_call.h den Abschnitt um den vectorcall-Versand. Bestimme die erwartete Interaktion mit einer Überschreibung von call auf Python-Ebene und füge Regressionstests hinzu, die das beabsichtigte Verhalten zeigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c, python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100