Amazon web services AWS SageMaker+;Tensorflow+;GPU
我试图提取ELMo嵌入,并在AWS SageMaker和TensorFlow上运行代码。代码在SageMaker的cpu实例上运行良好,但我想在GPU上运行它。以下是我执行的步骤和错误列表:Amazon web services AWS SageMaker+;Tensorflow+;GPU,amazon-web-services,tensorflow,gpu,amazon-sagemaker,Amazon Web Services,Tensorflow,Gpu,Amazon Sagemaker,我试图提取ELMo嵌入,并在AWS SageMaker和TensorFlow上运行代码。代码在SageMaker的cpu实例上运行良好,但我想在GPU上运行它。以下是我执行的步骤和错误列表: 已启动AWS SageMaker实例:ml.p3.8xlarge-它有8个GPU 启动JuperterLab并为笔记本选择conda_tensorflow_p36 运行以下代码: !!pip3安装tensorflow gpu==1.15 !pip3安装“tensorflow Hub”你有没有想过?你有没有想
!pip3安装“tensorflow Hub”你有没有想过?你有没有想过?
url = "https://tfhub.dev/google/elmo/2"
embed = hub.Module(url)
def defineEmbeddings(start, end, extractions):
embeddings = embed(extractions[start:end],signature="default",as_dict=True)["default"]
return embeddings
def scoreExtractions (embeddings):
config = tf.compat.v1.ConfigProto(log_device_placement=True)
config.gpu_options.allow_growth = True
config.gpu_options.per_process_gpu_memory_fraction = 0.9
with tf.compat.v1.Session(config=config) as sess:
sess.run(tf.global_variables_initializer())
sess.run(tf.tables_initializer())
x = sess.run(embeddings)
return x
with tf.device('/device:GPU:3'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
with tf.Session() as sess:
print(sess.run(c))