Skip to content

Commit 6318437

Browse files
authored
fix bugs due to tf2 release (#447)
1 parent 320d2c1 commit 6318437

File tree

10 files changed

+47
-19
lines changed

10 files changed

+47
-19
lines changed

examples/cloudml-collaborative-filtering/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ Create a new project on GCP and set up GCP credentials:
2626
gcloud auth login
2727
gcloud auth application-default login
2828
```
29+
30+
Enable the following APIS:
31+
- [Dataflow](http://console.cloud.google.com/apis/api/dataflow.googleapis.com)
32+
- [AI Platform](http://console.cloud.google.com/apis/api/ml.googleapis.com)
33+
2934
Using the `preprocessing/config.example.ini` template, create
3035
`preprocessing/config.ini` with the GCP project id fields filled in.
36+
Additionally, you will need to create a GCS bucket. This code assumes a bucket
37+
exists by the name of `[project-id]-bucket`.
3138

3239
Set up your python environment:
3340
```shell
34-
virtualenv venv -p python3
41+
python3 -m venv venv
3542
source ./venv/bin/activate
3643
pip install -r requirements.txt
3744
```
@@ -113,7 +120,8 @@ Model training can be monitored on Tensorboard using the following command:
113120
tensorboard --logdir <path to model dir>/<trial number>
114121
```
115122
Tensorboard's projector, in particular, is very useful for debugging
116-
or analyzing embeddings.
123+
or analyzing embeddings. In the projector tab in Tensorboard, try setting the
124+
label to `name`.
117125

118126
## Serving
119127
Models can be hosted on CAIP, which can be used to make online and batch predictions via JSON requests.

examples/cloudml-collaborative-filtering/bin/run.predict.cloud.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
# TRIAL (optional): The trial number to use.
2323
. ./bin/_common.sh
2424

25+
if [ "$#" -lt 1 ]; then
26+
echo "Illegal number of parameters. Should be >= 1, given $#."
27+
exit 1
28+
fi
29+
2530
MODEL_OUTPUTS_DIR=$1
2631
TRIAL=${2:-${DEFAULT_TRIAL}}
2732

examples/cloudml-collaborative-filtering/bin/run.serve.cloud.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
# TRIAL (optional): The trial number to use.
2323
. ./bin/_common.sh
2424

25+
if [ "$#" -lt 1 ]; then
26+
echo "Illegal number of parameters. Should be >= 1, given $#."
27+
exit 1
28+
fi
29+
2530
MODEL_OUTPUTS_DIR=$1
2631
TRIAL=${2:-${DEFAULT_TRIAL}}
2732

examples/cloudml-collaborative-filtering/bin/run.train.cloud.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
# This should just be a timestamp.
2222
. ./bin/_common.sh
2323

24+
if [ "$#" -lt 1 ]; then
25+
echo "Illegal number of parameters. Should be >= 1, given $#."
26+
exit 1
27+
fi
28+
2429
MODEL_INPUTS_DIR=$1
2530

2631
NOW="$(get_date_time)"
@@ -37,13 +42,13 @@ gcloud ai-platform jobs submit training "${TRAINING_JOB_NAME}" \
3742
--staging-bucket "${OUTPUT_BUCKET}" \
3843
--package-path trainer \
3944
--region us-east1 \
40-
--runtime-version 1.13 \
45+
--runtime-version 1.15 \
4146
--scale-tier "${SCALE_TIER}" \
4247
-- \
4348
--model_dir "${MODEL_PATH}" \
4449
--input_dir "${INPUT_PATH}" \
4550
--tft_dir "${TFT_PATH}" \
46-
--max_steps 300000 \
51+
--max_steps 100000 \
4752
--batch_size 512 \
4853
--user_embed_mult 1.5 \
4954
--item_embed_mult 1 \

examples/cloudml-collaborative-filtering/bin/run.train.local.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
# This should just be a timestamp.
2222
. ./bin/_common.sh
2323

24+
if [ "$#" -lt 1 ]; then
25+
echo "Illegal number of parameters. Should be >= 1, given $#."
26+
exit 1
27+
fi
28+
2429
MODEL_INPUTS_DIR=$1
2530

2631
PROJECT_ID="$(get_project_id)"

examples/cloudml-collaborative-filtering/preprocessing/config.example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ runner = DataflowRunner
44
max_num_workers = 5
55
defaultWorkerLogLevel = INFO
66
log_level = ERROR
7-
zone = us-east1-b
7+
region = us-east1
88

99
[LOCAL]
1010
project = [GCP_PROJECT_ID]

examples/cloudml-collaborative-filtering/preprocessing/run_preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def get_pipeline_options(args, config):
107107
"../setup.py")),
108108
"staging_location": os.path.join(args.job_dir, "staging"),
109109
"temp_location": os.path.join(args.job_dir, "tmp"),
110-
"zone": config.get("zone")
110+
"region": config.get("region"),
111111
})
112112
pipeline_options = beam.pipeline.PipelineOptions(flags=[], **options)
113113
return pipeline_options
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
apache-beam[gcp]>=2.13.0
2-
configparser>=3.7.4
3-
google-api-core>=1.13.0
4-
google-api-python-client>=1.7.9
5-
google-cloud-core>=1.0.2
6-
nose>=1.3.7
7-
tensorflow>=1.14.0
8-
tensorflow-transform>=0.13.0
9-
1+
apache-beam[gcp]>=2.16.0
2+
configparser>=3.7.4
3+
google-api-core>=1.13.0
4+
google-api-python-client>=1.7.9
5+
google-cloud-core>=1.0.2
6+
nose>=1.3.7
7+
tensorboard==1.15.0
8+
tensorflow>=0.15.0,<2.0.0
9+
tensorflow-transform==0.21.2

examples/cloudml-collaborative-filtering/trainer/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import json
2121
import os
2222

23+
from tensorboard.plugins import projector
2324
import tensorflow as tf
24-
from tensorflow.contrib.tensorboard.plugins import projector
2525
import tensorflow_transform as tft
2626

2727
# pylint: disable=g-bad-import-order

examples/cloudml-collaborative-filtering/trainer/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def write_projector_metadata(metadata_dir, tft_dir):
7171
constants.NUM_PROJECTOR_ITEMS)
7272
metadata = user_metadata + item_metadata
7373
metadata_path = os.path.join(metadata_dir, constants.PROJECTOR_PATH)
74-
tf.gfile.MakeDirs(metadata_dir)
75-
with tf.gfile.GFile(metadata_path, "w+") as f:
74+
tf.io.gfile.makedirs(metadata_dir)
75+
with tf.io.gfile.GFile(metadata_path, "w+") as f:
7676
f.write("label\tname\n")
77-
f.write("\n".join(["\t".join(sample) for sample in metadata]))
77+
f.write("\n".join(["{}\t{}".format(label, name) for label, name in metadata]))
7878
return user_indices, item_indices

0 commit comments

Comments
 (0)