Skip to content

Commit c016773

Browse files
implement review suggestions (#1062)
#1062 was merged in order to meet the release cutoff. Here are the outstanding changes requested in #1062.
1 parent 879f5b6 commit c016773

File tree

2 files changed

+58
-45
lines changed

2 files changed

+58
-45
lines changed

examples/usecases/transformers-next-item-prediction.ipynb

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"name": "stderr",
9090
"output_type": "stream",
9191
"text": [
92-
"2023-04-17 10:53:46.419725: I tensorflow/core/platform/cpu_feature_guard.cc:194] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE3 SSE4.1 SSE4.2 AVX\n",
92+
"2023-04-19 01:35:02.207465: I tensorflow/core/platform/cpu_feature_guard.cc:194] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE3 SSE4.1 SSE4.2 AVX\n",
9393
"To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
9494
]
9595
},
@@ -106,9 +106,9 @@
106106
"text": [
107107
"/usr/local/lib/python3.8/dist-packages/merlin/dtypes/mappings/torch.py:43: UserWarning: PyTorch dtype mappings did not load successfully due to an error: No module named 'torch'\n",
108108
" warn(f\"PyTorch dtype mappings did not load successfully due to an error: {exc.msg}\")\n",
109-
"2023-04-17 10:53:47.662982: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
110-
"2023-04-17 10:53:47.663430: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
111-
"2023-04-17 10:53:47.663612: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n"
109+
"2023-04-19 01:35:03.422817: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
110+
"2023-04-19 01:35:03.423265: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
111+
"2023-04-19 01:35:03.423447: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n"
112112
]
113113
},
114114
{
@@ -125,17 +125,17 @@
125125
"name": "stderr",
126126
"output_type": "stream",
127127
"text": [
128-
"2023-04-17 10:53:47.910504: I tensorflow/core/platform/cpu_feature_guard.cc:194] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE3 SSE4.1 SSE4.2 AVX\n",
128+
"2023-04-19 01:35:03.695996: I tensorflow/core/platform/cpu_feature_guard.cc:194] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE3 SSE4.1 SSE4.2 AVX\n",
129129
"To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
130-
"2023-04-17 10:53:47.911325: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
131-
"2023-04-17 10:53:47.911536: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
132-
"2023-04-17 10:53:47.911695: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
133-
"2023-04-17 10:53:48.671264: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
134-
"2023-04-17 10:53:48.671486: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
135-
"2023-04-17 10:53:48.671654: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
136-
"2023-04-17 10:53:48.671765: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:42] Overriding orig_value setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.\n",
137-
"2023-04-17 10:53:48.671774: I tensorflow/core/common_runtime/gpu/gpu_process_state.cc:222] Using CUDA malloc Async allocator for GPU: 0\n",
138-
"2023-04-17 10:53:48.671836: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1637] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 24576 MB memory: -> device: 0, name: Quadro RTX 8000, pci bus id: 0000:08:00.0, compute capability: 7.5\n",
130+
"2023-04-19 01:35:03.696824: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
131+
"2023-04-19 01:35:03.697038: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
132+
"2023-04-19 01:35:03.697196: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
133+
"2023-04-19 01:35:04.438845: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
134+
"2023-04-19 01:35:04.439063: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
135+
"2023-04-19 01:35:04.439222: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:996] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
136+
"2023-04-19 01:35:04.439332: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:42] Overriding orig_value setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.\n",
137+
"2023-04-19 01:35:04.439340: I tensorflow/core/common_runtime/gpu/gpu_process_state.cc:222] Using CUDA malloc Async allocator for GPU: 0\n",
138+
"2023-04-19 01:35:04.439400: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1637] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 24576 MB memory: -> device: 0, name: Quadro RTX 8000, pci bus id: 0000:08:00.0, compute capability: 7.5\n",
139139
"/usr/local/lib/python3.8/dist-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
140140
" from .autonotebook import tqdm as notebook_tqdm\n"
141141
]
@@ -859,7 +859,7 @@
859859
"text": [
860860
"/usr/local/lib/python3.8/dist-packages/keras/initializers/initializers_v2.py:120: UserWarning: The initializer TruncatedNormal is unseeded and being called multiple times, which will return identical values each time (even if the initializer is unseeded). Please update your code to provide a seed to the initializer, or avoid using the same initalizer instance more than once.\n",
861861
" warnings.warn(\n",
862-
"2023-04-17 10:53:56.422412: I tensorflow/stream_executor/cuda/cuda_dnn.cc:424] Loaded cuDNN version 8700\n"
862+
"2023-04-19 01:35:13.112516: I tensorflow/stream_executor/cuda/cuda_dnn.cc:424] Loaded cuDNN version 8700\n"
863863
]
864864
},
865865
{
@@ -893,28 +893,28 @@
893893
"name": "stderr",
894894
"output_type": "stream",
895895
"text": [
896-
"2023-04-17 10:54:07.156255: W tensorflow/core/grappler/optimizers/loop_optimizer.cc:907] Skipping loop optimization for Merge node with control input: model/xl_net_block/sequential_block_5/replace_masked_embeddings/RaggedWhere/Assert/AssertGuard/branch_executed/_95\n"
896+
"2023-04-19 01:35:23.514177: W tensorflow/core/grappler/optimizers/loop_optimizer.cc:907] Skipping loop optimization for Merge node with control input: model/xl_net_block/sequential_block_5/replace_masked_embeddings/RaggedWhere/Assert/AssertGuard/branch_executed/_95\n"
897897
]
898898
},
899899
{
900900
"name": "stdout",
901901
"output_type": "stream",
902902
"text": [
903-
"2720/2720 [==============================] - 79s 25ms/step - loss: 7.3254 - recall_at_10: 0.1956 - mrr_at_10: 0.0829 - ndcg_at_10: 0.1092 - map_at_10: 0.0829 - precision_at_10: 0.0196 - regularization_loss: 0.0000e+00 - loss_batch: 7.3244\n",
903+
"2720/2720 [==============================] - 77s 24ms/step - loss: 7.3177 - recall_at_10: 0.2005 - mrr_at_10: 0.0877 - ndcg_at_10: 0.1141 - map_at_10: 0.0877 - precision_at_10: 0.0201 - regularization_loss: 0.0000e+00 - loss_batch: 7.3157\n",
904904
"Epoch 2/5\n",
905-
"2720/2720 [==============================] - 67s 24ms/step - loss: 6.1170 - recall_at_10: 0.3607 - mrr_at_10: 0.1683 - ndcg_at_10: 0.2137 - map_at_10: 0.1683 - precision_at_10: 0.0361 - regularization_loss: 0.0000e+00 - loss_batch: 6.1153\n",
905+
"2720/2720 [==============================] - 67s 24ms/step - loss: 6.1038 - recall_at_10: 0.3626 - mrr_at_10: 0.1703 - ndcg_at_10: 0.2157 - map_at_10: 0.1703 - precision_at_10: 0.0363 - regularization_loss: 0.0000e+00 - loss_batch: 6.1022\n",
906906
"Epoch 3/5\n",
907-
"2720/2720 [==============================] - 68s 25ms/step - loss: 5.5579 - recall_at_10: 0.4363 - mrr_at_10: 0.2080 - ndcg_at_10: 0.2620 - map_at_10: 0.2080 - precision_at_10: 0.0436 - regularization_loss: 0.0000e+00 - loss_batch: 5.5554\n",
907+
"2720/2720 [==============================] - 63s 23ms/step - loss: 5.5767 - recall_at_10: 0.4321 - mrr_at_10: 0.2067 - ndcg_at_10: 0.2600 - map_at_10: 0.2067 - precision_at_10: 0.0432 - regularization_loss: 0.0000e+00 - loss_batch: 5.5751\n",
908908
"Epoch 4/5\n",
909-
"2720/2720 [==============================] - 69s 25ms/step - loss: 5.3061 - recall_at_10: 0.4666 - mrr_at_10: 0.2246 - ndcg_at_10: 0.2818 - map_at_10: 0.2246 - precision_at_10: 0.0467 - regularization_loss: 0.0000e+00 - loss_batch: 5.3038\n",
909+
"2720/2720 [==============================] - 64s 23ms/step - loss: 5.3249 - recall_at_10: 0.4631 - mrr_at_10: 0.2223 - ndcg_at_10: 0.2792 - map_at_10: 0.2223 - precision_at_10: 0.0463 - regularization_loss: 0.0000e+00 - loss_batch: 5.3230\n",
910910
"Epoch 5/5\n",
911-
"2720/2720 [==============================] - 70s 25ms/step - loss: 5.1669 - recall_at_10: 0.4821 - mrr_at_10: 0.2327 - ndcg_at_10: 0.2917 - map_at_10: 0.2327 - precision_at_10: 0.0482 - regularization_loss: 0.0000e+00 - loss_batch: 5.1647\n"
911+
"2720/2720 [==============================] - 68s 25ms/step - loss: 5.1779 - recall_at_10: 0.4796 - mrr_at_10: 0.2318 - ndcg_at_10: 0.2904 - map_at_10: 0.2318 - precision_at_10: 0.0480 - regularization_loss: 0.0000e+00 - loss_batch: 5.1764\n"
912912
]
913913
},
914914
{
915915
"data": {
916916
"text/plain": [
917-
"<keras.callbacks.History at 0x7fb47895b0a0>"
917+
"<keras.callbacks.History at 0x7fa9a45e20a0>"
918918
]
919919
},
920920
"execution_count": 15,
@@ -961,27 +961,27 @@
961961
"name": "stderr",
962962
"output_type": "stream",
963963
"text": [
964-
"2023-04-17 10:59:53.461458: W tensorflow/core/grappler/optimizers/loop_optimizer.cc:907] Skipping loop optimization for Merge node with control input: model/xl_net_block/sequential_block_5/replace_masked_embeddings/RaggedWhere/Assert/AssertGuard/branch_executed/_71\n"
964+
"2023-04-19 01:40:55.868086: W tensorflow/core/grappler/optimizers/loop_optimizer.cc:907] Skipping loop optimization for Merge node with control input: model/xl_net_block/sequential_block_5/replace_masked_embeddings/RaggedWhere/Assert/AssertGuard/branch_executed/_71\n"
965965
]
966966
},
967967
{
968968
"name": "stdout",
969969
"output_type": "stream",
970970
"text": [
971-
"340/340 [==============================] - 11s 20ms/step - loss: 4.7125 - recall_at_10: 0.5556 - mrr_at_10: 0.3126 - ndcg_at_10: 0.3704 - map_at_10: 0.3126 - precision_at_10: 0.0556 - regularization_loss: 0.0000e+00 - loss_batch: 4.7121\n"
971+
"340/340 [==============================] - 10s 18ms/step - loss: 4.7317 - recall_at_10: 0.5562 - mrr_at_10: 0.3114 - ndcg_at_10: 0.3695 - map_at_10: 0.3114 - precision_at_10: 0.0556 - regularization_loss: 0.0000e+00 - loss_batch: 4.7313\n"
972972
]
973973
},
974974
{
975975
"data": {
976976
"text/plain": [
977-
"{'loss': 4.712502956390381,\n",
978-
" 'recall_at_10': 0.5555964112281799,\n",
979-
" 'mrr_at_10': 0.3125925064086914,\n",
980-
" 'ndcg_at_10': 0.37040114402770996,\n",
981-
" 'map_at_10': 0.3125925064086914,\n",
982-
" 'precision_at_10': 0.05555963143706322,\n",
977+
"{'loss': 4.731719017028809,\n",
978+
" 'recall_at_10': 0.556216835975647,\n",
979+
" 'mrr_at_10': 0.3114089369773865,\n",
980+
" 'ndcg_at_10': 0.36954960227012634,\n",
981+
" 'map_at_10': 0.3114089369773865,\n",
982+
" 'precision_at_10': 0.0556216724216938,\n",
983983
" 'regularization_loss': 0.0,\n",
984-
" 'loss_batch': 4.561119079589844}"
984+
" 'loss_batch': 4.579279899597168}"
985985
]
986986
},
987987
"execution_count": 16,
@@ -1091,15 +1091,15 @@
10911091
"name": "stdout",
10921092
"output_type": "stream",
10931093
"text": [
1094-
"INFO:tensorflow:Assets written to: /tmp/tmpvdxq5w0m/model.savedmodel/assets\n"
1094+
"INFO:tensorflow:Assets written to: /tmp/tmpk2jcmm5x/model.savedmodel/assets\n"
10951095
]
10961096
},
10971097
{
10981098
"name": "stderr",
10991099
"output_type": "stream",
11001100
"text": [
1101-
"INFO:tensorflow:Assets written to: /tmp/tmpvdxq5w0m/model.savedmodel/assets\n",
1102-
"/usr/local/lib/python3.8/dist-packages/merlin/models/tf/utils/tf_utils.py:100: CustomMaskWarning: Custom mask layers require a config and must override get_config. When loading, the custom mask layer must be passed to the custom_objects argument.\n",
1101+
"INFO:tensorflow:Assets written to: /tmp/tmpk2jcmm5x/model.savedmodel/assets\n",
1102+
"/usr/local/lib/python3.8/dist-packages/merlin/models/tf/utils/tf_utils.py:101: CustomMaskWarning: Custom mask layers require a config and must override get_config. When loading, the custom mask layer must be passed to the custom_objects argument.\n",
11031103
" config[key] = tf.keras.utils.serialize_keras_object(maybe_value)\n",
11041104
"/usr/local/lib/python3.8/dist-packages/merlin/models/tf/core/combinators.py:288: CustomMaskWarning: Custom mask layers require a config and must override get_config. When loading, the custom mask layer must be passed to the custom_objects argument.\n",
11051105
" config[i] = tf.keras.utils.serialize_keras_object(layer)\n",
@@ -1286,7 +1286,7 @@
12861286
"output_type": "stream",
12871287
"text": [
12881288
"INFO:tensorflow:Assets written to: /workspace/ensemble/1_predicttensorflowtriton/1/model.savedmodel/assets\n",
1289-
"/usr/local/lib/python3.8/dist-packages/merlin/models/tf/utils/tf_utils.py:100: CustomMaskWarning: Custom mask layers require a config and must override get_config. When loading, the custom mask layer must be passed to the custom_objects argument.\n",
1289+
"/usr/local/lib/python3.8/dist-packages/merlin/models/tf/utils/tf_utils.py:101: CustomMaskWarning: Custom mask layers require a config and must override get_config. When loading, the custom mask layer must be passed to the custom_objects argument.\n",
12901290
" config[key] = tf.keras.utils.serialize_keras_object(maybe_value)\n",
12911291
"/usr/local/lib/python3.8/dist-packages/merlin/models/tf/core/combinators.py:288: CustomMaskWarning: Custom mask layers require a config and must override get_config. When loading, the custom mask layer must be passed to the custom_objects argument.\n",
12921292
" config[i] = tf.keras.utils.serialize_keras_object(layer)\n",
@@ -1397,8 +1397,8 @@
13971397
{
13981398
"data": {
13991399
"text/plain": [
1400-
"array([[-3.497796 , -3.5179672 , 2.9564662 , ..., -0.45221543,\n",
1401-
" -0.8475621 , -1.217337 ]], dtype=float32)"
1400+
"array([[-4.958611 , -4.977809 , 0.66012955, ..., -2.32572 ,\n",
1401+
" -0.6495375 , -2.4545593 ]], dtype=float32)"
14021402
]
14031403
},
14041404
"execution_count": 20,
@@ -1428,7 +1428,8 @@
14281428
}
14291429
],
14301430
"source": [
1431-
"response.as_numpy('city_id_list/categorical_output').shape"
1431+
"predictions = response.as_numpy('city_id_list/categorical_output')\n",
1432+
"predictions.shape"
14321433
]
14331434
},
14341435
{
@@ -1457,7 +1458,8 @@
14571458
}
14581459
],
14591460
"source": [
1460-
"wf.output_schema.select_by_name('city_id_list').to_pandas()['properties.embedding_sizes.cardinality'][0]"
1461+
"cardinality = wf.output_schema['city_id_list'].properties['embedding_sizes']['cardinality']\n",
1462+
"cardinality"
14611463
]
14621464
},
14631465
{

tests/unit/tf/examples/test_usecase_transformers_next_item_prediction.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
execute=False,
1919
)
2020
@pytest.mark.notebook
21-
def test_next_item_prediction(tb):
21+
def test_next_item_prediction(tb, tmpdir):
2222
tb.inject(
23-
"""
23+
f"""
2424
import os, random
2525
from datetime import datetime, timedelta
2626
from merlin.datasets.synthetic import generate_data
@@ -33,16 +33,27 @@ def generate_date():
3333
return date
3434
df['checkin'] = [generate_date() for _ in range(df.shape[0])]
3535
df['checkout'] = [generate_date() for _ in range(df.shape[0])]
36-
df.to_csv('/tmp/train_set.csv')
36+
df.to_csv('{tmpdir}/train_set.csv')
3737
"""
3838
)
3939
tb.cells[4].source = tb.cells[4].source.replace("get_booking('/workspace/data')", "")
4040
tb.cells[4].source = tb.cells[4].source.replace(
41-
"read_csv('/workspace/data/train_set.csv'", "read_csv('/tmp/train_set.csv'"
41+
"read_csv('/workspace/data/train_set.csv'", f"read_csv('{tmpdir}/train_set.csv'"
4242
)
4343
tb.cells[31].source = tb.cells[31].source.replace("epochs=5", "epochs=1")
44-
tb.cells[37].source = tb.cells[37].source.replace("/workspace/ensemble", "/tmp/ensemble")
44+
tb.cells[37].source = tb.cells[37].source.replace("/workspace/ensemble", f"{tmpdir}/ensemble")
4545
tb.execute_cell(list(range(0, 38)))
4646

47-
with utils.run_triton_server("/tmp/ensemble", grpc_port=8001):
47+
with utils.run_triton_server(f"{tmpdir}/ensemble", grpc_port=8001):
4848
tb.execute_cell(list(range(38, len(tb.cells))))
49+
50+
tb.inject(
51+
"""
52+
logits_count = predictions.shape[1]
53+
"""
54+
)
55+
tb.execute_cell(len(tb.cells) - 1)
56+
57+
cardinality = tb.ref("cardinality")
58+
logits_count = tb.ref("logits_count")
59+
assert logits_count == cardinality

0 commit comments

Comments
 (0)