Skip to content

Commit c59c33b

Browse files
teijeongtensorflower-gardener
authored andcommitted
Change py_binary targets to py_strict_binary
PiperOrigin-RevId: 370811583
1 parent b10200f commit c59c33b

File tree

8 files changed

+40
-26
lines changed

8 files changed

+40
-26
lines changed

tensorflow_model_optimization/BUILD

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# used to optimize machine learning models for deployment and execution.
66
#
77
# https://github.com/tensorflow/model-optimization
8-
load("//tensorflow_model_optimization:tensorflow_model_optimization.bzl", "py_strict_library")
8+
load("//tensorflow_model_optimization:tensorflow_model_optimization.bzl", "py_strict_binary", "py_strict_library")
99

1010
package(default_visibility = ["//visibility:public"])
1111

@@ -24,11 +24,13 @@ py_strict_library(
2424
],
2525
)
2626

27-
py_binary(
27+
py_strict_binary(
2828
name = "build_docs",
2929
srcs = ["build_docs.py"],
3030
python_version = "PY3",
3131
deps = [
32+
# absl:app dep1,
33+
# absl/flags dep1,
3234
# tensorflow_docs/api_generator:generate_lib dep1,
3335
"//third_party/tensorflow_model_optimization",
3436
],

tensorflow_model_optimization/python/examples/cluster_preserve_qat/keras/BUILD

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
load("//tensorflow_model_optimization:tensorflow_model_optimization.bzl", "py_strict_binary")
2+
13
licenses(["notice"])
24

3-
py_binary(
5+
py_strict_binary(
46
name = "mnist_cnn",
57
srcs = [
68
"mnist_cnn.py",
@@ -10,7 +12,10 @@ py_binary(
1012
# absl:app dep1,
1113
# numpy dep1,
1214
# tensorflow dep1,
15+
"//tensorflow_model_optimization/python/core/clustering/keras:cluster",
16+
"//tensorflow_model_optimization/python/core/clustering/keras:cluster_config",
1317
"//tensorflow_model_optimization/python/core/quantization/keras:quantize",
18+
"//tensorflow_model_optimization/python/core/quantization/keras/collaborative_optimizations/cluster_preserve:cluster_utils",
1419
"//tensorflow_model_optimization/python/core/quantization/keras/collaborative_optimizations/cluster_preserve:default_8bit_cluster_preserve_quantize_scheme",
1520
],
1621
)

tensorflow_model_optimization/python/examples/clustering/keras/mnist/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("//tensorflow_model_optimization:tensorflow_model_optimization.bzl", "py_strict_binary")
2+
13
package(
24
default_visibility = ["//visibility:public"],
35
)
@@ -9,7 +11,7 @@ filegroup(
911
srcs = glob(["**"]),
1012
)
1113

12-
py_binary(
14+
py_strict_binary(
1315
name = "mnist_cnn",
1416
srcs = [
1517
"mnist_cnn.py",
@@ -19,8 +21,6 @@ py_binary(
1921
# absl:app dep1,
2022
# absl/flags dep1,
2123
# tensorflow dep1,
22-
# python/keras tensorflow dep2,
23-
# python/keras/optimizer_v2 tensorflow dep2,
2424
"//tensorflow_model_optimization/python/core/clustering/keras:cluster",
2525
"//tensorflow_model_optimization/python/core/clustering/keras:cluster_config",
2626
"//tensorflow_model_optimization/python/core/clustering/keras:clustering_callbacks",
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1+
load("//tensorflow_model_optimization:tensorflow_model_optimization.bzl", "py_strict_binary")
2+
13
licenses(["notice"]) # Apache 2.0
24

3-
py_binary(
5+
py_strict_binary(
46
name = "mnist_cnn",
57
srcs = [
68
"mnist_cnn.py",
79
],
810
python_version = "PY3",
911
deps = [
10-
# numpy dep1,
1112
# tensorflow dep1,
12-
# python/keras tensorflow dep2,
1313
"//tensorflow_model_optimization/python/core/quantization/keras:quantize",
1414
],
1515
)
1616

17-
py_binary(
17+
py_strict_binary(
1818
name = "mnist_cnn_cont_quant",
1919
srcs = [
2020
"mnist_cnn_cont_quant.py",
@@ -23,7 +23,6 @@ py_binary(
2323
deps = [
2424
# numpy dep1,
2525
# tensorflow dep1,
26-
# python/keras tensorflow dep2,
2726
"//tensorflow_model_optimization/python/core/quantization/keras:quantize",
2827
],
2928
)

tensorflow_model_optimization/python/examples/quantization_with_sparsity/keras/BUILD

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
load("//tensorflow_model_optimization:tensorflow_model_optimization.bzl", "py_strict_binary")
2+
13
licenses(["notice"])
24

3-
py_binary(
5+
py_strict_binary(
46
name = "mnist_cnn",
57
srcs = [
68
"mnist_cnn.py",
@@ -12,6 +14,8 @@ py_binary(
1214
# tensorflow dep1,
1315
"//tensorflow_model_optimization/python/core/quantization/keras:quantize",
1416
"//tensorflow_model_optimization/python/core/quantization/keras/collaborative_optimizations/prune_preserve:default_8bit_prune_preserve_quantize_scheme",
15-
"//tensorflow_model_optimization/python/core/sparsity/keras",
17+
"//tensorflow_model_optimization/python/core/sparsity/keras:prune",
18+
"//tensorflow_model_optimization/python/core/sparsity/keras:pruning_callbacks",
19+
"//tensorflow_model_optimization/python/core/sparsity/keras:pruning_schedule",
1620
],
1721
)

tensorflow_model_optimization/python/examples/sparsity/keras/imdb/BUILD

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("//tensorflow_model_optimization:tensorflow_model_optimization.bzl", "py_strict_binary")
2+
13
package(
24
default_visibility = ["//visibility:public"],
35
)
@@ -9,7 +11,7 @@ filegroup(
911
srcs = glob(["**"]),
1012
)
1113

12-
py_binary(
14+
py_strict_binary(
1315
name = "imdb_lstm",
1416
srcs = [
1517
"imdb_lstm.py",

tensorflow_model_optimization/python/examples/sparsity/keras/imdb/imdb_lstm.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@
1818
compared to simpler, much faster methods such as TF-IDF+LogReg.
1919
"""
2020

21-
from __future__ import print_function
22-
# import g3
2321
import numpy as np
22+
import tensorflow as tf
2423

25-
import tensorflow.keras as keras
26-
import tensorflow.keras.backend as K
27-
import tensorflow.keras.preprocessing.sequence as sequence
2824
from tensorflow_model_optimization.python.core.sparsity.keras import prune
2925
from tensorflow_model_optimization.python.core.sparsity.keras import pruning_callbacks
3026
from tensorflow_model_optimization.python.core.sparsity.keras import pruning_schedule
3127
from tensorflow_model_optimization.python.core.sparsity.keras import pruning_wrapper
3228

29+
keras = tf.keras
30+
K = tf.keras.backend
31+
3332

3433
def print_model_sparsity(pruned_model):
3534
"""Prints sparsity for the pruned layers in the model.
@@ -75,8 +74,8 @@ def _get_sparsity(weights):
7574
print(len(x_test), "test sequences")
7675

7776
print("Pad sequences (samples x time)")
78-
x_train = sequence.pad_sequences(x_train, maxlen=maxlen)
79-
x_test = sequence.pad_sequences(x_test, maxlen=maxlen)
77+
x_train = keras.sequence.pad_sequences(x_train, maxlen=maxlen)
78+
x_test = keras.sequence.pad_sequences(x_test, maxlen=maxlen)
8079
print("x_train shape:", x_train.shape)
8180
print("x_test shape:", x_test.shape)
8281

tensorflow_model_optimization/python/examples/sparsity/keras/mnist/BUILD

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("//tensorflow_model_optimization:tensorflow_model_optimization.bzl", "py_strict_binary")
2+
13
package(
24
default_visibility = ["//visibility:public"],
35
)
@@ -9,7 +11,7 @@ filegroup(
911
srcs = glob(["**"]),
1012
)
1113

12-
py_binary(
14+
py_strict_binary(
1315
name = "mnist_estimator",
1416
srcs = [
1517
"dataset.py",
@@ -23,12 +25,14 @@ py_binary(
2325
# tensorflow dep1,
2426
"//tensorflow_model_optimization/python/core/sparsity/keras:estimator_utils",
2527
"//tensorflow_model_optimization/python/core/sparsity/keras:prune",
26-
"//third_party/tensorflow_models/official/r1/utils/logs",
28+
"//tensorflow_model_optimization/python/core/sparsity/keras:pruning_schedule",
29+
"//third_party/tensorflow_models/official/common:distribute_utils",
30+
"//third_party/tensorflow_models/official/r1/utils/logs:hooks_helper",
2731
"//third_party/tensorflow_models/official/utils",
2832
],
2933
)
3034

31-
py_binary(
35+
py_strict_binary(
3236
name = "mnist_cnn",
3337
srcs = [
3438
"mnist_cnn.py",
@@ -41,11 +45,10 @@ py_binary(
4145
"//tensorflow_model_optimization/python/core/sparsity/keras:prune",
4246
"//tensorflow_model_optimization/python/core/sparsity/keras:pruning_callbacks",
4347
"//tensorflow_model_optimization/python/core/sparsity/keras:pruning_schedule",
44-
"//tensorflow_model_optimization/python/core/sparsity/keras:pruning_wrapper",
4548
],
4649
)
4750

48-
py_binary(
51+
py_strict_binary(
4952
name = "mnist_e2e",
5053
srcs = [
5154
"mnist_e2e.py",

0 commit comments

Comments
 (0)