簡體   English   中英

Tensorflow 1.15 之后 - 無需安裝 tensorflow-gpu package

[英]Tensorflow after 1.15 - No need to install tensorflow-gpu package

問題

Please confirm that to use both CPU and GPU with TensorFlow after 1.15 , install tensorflow package is enough and tensorflow-gpu is no more required.

背景

仍然看到說明安裝tensorflow-gpu 的文章,例如pip install tensorflow-gpu==2.2.0tensorflow-gpu package 的 PyPi 存儲庫在最新的tensorflow-gpu 2.4.1中處於活動狀態。

Annaconda 文檔還提到了 tensorflow-gpu package。

TensorFlow 是一個通用機器學習庫,但在深度學習應用中最流行。 Z853F30A23CE8B86946C91D67F5C78Z 中的 tensorflow package 支持三種變體,其中之一是 NVIDIA Z52F9EC17CD329 版本。 這是通過安裝元包 tensorflow-gpu 來選擇的:

但是,根據 TensorFlow v2.4.1(截至 2021 年 4 月)核心文檔GPU 支持 - TensorFlow 的舊版本

對於 1.15 及更早版本,CPU 和 GPU 包是分開的:

pip install tensorflow==1.15      # CPU
pip install tensorflow-gpu==1.15  # GPU

根據 TensorFlow 核心指南使用 GPU

TensorFlow 代碼和 tf.keras 模型將透明地在單個 GPU 上運行,無需更改代碼。

根據TensorFlow GPU 與 CPU 的安裝庫之間的差異

只是一個快速(不必要的?)注意......從 TensorFlow 2.0 開始,這些沒有分開,您只需安裝 tensorflow(因為這包括 GPU 支持,如果您安裝了適當的卡)。

因此,希望明確確認 tensorflow-gpu package 只是為了方便(已指定 tensorflow-gpu 等的舊腳本),不再需要。 現在 tensorflow 和 tensorflow-gpu 包之間沒有區別。

在這里對 package 命名感到困惑是合理的。 但是,這是我的理解。 對於tf 1.15更早版本CPUGPU包是分開的:

pip install tensorflow==1.15      # CPU
pip install tensorflow-gpu==1.15  # GPU

因此,如果我想完全在tfCPU版本上工作,我將使用第一個命令 go ,否則,如果我想完全在tfGPU版本上工作,我將使用第二個命令 Z34D1F91FB2E514B85BZFAB 。


現在,在tf 2.0或更高版本中,我們只需要一個可以方便地在兩種硬件上運行的命令 因此,在基於CPUGPU的系統中,我們需要相同的命令來安裝tf ,即:

pip install tensorflow

現在,我們可以在基於CPU的系統上測試它(沒有GPU

import tensorflow as tf 
print(tf.__version__)

print('1: ', tf.config.list_physical_devices('GPU'))
print('2: ', tf.test.is_built_with_cuda)
print('3: ', tf.test.gpu_device_name())
print('4: ', tf.config.get_visible_devices())

2.4.1
1:  []
2:  <function is_built_with_cuda at 0x7f2ce91415f0>
3:  
4:  [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]

或者也在基於CPU的系統上進行測試(使用GPU

2.4.1
1:  [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
2:  <function is_built_with_cuda at 0x7fb6affd0560>
3:  /device:GPU:0
4:  [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'),
     PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

因此,正如您所見,這只是針對CPUGPU案例的單個命令。 希望現在更清楚了。 但直到現在(在tf > = 2中)我們還可以在安裝tf時使用-gpu / -cpu后綴,分別用於GPU / CPU

!pip install tensorflow-gpu 
....
Installing collected packages: tensorflow-gpu
Successfully installed tensorflow-gpu-2.4.1

# -------------------------------------------------------------

!pip install tensorflow-cpu
....
Installing collected packages: tensorflow-cpu
Successfully installed tensorflow-cpu-2.4.1

檢查:來自 tf-team 的類似響應

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM