tensorflow如何使用TPU訓練模型


  首先檢測TPU存在:

tpu = tf.distribute.cluster_resolver.TPUClusterResolver()   #如果先前設置好了TPU_NAME環境變量,不需要再給參數.

 

tpu的返回值為1 or 0 ,1則檢測到了TPU.

 

tf.config.experimental_connect_to_cluster(tpu)

tf.tpu.experimental.initialize_tpu_system(tpu)

strategy = tf.distribute.experimental.TPUStrategy(tpu)

with strategy.scope():

  #define a model

  #compile it

  #train it

 

 

因為這目前還是一個實驗功能,代碼實現可能過一段時間就變了,看官方給的通知吧.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM