TensorFlow 检查正在使用哪个 protobuf 实现

TensorFlow check which protobuf implementation is being used

有没有办法检查 TensorFlow 使用哪个 protobuf 实现(即它使用的是 C++ 版本还是 Python 版本)?

尝试以下操作:

$ python -c "from google.protobuf.internal import api_implementation; print(api_implementation._default_implementation_type)"

它应该打印 pythoncpp

@keveman 的回答告诉我们 default 实现而不是 active 实现。

重要的是,PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION 环境变量会影响激活的实现,因此

PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp python -c "from google.protobuf.internal import api_implementation; print(api_implementation._default_implementation_type)"

PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python python -c "from google.protobuf.internal import api_implementation; print(api_implementation._default_implementation_type)"

将始终显示相同的结果。

要查看哪个实现处于活动状态,请改用它:

python -c "from google.protobuf.internal import api_implementation; print(api_implementation.Type())"

更改 PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION 环境变量将导致 Type() 的结果发生变化,而 _default_implementation_type.

则不会