显卡保护程序
2019-05-17 本文已影响0人
VanJordan
import os
python_code_raw= r"""
import tensorflow as tf
import time
a = tf.get_variable('a',shape=[2,2],dtype=tf.float32)
b = tf.get_variable('b',shape=[2,2],dtype=tf.float32)
with tf.Session() as sess:
number = 0
start_time = time.time()
while True:
number += 1
sess.run(tf.global_variables_initializer())
sess.run(a*b+b*a+a*a+b*b)
if number % 1000 == 0:
print(time.time()-start_time)
"""
with open('train.py','w') as f:
f.write(python_code_raw)
try:
cmd = "python3 train.py data-bin/iwslt14.tokenized.de-en -a transformer_iwslt_de_en --optimizer adam --lr 0.001 -s de -t en"
os.system(cmd)
finally:
os.remove('train.py')