Skip to content

Commit 90c3481

Browse files
authored
Upgrade the Tensorflow version to address some security issues (#1870)
* upgrade the tensorflow version to address some security issues * fix enas example codes * upgrade tensorflow to v2.9.1 and tensorflow-aarch64 to v2.9.0 * install protobuf (>= 3.9.2, < 3.20) for tensorflow-aarch64
1 parent a9d92bd commit 90c3481

File tree

10 files changed

+33
-33
lines changed

10 files changed

+33
-33
lines changed

cmd/metricscollector/v1beta1/tfevent-metricscollector/Dockerfile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@ FROM python:3.9
22

33
ENV TARGET_DIR /opt/katib
44
ENV METRICS_COLLECTOR_DIR cmd/metricscollector/v1beta1/tfevent-metricscollector
5-
# tensorflow community build for aarch64
6-
# https://github.com/tensorflow/build#tensorflow-builds
7-
ENV PIP_EXTRA_INDEX_URL https://snapshots.linaro.org/ldcg/python-cache/
85

96
ADD ./pkg/ ${TARGET_DIR}/pkg/
107
ADD ./${METRICS_COLLECTOR_DIR}/ ${TARGET_DIR}/${METRICS_COLLECTOR_DIR}/
118
WORKDIR ${TARGET_DIR}/${METRICS_COLLECTOR_DIR}
129

13-
RUN if [ "$(uname -m)" = "aarch64" ]; then \
14-
pip install tensorflow-aarch64==2.7.0; \
15-
else \
16-
pip install tensorflow==2.7.0; \
17-
fi;
1810
RUN pip install --no-cache-dir -r requirements.txt
1911

2012
RUN chgrp -R 0 ${TARGET_DIR} \

cmd/metricscollector/v1beta1/tfevent-metricscollector/requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ psutil==5.8.0
22
rfc3339>=6.2
33
grpcio==1.41.1
44
googleapis-common-protos==1.6.0
5+
# TODO (tenzen-y): We need to delete the line to install protobuf after tensorflow-aarch64 v2.9.1, or higher has been released.
6+
# To avoid the `If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.` error,
7+
# we must restrict the protobuf version.
8+
protobuf >= 3.9.2, < 3.20; platform_machine=="aarch64"
9+
tensorflow==2.9.1; platform_machine=="x86_64"
10+
tensorflow-aarch64==2.9.0; platform_machine=="aarch64"

cmd/suggestion/chocolate/v1beta1/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ RUN if [ "$(uname -m)" = "ppc64le" ]; then \
2222
ADD ./pkg/ ${TARGET_DIR}/pkg/
2323
ADD ./${SUGGESTION_DIR}/ ${TARGET_DIR}/${SUGGESTION_DIR}/
2424
WORKDIR ${TARGET_DIR}/${SUGGESTION_DIR}
25-
RUN if [ "$(uname -m)" = "aarch64" ]; then \
26-
sed -i -e '$a git+https://github.com/fmder/ghalton@master' -e '/^ghalton/d' requirements.txt; \
27-
fi;
2825
RUN pip install --no-cache-dir -r requirements.txt
2926

3027
RUN chgrp -R 0 ${TARGET_DIR} \

cmd/suggestion/chocolate/v1beta1/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ protobuf==3.19.1
88
googleapis-common-protos==1.6.0
99
SQLAlchemy==1.4.26
1010
git+https://github.com/AIworx-Labs/chocolate@master
11-
ghalton>=0.6.2
11+
ghalton>=0.6.2; platform_machine=="x86_64"
12+
git+https://github.com/fmder/ghalton@master; platform_machine=="aarch64"
1213
cython>=0.29.24

cmd/suggestion/nas/enas/v1beta1/Dockerfile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ FROM python:3.9
33
ENV TARGET_DIR /opt/katib
44
ENV SUGGESTION_DIR cmd/suggestion/nas/enas/v1beta1
55
ENV GRPC_HEALTH_PROBE_VERSION v0.4.11
6-
# tensorflow community build for aarch64
7-
# https://github.com/tensorflow/build#tensorflow-builds
8-
ENV PIP_EXTRA_INDEX_URL https://snapshots.linaro.org/ldcg/python-cache/
96

107
RUN if [ "$(uname -m)" = "ppc64le" ] || [ "$(uname -m)" = "aarch64" ]; then \
118
apt-get -y update && \
@@ -26,10 +23,6 @@ RUN if [ "$(uname -m)" = "ppc64le" ]; then \
2623
ADD ./pkg/ ${TARGET_DIR}/pkg/
2724
ADD ./${SUGGESTION_DIR}/ ${TARGET_DIR}/${SUGGESTION_DIR}/
2825
WORKDIR ${TARGET_DIR}/${SUGGESTION_DIR}
29-
30-
RUN if [ "$(uname -m)" = "aarch64" ]; then \
31-
sed -i 's/tensorflow==/tensorflow-aarch64==/' requirements.txt; \
32-
fi;
3326
RUN pip install --no-cache-dir -r requirements.txt
3427

3528
RUN chgrp -R 0 ${TARGET_DIR} \
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
grpcio==1.41.1
2-
protobuf==3.19.1
32
googleapis-common-protos==1.6.0
4-
tensorflow==2.8.0
53
cython>=0.29.24
4+
# TODO (tenzen-y): We need to delete the line to install protobuf after tensorflow-aarch64 v2.9.1, or higher has been released.
5+
# To avoid the `If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.` error,
6+
# we must restrict the protobuf version.
7+
protobuf >= 3.9.2, < 3.20; platform_machine=="aarch64"
8+
tensorflow==2.9.1; platform_machine=="x86_64"
9+
tensorflow-aarch64==2.9.0; platform_machine=="aarch64"

examples/v1beta1/trial-images/enas-cnn-cifar10/Dockerfile.cpu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM tensorflow/tensorflow:2.7.0
1+
FROM tensorflow/tensorflow:2.9.1
22

33
ENV TARGET_DIR /opt/enas-cnn-cifar10
44

examples/v1beta1/trial-images/enas-cnn-cifar10/Dockerfile.gpu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM tensorflow/tensorflow:2.7.0-gpu
1+
FROM tensorflow/tensorflow:2.9.1-gpu
22

33
ENV TARGET_DIR /opt/enas-cnn-cifar10
44

examples/v1beta1/trial-images/enas-cnn-cifar10/RunTrial.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
from keras.datasets import cifar10
1717
from ModelConstructor import ModelConstructor
1818
from tensorflow.keras.utils import to_categorical
19-
from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model
2019
from keras.preprocessing.image import ImageDataGenerator
20+
import tensorflow as tf
2121
import argparse
2222

2323
if __name__ == "__main__":
@@ -50,16 +50,23 @@
5050

5151
print("\n>>> Constructing Model...")
5252
constructor = ModelConstructor(arch, nn_config)
53-
test_model = constructor.build_model()
54-
print(">>> Model Constructed Successfully\n")
5553

56-
if num_gpus > 1:
57-
test_model = multi_gpu_model(test_model, gpus=num_gpus)
54+
num_physical_gpus = len(tf.config.experimental.list_physical_devices('GPU'))
55+
if 1 <= num_gpus <= num_physical_gpus:
56+
devices = ["/gpu:"+str(i) for i in range(num_physical_gpus)]
57+
else:
58+
num_physical_cpu = len(tf.config.experimental.list_physical_devices('CPU'))
59+
devices = ["/cpu:"+str(j) for j in range(num_physical_cpu)]
60+
61+
strategy = tf.distribute.MirroredStrategy(devices)
62+
with strategy.scope():
63+
test_model = constructor.build_model()
64+
test_model.summary()
65+
test_model.compile(loss=keras.losses.categorical_crossentropy,
66+
optimizer=keras.optimizers.Adam(learning_rate=1e-3, decay=1e-4),
67+
metrics=['accuracy'])
5868

59-
test_model.summary()
60-
test_model.compile(loss=keras.losses.categorical_crossentropy,
61-
optimizer=keras.optimizers.Adam(learning_rate=1e-3, decay=1e-4),
62-
metrics=['accuracy'])
69+
print(">>> Model Constructed Successfully\n")
6370

6471
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
6572
x_train = x_train.astype('float32')

examples/v1beta1/trial-images/tf-mnist-with-summaries/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM tensorflow/tensorflow:2.7.0
1+
FROM tensorflow/tensorflow:2.9.1
22

33
ADD examples/v1beta1/trial-images/tf-mnist-with-summaries /opt/tf-mnist-with-summaries
44
WORKDIR /opt/tf-mnist-with-summaries

0 commit comments

Comments
 (0)