google-deepmind / google-deepmind/reverb

c++ use python to import reverb error

Open
#127 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
793
Forks
113
PR merge metrics
No merged PRs in 30d

Description

python:
```
import traceback
import reverb
class RevervbUtil(object):
# str,int,[str],int,int
def init(self, learner_addr, learner_port, reverb_table_names,
reverb_client_max_sequence_length, reverb_client_chunk_length):
self.revervb_util = revervbutil(f'{learner_addr}:{learner_port}')
self.reverb_table_names = reverb_table_names
self.reverb_client_max_sequence_length = reverb_client_max_sequence_length
self.reverb_client_chunk_length = reverb_client_chunk_length
def send_datas(self, train_data):
self.revervb_util.write_to_reverb_server_simple(self.reverb_table_names, train_data)

class revervbutil():
def __init__(self, learner_addr) -> None:
self.reverb_client = reverb.Client(learner_addr)
def write_to_reverb_server_simple(self, reverb_table_names, train_data):
try:
with self.reverb_client.writer(max_sequence_length=int(self.reverb_client_max_sequence_length),
chunk_length=int(self.reverb_client_chunk_length)) as writer:
count = 0
for sample in train_data:
for table in reverb_table_names:
writer.append(sample)
prioritezed = 1.0
writer.create_item(table, 1, prioritezed)
writer.flush()
count += 1
except Exception as e:
print(f'learner_proxy send one data to reverb server error as {str(e)}, traceback.print_exc() is {traceback.format_exc()}')
```
c++:

```
#include "learner_proxy.h"

#include

using namespace std;

int main(int argc, char* argv[])
{
//py::scoped_interpreter guard{};
Py_Initialize();
if(!Py_IsInitialized())
{
return -1;
}

PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('/data/projects/kaiwu-fwk/framework/server/cpp/src/aisrv/')");

PyObject* pModule = PyImport_ImportModule("python_reverb_util");

PyObject* pDict = PyModule_GetDict(pModule);
PyObject* pClass = PyDict_GetItemString(pDict, "RevervbUtil");
PyObject* pConstruct = PyInstanceMethod_New(pClass);
PyObject* pInstanceReverb = PyObject_CallObject(pConstruct, NULL);

return 0;
}
```

when I execute it, segment falut happens:

```
(gdb) bt
#0 0x00007fed93c8eb1a in tensorflow::kernel_factory::OpKernelRegistrar::InitInternal(tensorflow::KernelDef const*, absl::lts_2020_02_25::string_view, std::unique_ptr >) ()
from /usr/local/python-3.7/lib/python3.7/site-packages/tensorflow/python/../libtensorflow_framework.so.2
#1 0x00007fed97835395 in tensorflow::kernel_factory::OpKernelRegistrar::OpKernelRegistrar(tensorflow::KernelDef const*, absl::lts_2020_02_25::string_view, tensorflow::OpKernel* (*)(tensorflow::OpKernelConstruction*)) ()
from /usr/local/python-3.7/lib/python3.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
#2 0x00007fed935a0d4f in _GLOBAL__sub_I_dataset.cc ()
from /usr/local/python-3.7/lib/python3.7/site-packages/tensorflow/python/../libtensorflow_framework.so.2
```

Butttt, I can run the python file in python environment.
```
if __name__ == '__main__':
revervb_util = RevervbUtil('127.0.0.1:9999', 1, 1)
train_data = []
revervb_util.write_to_reverb_server_simple('a', train_data)
```

How can I fix it? :>

Contributor guide

Open the contributing guide

Research direction

Start with the C++ embedding sequence in learner_proxy.h and the shown main function: Py_Initialize, sys.path setup, python_reverb_util import, and RevervbUtil construction. Reproduce the crash under gdb and inspect the TensorFlow frames in the backtrace, comparing this path with the working Python invocation. Done means the module can be imported and the class constructed from C++ without a segmentation fault, with the supported initialization path documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python, tensorflow
Domain
backend, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.