Skip to content

Conversation

@SigureMo
Copy link
Member

@SigureMo SigureMo commented Jan 6, 2026

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

#73038paddle.distributed.fleet 会有同样的问题,这导致在调用分布式 API 的情况下会报错,本 PR 避免 bind 时候 bind 错 instance

fleet = Fleet()
_final_strategy = fleet._final_strategy
_get_applied_meta_list = fleet._get_applied_meta_list
_get_applied_graph_list = fleet._get_applied_graph_list
init = fleet.init
is_first_worker = fleet.is_first_worker
worker_index = fleet.worker_index
worker_num = fleet.worker_num
node_num = fleet.node_num
rank = fleet.worker_index
nranks = fleet.worker_num
world_size = fleet.worker_num
# device id in current trainer
local_device_ids = fleet.local_device_ids
# device ids in world
world_device_ids = fleet.world_device_ids
# rank in node
local_rank = fleet.local_rank
rank_in_node = local_rank
is_worker = fleet.is_worker
is_coordinator = fleet.is_coordinator
init_coordinator = fleet.init_coordinator
make_fl_strategy = fleet.make_fl_strategy
get_fl_client = fleet.get_fl_client
worker_endpoints = fleet.worker_endpoints
server_num = fleet.server_num
server_index = fleet.server_index
server_endpoints = fleet.server_endpoints
is_server = fleet.is_server
util = UtilBase()
barrier_worker = fleet.barrier_worker
all_reduce = fleet.all_reduce
init_worker = fleet.init_worker
init_server = fleet.init_server
run_server = fleet.run_server
stop_worker = fleet.stop_worker
distributed_optimizer = distributed_optimizer
save_inference_model = fleet.save_inference_model
save_persistables = fleet.save_persistables
save_cache_model = fleet.save_cache_model
check_save_pre_patch_done = fleet.check_save_pre_patch_done
save_one_table = fleet.save_one_table
save_dense_params = fleet.save_dense_params
load_model = fleet.load_model
load_inference_model = fleet.load_inference_model
load_one_table = fleet.load_one_table
set_date = fleet.set_date
print_table_stat = fleet.print_table_stat
minimize = fleet.minimize
distributed_model = distributed_model
shrink = fleet.shrink
get_hybrid_communicate_group = fleet.get_hybrid_communicate_group
distributed_scaler = distributed_scaler
set_log_level = log_util.set_log_level
get_log_level_code = log_util.get_log_level_code
get_log_level_name = log_util.get_log_level_name
check_memory_usage = log_util.check_memory_usage
save_cache_table = fleet.save_cache_table
collective_perf = fleet.collective_perf
from .. import auto_parallel as auto # noqa: F401

cpython 在 LOAD_METHOD 时如果不是 obj.__class__.<name>.__get__(obj, obj.__class__) 这种形式的情况下,是不会走第一个 meth_found 分支的

对于当前 case,这是因为 obj.__dict__<name>,即 patched method,这种情况会被认为 meth_found=0

https://github.com/python/cpython/blob/1173f8068b9a8c1168780532c466c391be10bf67/Objects/object.c#L1174-L1181

另外 super().fn 之前也走了错误的路径,但是能跑,tp_getattro 实际是 super_getattro,所以在 Py_TYPE(obj)->tp_getattro != PyObject_GenericGetAttr 就会走到 meth_found=0

https://github.com/python/cpython/blob/1173f8068b9a8c1168780532c466c391be10bf67/Objects/object.c#L1147-L1151

Copilot AI review requested due to automatic review settings January 6, 2026 14:31
@paddle-bot
Copy link

paddle-bot bot commented Jan 6, 2026

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where patched methods (methods attached to instances rather than defined on their class) were incorrectly binding the wrong instance when accessed through the SOT (Symbolic Opcode Translator) system. The fix adds a check to determine if an attribute exists on the class type before binding an instance, preventing incorrect bindings for dynamically-attached methods.

Key changes:

  • Added logic to detect patched methods by checking if attributes exist on the class type
  • When attributes don't exist on the class, the instance is set to None, allowing the correct instance to be extracted from the method's __self__
  • Applied the fix in both attr_proxy_getter and load_method to ensure consistency

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/sot/test_patched_method.py Adds test case validating that patched methods (methods bound to a different instance) are correctly handled without breaking the graph
python/paddle/jit/sot/opcode_translator/executor/variables/base.py Adds check for whether attribute exists on class type; if not, sets instance to None to avoid binding wrong instance
python/paddle/jit/sot/opcode_translator/executor/opcode_executor.py Adds the same hasattr check when loading methods to ensure consistent handling of patched methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

gouzil
gouzil previously approved these changes Jan 7, 2026
Copy link
Contributor

@DrRyanHuang DrRyanHuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最小复现demo真简洁喵 👍

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@ad925a3). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #77227   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         2           
  Lines              ?         4           
  Branches           ?         0           
===========================================
  Hits               ?         4           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SigureMo SigureMo merged commit fa0959e into PaddlePaddle:develop Jan 7, 2026
123 of 131 checks passed
@SigureMo SigureMo deleted the sot/avoid-bind-wrong-instance-on-patched-method branch January 7, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants