python / python/cpython

Cannot patch __call__ on an object with vectorcall defined

未关闭
#101,497 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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.

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 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

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。