diff --git a/debug/accuracy_tools/msprobe/ccsrc/if/python/MsProbeIfPython.cpp b/debug/accuracy_tools/msprobe/ccsrc/if/python/MsProbeIfPython.cpp index fa3f65cc5fc4d211f9608cadc115601598232d05..58a60538e0989ac1a197f77f14fc67b9593ecd40 100644 --- a/debug/accuracy_tools/msprobe/ccsrc/if/python/MsProbeIfPython.cpp +++ b/debug/accuracy_tools/msprobe/ccsrc/if/python/MsProbeIfPython.cpp @@ -58,7 +58,6 @@ PyMODINIT_FUNC PyInit__msprobe_c(void) Py_DECREF(m); return nullptr; } - Py_INCREF(precisionDebugger); PyObject* cpyAgent = MindStudioDebugger::GetCPythonAgentModule(); if (cpyAgent == nullptr) { @@ -71,11 +70,17 @@ PyMODINIT_FUNC PyInit__msprobe_c(void) Py_DECREF(m); return nullptr; } - Py_INCREF(cpyAgent); PyMethodDef* dumpmethods = MindStudioDebugger::GetDumpMethods(); for (PyMethodDef* method = dumpmethods; method->ml_name != nullptr; ++method) { - if (PyModule_AddObject(m, method->ml_name, PyCFunction_New(method, nullptr)) < 0) { + PyObject* func = PyCFunction_New(method, nullptr); + if (func == nullptr) { + PyErr_SetString(PyExc_ImportError, "Failed to create dump method."); + Py_DECREF(m); + return nullptr; + } + if (PyModule_AddObject(m, method->ml_name, func) < 0) { + Py_DECREF(func); // 释放未被模块接管的方法对象 PyErr_SetString(PyExc_ImportError, "Failed to bind dump method."); Py_DECREF(m); return nullptr; diff --git a/debug/accuracy_tools/msprobe/ccsrc/utils/CPythonUtils.cpp b/debug/accuracy_tools/msprobe/ccsrc/utils/CPythonUtils.cpp index 1122a348311697ee199fd11607be567db35eb5da..9be7813a605fa11f55dbc2d72ec2e97e7124c5c3 100644 --- a/debug/accuracy_tools/msprobe/ccsrc/utils/CPythonUtils.cpp +++ b/debug/accuracy_tools/msprobe/ccsrc/utils/CPythonUtils.cpp @@ -448,9 +448,18 @@ PythonListObject& PythonListObject::Insert(int64_t pos, PythonObject& item, bool return *this; } - if (PyList_Insert(ptr, pos, item) != 0) { + PyObject* item_ptr = item.GetPtr(); // 需确保PythonObject有此方法,返回内部PyObject* + if (item_ptr == nullptr) { + if (!ignore) { + PyErr_SetString(PyExc_ValueError, "Cannot insert a null object into the list."); + } + return *this; + } + + int insert_result = PyList_Insert(ptr, pos, item_ptr); + if (insert_result != 0) { if (ignore) { - PyErr_Clear(); + PyErr_Clear(); // 清除错误状态,避免影响后续操作 } } diff --git a/debug/accuracy_tools/msprobe/core/config_check/ckpt_compare/megatron_loader.py b/debug/accuracy_tools/msprobe/core/config_check/ckpt_compare/megatron_loader.py index af1c5518aacfa5d02f21633d1bb162e41f979917..5a03b4d2542c98736745d995d66a5869beb0bf13 100644 --- a/debug/accuracy_tools/msprobe/core/config_check/ckpt_compare/megatron_loader.py +++ b/debug/accuracy_tools/msprobe/core/config_check/ckpt_compare/megatron_loader.py @@ -138,6 +138,8 @@ def _consolidate_tp_weights(weights: Dict) -> Dict: def _parse_num_layers_per_stage(tp_partition): match = [re.findall(LAYER_IDX_PATTERN, key) for key in tp_partition.keys()] layer_idx = [int(i[0]) for i in match if i] + if not layer_idx: + return 1 num_layers_per_pipeline_stage = max(layer_idx) + 1 return num_layers_per_pipeline_stage