System information
- OS Platform: Google Colab / macOS Big Sur 11.2.3
- TensorFlow version and how it was installed (source or binary): 2.4.1 (Colab), 2.4.0-rc0 (0.a3)
- TensorFlow-Recommenders-Addons version and how it was installed (source or binary):
The Colab's addon was installed via !pip install -q --upgrade tensorflow-recommenders-addons
My local system's addon was installed via binary code.
- Python version: 3.7.10 (Colab), 3.8.8 (Local)
- Is GPU used? (yes/no):
I've tried None, and GPU on Colab. I don't know if the binary one uses a GPU or not.
Describe the bug
The cell after 4. Train the model raises an exception:
![image](https://user-images.githubusercontent.com/56426474/115942679-46687a80-a460-11eb-8863-3b60121e744d.png)
My local env:
![image](https://user-images.githubusercontent.com/56426474/115942731-83347180-a460-11eb-9644-b819c9f46c11.png)
![image](https://user-images.githubusercontent.com/56426474/115942743-93e4e780-a460-11eb-957a-bc5f25c3fcf2.png)
![image](https://user-images.githubusercontent.com/56426474/115942712-6a2bc080-a460-11eb-8343-78e3caf9c77a.png)
FYI, I added a cell at the beginning of the ipynb file to install the addons:
!pip install -q --upgrade tensorflow-recommenders-addons
!pip install -q --upgrade tensorflow-datasets
The ipynb file with exception log:
embedding_variable_tutorial.ipynb
Other info / logs
Colab exception message:
InvalidArgumentError Traceback (most recent call last)
in ()
11
12 if name=="main":
---> 13 train(10)
10 frames
in train(epoch)
4 for (_, batch) in enumerate(dataset_train):
5 with tf.GradientTape() as tape:
----> 6 loss = model(batch)
7 total_loss = np.append(total_loss, loss)
8 grads = tape.gradient(loss, model.trainable_variables)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
1010 with autocast_variable.enable_auto_cast_variables(
1011 self._compute_dtype_object):
-> 1012 outputs = call_fn(inputs, *args, **kwargs)
1013
1014 if self._activity_regularizer:
in call(self, batch)
37 params=self.user_embeddings,
38 ids=user_id_val,
---> 39 name="user-id-weights")
40 user_id_weights = tf.gather(user_id_weights, user_id_idx)
41
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/embedding_ops.py in embedding_lookup_v2(params, ids, max_norm, name)
392 ValueError: If params
is empty.
393 """
--> 394 return embedding_lookup(params, ids, "div", name, max_norm=max_norm)
395
396
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/embedding_ops.py in embedding_lookup(params, ids, partition_strategy, name, validate_indices, max_norm)
326 name=name,
327 max_norm=max_norm,
--> 328 transform_fn=None)
329
330
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/embedding_ops.py in _embedding_lookup_and_transform(params, ids, partition_strategy, name, max_norm, transform_fn)
136 with ops.colocate_with(params[0]):
137 result = _clip(
--> 138 array_ops.gather(params[0], ids, name=name), ids, max_norm)
139 if transform_fn:
140 result = transform_fn(result)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/array_ops.py in gather(failed resolving arguments)
4811 # TODO(apassos) find a less bad way of detecting resource variables
4812 # without introducing a circular dependency.
-> 4813 return params.sparse_read(indices, name=name)
4814 except AttributeError:
4815 return gen_array_ops.gather_v2(params, indices, axis, name=name)
/usr/local/lib/python3.7/dist-packages/tensorflow_recommenders_addons/embedding_variable/python/ops/embedding_variable_ops.py in sparse_read(self, indices, name)
425 raise errors_impl.InvalidArgumentError(
426 None, None,
--> 427 "type of indices is not match with EmbeddingVariable key type.")
428 with ops.name_scope("Gather" if name is None else name) as name:
429 resource_variable_ops.variable_accessed(self)
InvalidArgumentError: type of indices is not match with EmbeddingVariable key type.
Local exception message:
InvalidArgumentError Traceback (most recent call last)
in
11
12 if name=="main":
---> 13 train(10)
in train(epoch)
4 for (_, batch) in enumerate(dataset_train):
5 with tf.GradientTape() as tape:
----> 6 loss = model(batch)
7 total_loss = np.append(total_loss, loss)
8 grads = tape.gradient(loss, model.trainable_variables)
~/miniforge3/envs/tf24/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
1005 with autocast_variable.enable_auto_cast_variables(
1006 self._compute_dtype_object):
-> 1007 outputs = call_fn(inputs, *args, **kwargs)
1008
1009 if self._activity_regularizer:
in call(self, batch)
34
35 user_id_val, user_id_idx = np.unique(user_id, return_inverse=True)
---> 36 user_id_weights = tf.nn.embedding_lookup(
37 params=self.user_embeddings,
38 ids=user_id_val,
~/miniforge3/envs/tf24/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
~/miniforge3/envs/tf24/lib/python3.8/site-packages/tensorflow/python/ops/embedding_ops.py in embedding_lookup_v2(params, ids, max_norm, name)
392 ValueError: If params
is empty.
393 """
--> 394 return embedding_lookup(params, ids, "div", name, max_norm=max_norm)
395
396
~/miniforge3/envs/tf24/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
~/miniforge3/envs/tf24/lib/python3.8/site-packages/tensorflow/python/ops/embedding_ops.py in embedding_lookup(params, ids, partition_strategy, name, validate_indices, max_norm)
320 name=name)
321
--> 322 return _embedding_lookup_and_transform(
323 params=params,
324 ids=ids,
~/miniforge3/envs/tf24/lib/python3.8/site-packages/tensorflow/python/ops/embedding_ops.py in _embedding_lookup_and_transform(params, ids, partition_strategy, name, max_norm, transform_fn)
136 with ops.colocate_with(params[0]):
137 result = _clip(
--> 138 array_ops.gather(params[0], ids, name=name), ids, max_norm)
139 if transform_fn:
140 result = transform_fn(result)
~/miniforge3/envs/tf24/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
~/miniforge3/envs/tf24/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py in gather(failed resolving arguments)
4811 # TODO(apassos) find a less bad way of detecting resource variables
4812 # without introducing a circular dependency.
-> 4813 return params.sparse_read(indices, name=name)
4814 except AttributeError:
4815 return gen_array_ops.gather_v2(params, indices, axis, name=name)
~/miniforge3/envs/tf24/lib/python3.8/site-packages/tensorflow_recommenders_addons/embedding_variable/python/ops/embedding_variable_ops.py in sparse_read(self, indices, name)
437 """Reads the value of this variable sparsely, using gather
."""
438 if indices.dtype != self._ktype:
--> 439 raise errors_impl.InvalidArgumentError(
440 None, None,
441 "type of indices is not match with EmbeddingVariable key type.")
InvalidArgumentError: type of indices is not match with EmbeddingVariable key type.