MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / eager_api_linear

Function eager_api_linear

paddle/fluid/pybind/eager_custom_python_api.h:28–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26namespace pybind {
27
28static 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
80static PyObject *eager_api_run_program(PyObject *self,
81 PyObject *args,

Callers

nothing calls this directly

Calls 10

SetPythonStackFunction · 0.85
InputsContainDistTensorFunction · 0.85
ThrowExceptionToPythonFunction · 0.85
is_dist_tensorMethod · 0.80
set_error_strMethod · 0.80
ToPyObjectFunction · 0.70
has_allocationMethod · 0.45
whatMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected