Error in embedding layer on M1 Mac

This post is created on bahalf of @Ed_Sykes since he didn’t take the time to create the post upon my request.

This is the error on M1 Mac using Anaconda - TF: 2.10.0; python: 3.10.4

Interestingly, all the labs work just fine and on another machine with GPU the assignment works fine too.

2022-09-16 11:37:19.024204: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Epoch 1/30

InvalidArgumentError Traceback (most recent call last)
/Volumes/GoogleDrive-107870226340842906740/My Drive/My_Research/Intro_Tensorflow/tensorflow-1-public/C3/W2/assignment/C3W2_Assignment.ipynb Cell 30 in <cell line: 3>()
1 model = create_model(NUM_WORDS, EMBEDDING_DIM, MAXLEN)
----> 3 history = model.fit(train_padded_seq, train_label_seq, epochs=30, validation_data=(val_padded_seq, val_label_seq))

File ~/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback..error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.traceback)
68 # To get the full stack trace, call:
69 # tf.debugging.disable_traceback_filtering()
—> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb

File ~/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/tensorflow/python/eager/execute.py:54, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
52 try:
53 ctx.ensure_initialized()
—> 54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
57 if name is not None:

InvalidArgumentError: Graph execution error:

Detected at node ‘sequential/embedding/embedding_lookup’ defined at (most recent call last):
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/runpy.py”, line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/runpy.py”, line 86, in _run_code
exec(code, run_globals)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/ipykernel_launcher.py”, line 17, in
app.launch_new_instance()
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/traitlets/config/application.py”, line 846, in launch_instance
app.start()
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/ipykernel/kernelapp.py”, line 712, in start
self.io_loop.start()
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/tornado/platform/asyncio.py”, line 215, in start
self.asyncio_loop.run_forever()
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/asyncio/base_events.py”, line 600, in run_forever
self._run_once()
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/asyncio/base_events.py”, line 1896, in _run_once
handle._run()
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/asyncio/events.py”, line 80, in _run
self._context.run(self._callback, *self._args)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 510, in dispatch_queue
await self.process_one()
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 499, in process_one
await dispatch(*args)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 406, in dispatch_shell
await result
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 730, in execute_request
reply_content = await reply_content
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/ipykernel/ipkernel.py”, line 383, in do_execute
res = shell.run_cell(
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/ipykernel/zmqshell.py”, line 528, in run_cell
return super().run_cell(*args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 2881, in run_cell
result = self._run_cell(
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 2936, in _run_cell
return runner(coro)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/IPython/core/async_helpers.py”, line 129, in pseudo_sync_runner
coro.send(None)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3135, in run_cell_async
has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3338, in run_ast_nodes
if await self.run_code(code, result, async=asy):
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3398, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “/var/folders/61/2rsxbqtx2zqbwlb914ssc_zm0000gn/T/ipykernel_10463/646807408.py”, line 3, in <cell line: 3>
history = model.fit(train_padded_seq, train_label_seq, epochs=30, validation_data=(val_padded_seq, val_label_seq))
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/utils/traceback_utils.py”, line 65, in error_handler
return fn(*args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py”, line 1564, in fit
tmp_logs = self.train_function(iterator)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py”, line 1160, in train_function
return step_function(self, iterator)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py”, line 1146, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py”, line 1135, in run_step
outputs = model.train_step(data)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py”, line 993, in train_step
y_pred = self(x, training=True)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/utils/traceback_utils.py”, line 65, in error_handler
return fn(*args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py”, line 557, in call
return super().call(*args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/utils/traceback_utils.py”, line 65, in error_handler
return fn(*args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/base_layer.py”, line 1097, in call
outputs = call_fn(inputs, *args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/utils/traceback_utils.py”, line 96, in error_handler
return fn(*args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/sequential.py”, line 410, in call
return super().call(inputs, training=training, mask=mask)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/functional.py”, line 510, in call
return self._run_internal_graph(inputs, training=training, mask=mask)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/functional.py”, line 667, in _run_internal_graph
outputs = node.layer(*args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/utils/traceback_utils.py”, line 65, in error_handler
return fn(*args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/base_layer.py”, line 1097, in call
outputs = call_fn(inputs, *args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/utils/traceback_utils.py”, line 96, in error_handler
return fn(*args, **kwargs)
File “/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/layers/core/embedding.py”, line 208, in call
out = tf.nn.embedding_lookup(self.embeddings, inputs)
Node: ‘sequential/embedding/embedding_lookup’
indices[10,52] = 1038 is not in [0, 1000)
[[{{node sequential/embedding/embedding_lookup}}]] [Op:__inference_train_function_723]

Feedback after looking at his notebook:

There are a few things that look odd in the notebook though. Please fix these and confirm that the notebook works:

  1. In fit_tokenizer, num_words should not be set to len(train_sentences). This would explain why embedding lookup would error out when fitting the model.
  2. In seq_and_pad, padding is not set when invoking pad_sequences.
1 Like

Thank you @balaji.ambresh