Cannot patch __call__ on an object with vectorcall defined
オープン
まだ誰も着手していません。
topic-C-API
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず JAX の例を再現し、次に Objects/call.c の PyObject_Call における vectorcall チェック周辺と、Include/internal/pycore_call.h の vectorcall ディスパッチ周辺を読みます。Python レベルの call オーバーライドとの想定される相互作用を確認し、意図した動作を示すリグレッションカバレッジを追加します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100