tensorflow 未知错误:图形执行错误:JIT编译失败,

ryoqjall  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(563)

我尝试使用Tensorflow集线器的通用句子编码器。从集线器下载并提取通用句子编码器,当我尝试预测一个句子时,它显示一个错误说
未知错误:图形执行错误:
JIT编译失败。

import tensorflow_hub as hub

#loading downloaded and untarred universal sentence encoder
embed = hub.load("./universal-sentence-encoder_4/")
  
# passed as an array in embed()
Sentences = [
    "How old are you"
]
embeddings = embed(Sentences)
  
print(embeddings)

并出现错误

2022-11-25 06:29:46.006767: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1616] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 2630 MB memory:  -> device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5
error: Can't find libdevice directory ${CUDA_DIR}/nvvm/libdevice
2022-11-25 06:29:50.652156: W tensorflow/core/framework/op_kernel.cc:1768] UNKNOWN: JIT compilation failed.
---------------------------------------------------------------------------
UnknownError                              Traceback (most recent call last)
Input In [1], in <cell line: 25>()
     17 # Load pre-trained universal sentence encoder model
     18 # embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
     19   
     20 # Sentences for which you want to create embeddings,
     21 # passed as an array in embed()
     22 Sentences = [
     23     "How old are you"
     24 ]
---> 25 embeddings = embed(Sentences)
     27 # Printing embeddings of each sentence
     28 print(embeddings)

File ~/miniconda3/envs/tf/lib/python3.10/site-packages/tensorflow/python/saved_model/load.py:704, in _call_attribute(instance, *args, **kwargs)
    703 def _call_attribute(instance, *args, **kwargs):
--> 704   return instance.__call__(*args, **kwargs)

File ~/miniconda3/envs/tf/lib/python3.10/site-packages/tensorflow/python/util/traceback_utils.py:153, in filter_traceback.<locals>.error_handler(*args, **kwargs)
    151 except Exception as e:
    152   filtered_tb = _process_traceback_frames(e.__traceback__)
--> 153   raise e.with_traceback(filtered_tb) from None
    154 finally:
    155   del filtered_tb

File ~/miniconda3/envs/tf/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:

UnknownError: Graph execution error:

JIT compilation failed.
     [[{{node EncoderDNN/EmbeddingLookup/EmbeddingLookupUnique/embedding_lookup/mod}}]] [Op:__inference_restored_function_body_4561]

我怎么修?我只想让它能用。

u5rb5r59

u5rb5r591#

首先,在CPU回退中使用GPU存在一个错误,tf. estimators()和TensorFlow集线器需要专用硬件。embedding-4
示例:尝试将CUDA路径添加到操作系统的局部变量中,出现错误,请按照说明操作。这些错误表示安装或设置不完整。

import tensorflow as tf
import tensorflow_hub as hub

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
None
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
config = tf.config.experimental.set_memory_growth(physical_devices[0], True)
print(physical_devices)
print(config)

embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")

embeddings = embed([
    "The quick brown fox jumps over the lazy dog.",
    "I am a sentence for which I would like to get its embedding"])
  
print(embeddings)

输出:简单的嵌入层,字到序列与原则的工作。

tf.Tensor(
[[-0.03133015 -0.06338634 -0.01607501 ... -0.03242781 -0.0457574
   0.05370456]
 [ 0.05080863 -0.01652433  0.0157378  ...  0.00976659  0.03170122
   0.01788119]], shape=(2, 512), dtype=float32)

相关问题