tensorflow / recommenders-addons

Additional utils and helpers to extend TensorFlow when build recommendation systems, contributed and maintained by SIG Recommenders.
Apache License 2.0
596 stars 136 forks source link

Demo not working on Apple M1, 'NoneType' object has no attribute 'tfra_hkv_hash_table_of_tensors' #481

Closed Ross-Fan closed 1 day ago

Ross-Fan commented 1 day ago

System information

A clear and concise description of what the bug is. it seems no table resource was created, self._resource_handle = self._create_resource() table_ref = hkv_ops.tfra_hkv_hash_table_of_tensors(

Code to reproduce the issue `

import tensorflow as tf import tensorflow_recommenders_addons as tfra

class DIN_KerasModel(tf.keras.Model): def init(self, embedding_dim, num_items, num_features, name=None): super(DIN_KerasModel, self).init(name=name) self.embedding_dim = 32

self.userID_embs = tfra.dynamic_embedding.keras.layers.BasicEmbedding(8)

    self.userID_embs = tfra.dynamic_embedding.get_variable(
        name="userid_dynamic_embeddings",
        dim=self.embedding_dim,
        initializer=tf.keras.initializers.RandomNormal(-1, 1)
    )

din_keras_model = DIN_KerasModel(embedding_dim=8, num_items=10000, num_features=50)

` Provide a reproducible test case that is the bare minimum necessary to generate the problem.

Other info / logs 2024-11-25 10:07:24.160004: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support. 2024-11-25 10:07:24.160027: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>) Traceback (most recent call last): File "/Users/fanwei/work/moviebox/panlong_jobs/排序/test/tfra_mlen_1m.py", line 204, in <module> app.run(main) File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/absl/app.py", line 308, in run _run_main(main, args) File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/absl/app.py", line 254, in _run_main sys.exit(main(argv)) File "/Users/fanwei/work/moviebox/panlong_jobs/排序/test/tfra_mlen_1m.py", line 194, in main train() File "/Users/fanwei/work/moviebox/panlong_jobs/排序/test/tfra_mlen_1m.py", line 120, in train model = DualChannelsDeepModel(FLAGS.embedding_size, FLAGS.embedding_size, File "/Users/fanwei/work/moviebox/panlong_jobs/排序/test/tfra_mlen_1m.py", line 54, in __init__ self.user_embedding = de.keras.layers.SquashedEmbedding( File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/tensorflow_recommenders_addons/dynamic_embedding/python/keras/layers/embedding.py", line 201, in __init__ self.params = de.get_variable(parameter_name, File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/tensorflow_recommenders_addons/dynamic_embedding/python/ops/dynamic_embedding_variable.py", line 1334, in get_variable var_ = Variable( File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/tensorflow_recommenders_addons/dynamic_embedding/python/ops/dynamic_embedding_variable.py", line 666, in __init__ mht = self.kv_creator.create( File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/tensorflow_recommenders_addons/dynamic_embedding/python/ops/dynamic_embedding_creator.py", line 111, in create return de.CuckooHashTable( File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/tensorflow/python/trackable/resource.py", line 103, in __call__ return previous_getter(*args, **kwargs) File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/tensorflow/python/trackable/resource.py", line 98, in <lambda> previous_getter = lambda *a, **kw: default_resource_creator(None, *a, **kw) File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/tensorflow/python/trackable/resource.py", line 95, in default_resource_creator obj.__init__(*a, **kw) File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/tensorflow_recommenders_addons/dynamic_embedding/python/ops/cuckoo_hashtable_ops.py", line 121, in __init__ self._resource_handle = self._create_resource() File "/Users/fanwei/miniforge3/envs/factormachine/lib/python3.9/site-packages/tensorflow_recommenders_addons/dynamic_embedding/python/ops/cuckoo_hashtable_ops.py", line 155, in _create_resource table_ref = hkv_ops.tfra_hkv_hash_table_of_tensors( AttributeError: 'NoneType' object has no attribute 'tfra_hkv_hash_table_of_tensors' Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

Ross-Fan commented 1 day ago

this issue solved by indicate the device:

self.user_embedding = de.keras.layers.SquashedEmbedding(

    user_embedding_size,
    initializer=embedding_initializer,
    name='user_embedding', devices=['/cpu:0'],)