Skip to content

Commit 2fd4d63

Browse files
committed
RHAIENG-1277: fix(ci): monkypatch a protobuf 6.x (6.31) incompatibility
`AttributeError: 'MessageFactory' object has no attribute 'GetPrototype'` is not a problem in your own code—it is a **library-level incompatibility** that started to appear after the release of **protobuf ≥ 6.30** (especially 6.31). Google removed/deprecated the method `MessageFactory.GetPrototype` and replaced it with `GetMessageClass`. TensorFlow, PyTorch, Transformers, YOLO, ComfyUI, etc. still contain helper code that tries to call the old name, so the exception is raised **while they are being imported or while they build a graph**, not while your script is doing anything special. ## What you can (and should) do 1. **Down-grade protobuf to the last 5.x line** (5.29.4 or lower). That version still has `GetPrototype`, so the error disappears immediately. ```bash pip install -U "protobuf<6.0" # 5.29.4 is the newest 5.x ``` After the downgrade **restart the Python kernel / re-launch the process** so the already-imported modules disappear from `sys.modules`. > 99 % of the reports on GitHub, HF, Ultralytics, ComfyUI, etc. are solved by this single step . 2. **Keep every other package at their current version**; you do **not** need to downgrade TensorFlow, PyTorch, etc. Protobuf 5.29 is forward-compatible with every major framework that ships `.proto` files. 3. **If you must stay on protobuf 6.x** you would have to patch the offending code yourself (monkey-patch `google.protobuf.message_factory.MessageFactory.GetPrototype` so that it simply aliases `GetMessageClass`). A few projects already ship such a shim, but most users simply stay on 5.x until the ecosystem catches up . 4. **Watch the issue trackers** (TensorFlow #94030, Ultralytics #20527, …). When the libraries eventually release a version that says “supports protobuf 6.x” you can upgrade again.
1 parent 6db118d commit 2fd4d63

File tree

6 files changed

+24
-0
lines changed

6 files changed

+24
-0
lines changed

jupyter/rocm/tensorflow/ubi9-python-3.12/Dockerfile.rocm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ WORKDIR /opt/app-root/src
114114
###########################
115115
FROM rocm-jupyter-datascience AS rocm-jupyter-tensorflow
116116

117+
ARG JUPYTER_REUSABLE_UTILS=jupyter/utils
117118
ARG DATASCIENCE_SOURCE_CODE=jupyter/datascience/ubi9-python-3.12
118119
ARG TENSORFLOW_SOURCE_CODE=jupyter/rocm/tensorflow/ubi9-python-3.12
119120

@@ -152,4 +153,6 @@ RUN echo "Installing softwares and packages" && \
152153
chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
153154
fix-permissions /opt/app-root -P
154155

156+
COPY ${JUPYTER_REUSABLE_UTILS}/usercustomize.pth ${JUPYTER_REUSABLE_UTILS}/monkey_patch_protobuf_6x.py /opt/app-root/lib/python3.12/site-packages/
157+
155158
WORKDIR /opt/app-root/src

jupyter/tensorflow/ubi9-python-3.12/Dockerfile.cuda

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ WORKDIR /opt/app-root/src
121121
############################
122122
FROM cuda-jupyter-datascience AS cuda-jupyter-tensorflow
123123

124+
ARG JUPYTER_REUSABLE_UTILS=jupyter/utils
124125
ARG DATASCIENCE_SOURCE_CODE=jupyter/datascience/ubi9-python-3.12
125126
ARG TENSORFLOW_SOURCE_CODE=jupyter/tensorflow/ubi9-python-3.12
126127

@@ -159,4 +160,6 @@ RUN echo "Installing softwares and packages" && \
159160
chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
160161
fix-permissions /opt/app-root -P
161162

163+
COPY ${JUPYTER_REUSABLE_UTILS}/usercustomize.pth ${JUPYTER_REUSABLE_UTILS}/monkey_patch_protobuf_6x.py /opt/app-root/lib/python3.12/site-packages/
164+
162165
WORKDIR /opt/app-root/src
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Works with protobuf 6.30 – 6.31 (and probably later 6.x)
2+
3+
import google.protobuf.message_factory as _mf
4+
5+
# https://protobuf.dev/news/v30/#remove-deprecated
6+
if not hasattr(_mf.MessageFactory, "GetPrototype"):
7+
_mf.MessageFactory.GetPrototype = staticmethod(_mf.GetMessageClass)

jupyter/utils/usercustomize.pth

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# site-packages/*.pth gets executed during Python startup
2+
# but only lines starting with `import`, so `import ...; print("hello")` is possible
3+
# https://docs.python.org/3/library/site.html
4+
5+
import monkey_patch_protobuf_6x

runtimes/rocm-tensorflow/ubi9-python-3.12/Dockerfile.rocm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ RUN curl -L https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/oc
4848
###########################
4949
FROM rocm-base AS rocm-runtime-tensorflow
5050

51+
ARG JUPYTER_REUSABLE_UTILS=jupyter/utils
5152
ARG TENSORFLOW_SOURCE_CODE=runtimes/rocm-tensorflow/ubi9-python-3.12
5253

5354
LABEL name="odh-notebook-rocm-runtime-tensorflow-ubi9-python-3.12" \
@@ -76,4 +77,6 @@ RUN echo "Installing softwares and packages" && \
7677
chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
7778
fix-permissions /opt/app-root -P
7879

80+
COPY ${JUPYTER_REUSABLE_UTILS}/usercustomize.pth ${JUPYTER_REUSABLE_UTILS}/monkey_patch_protobuf_6x.py /opt/app-root/lib/python3.12/site-packages/
81+
7982
WORKDIR /opt/app-root/src

runtimes/tensorflow/ubi9-python-3.12/Dockerfile.cuda

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ RUN curl -L https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/oc
5252
############################
5353
FROM cuda-base AS cuda-runtime-tensorflow
5454

55+
ARG JUPYTER_REUSABLE_UTILS=jupyter/utils
5556
ARG TENSORFLOW_SOURCE_CODE=runtimes/tensorflow/ubi9-python-3.12
5657

5758
LABEL name="odh-notebook-cuda-runtime-tensorflow-ubi9-python-3.12" \
@@ -79,4 +80,6 @@ RUN echo "Installing softwares and packages" && \
7980
chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
8081
fix-permissions /opt/app-root -P
8182

83+
COPY ${JUPYTER_REUSABLE_UTILS}/usercustomize.pth ${JUPYTER_REUSABLE_UTILS}/monkey_patch_protobuf_6x.py /opt/app-root/lib/python3.12/site-packages/
84+
8285
WORKDIR /opt/app-root/src

0 commit comments

Comments
 (0)