| 26 | namespace pybind { |
| 27 | |
| 28 | static PyObject *eager_api_linear(PyObject *self, |
| 29 | PyObject *args, |
| 30 | PyObject *kwargs) { |
| 31 | PyThreadState *tstate = nullptr; |
| 32 | try { |
| 33 | auto &x = GetTensorFromArgs("linear", "X", args, 0, false); |
| 34 | auto &weight = GetTensorFromArgs("linear", "weight", args, 1, false); |
| 35 | auto &bias = GetTensorFromArgs("linear", "Bias", args, 2, true); |
| 36 | |
| 37 | tstate = PyEval_SaveThread(); |
| 38 | SetPythonStack(); |
| 39 | if (bias.is_dist_tensor() || bias.has_allocation()) { |
| 40 | const phi::distributed::ProcessMesh *mesh = nullptr; |
| 41 | if (InputsContainDistTensor(&mesh, x, weight, bias)) { |
| 42 | ConvertAllInputsToDistTensor(mesh, x, weight, bias); |
| 43 | } |
| 44 | |
| 45 | auto mm_out = matmul_ad_func(x, weight, false, false); |
| 46 | auto out = add_ad_func(mm_out, bias); |
| 47 | PyEval_RestoreThread(tstate); |
| 48 | tstate = nullptr; |
| 49 | return ToPyObject(out); |
| 50 | } else { |
| 51 | const phi::distributed::ProcessMesh *mesh = nullptr; |
| 52 | if (InputsContainDistTensor(&mesh, x, weight)) { |
| 53 | ConvertAllInputsToDistTensor(mesh, x, weight); |
| 54 | } |
| 55 | |
| 56 | auto mm_out = matmul_ad_func(x, weight, false, false); |
| 57 | PyEval_RestoreThread(tstate); |
| 58 | tstate = nullptr; |
| 59 | return ToPyObject(mm_out); |
| 60 | } |
| 61 | } catch (paddle::platform::EnforceNotMet &exception) { |
| 62 | if (tstate) { |
| 63 | PyEval_RestoreThread(tstate); |
| 64 | } |
| 65 | std::ostringstream sout; |
| 66 | sout << exception.what(); |
| 67 | sout << " [operator < linear > error]"; |
| 68 | exception.set_error_str(sout.str()); |
| 69 | ThrowExceptionToPython(std::current_exception()); |
| 70 | return nullptr; |
| 71 | } catch (...) { |
| 72 | if (tstate) { |
| 73 | PyEval_RestoreThread(tstate); |
| 74 | } |
| 75 | ThrowExceptionToPython(std::current_exception()); |
| 76 | return nullptr; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | static PyObject *eager_api_run_program(PyObject *self, |
| 81 | PyObject *args, |
nothing calls this directly
no test coverage detected