换电脑了,3060显卡按照之前的方法 https://blog.csdn.net/weixin_41631106/article/details/119547755 ,用conda安装的tensorflow1.15版本虽然测试显示gpu可用,但实际跑代码时,一直卡在一个界面。
原因:3060显卡要求cuda11.0以上,而tensorflow1.15支持cuda10.0且官方已不再维护。
解决办法: https://blog.csdn.net/wu496963386/article/details/109583045#t1
Note:Ubuntu显卡驱动为470。
tensorflow1.15配置
先直接通过这两条命令装,成功最好,据官方 GitHub 说python版本需要3.8。
pip install nvidia-pyindex pip install nvidia-tensorflow
开始是参照 https://blog.csdn.net/wu496963386/article/details/109583045 在python3.7安装如下依赖,各种报错。试过降pip版本为21.2.2,最后看到官方的GitHub要求的是python3.8版本,升级了一下python,就不报错了。
执行pip install nvidia-tensorflow时,会自己重新下载下面的各种包,然后等很长时间。
2022.7.23重新配了一遍,python环境下直接装成功,没有报错。
(tf1.15) juling@zephyrus:~$ pip install nvidia-tensorflow[horovod] Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting nvidia-tensorflow[horovod] Downloading https://developer.download.nvidia.com/compute/redist/nvidia-tensorflow/nvidia_tensorflow-1.15.5%2Bnv22.06-5077300-cp38-cp38-linux_x86_64.whl (683.1 MB) |████████████████████████████████| 683.1 MB 447 kB/s Collecting nvidia-cuda-nvcc-cu117>=11.7 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-cuda-nvcc-cu117/nvidia_cuda_nvcc_cu117-11.7.64-py3-none-manylinux1_x86_64.whl (17.3 MB) |████████████████████████████████| 17.3 MB 426 kB/s Requirement already satisfied: wheel>=0.26 in ./anaconda3/envs/tf1.15/lib/python3.8/site-packages (from nvidia-tensorflow[horovod]) (0.37.1) Collecting google-pasta>=0.1.6 Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB) |████████████████████████████████| 57 kB 360 kB/s Collecting astunparse==1.6.3 Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB) Collecting nvidia-cuda-runtime-cu117>=11.7 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-cuda-runtime-cu117/nvidia_cuda_runtime_cu117-11.7.60-py3-none-manylinux1_x86_64.whl (849 kB) |████████████████████████████████| 849 kB 314 kB/s Collecting wrapt>=1.11.1 Downloading wrapt-1.14.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (81 kB) |████████████████████████████████| 81 kB 835 kB/s Collecting nvidia-nccl-cu116>=2.12 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-nccl-cu116/nvidia_nccl_cu116-2.12.12-py3-none-manylinux1_x86_64.whl (164.8 MB) |████████████████████████████████| 164.8 MB 357 kB/s Collecting tensorboard<1.16.0,>=1.15.0 Downloading https://developer.download.nvidia.com/compute/redist/tensorboard/tensorboard-1.15.0-py2.py3-none-any.whl (1.6 kB) Collecting gast==0.3.3 Downloading gast-0.3.3-py2.py3-none-any.whl (9.7 kB) Collecting absl-py>=0.9.0 Downloading absl_py-1.2.0-py3-none-any.whl (123 kB) |████████████████████████████████| 123 kB 559 kB/s Collecting astor==0.8.1 Downloading astor-0.8.1-py2.py3-none-any.whl (27 kB) Collecting protobuf<4.0.0,>=3.6.1 Downloading protobuf-3.20.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.0 MB) |████████████████████████████████| 1.0 MB 642 kB/s Collecting opt-einsum>=2.3.2 Downloading opt_einsum-3.3.0-py3-none-any.whl (65 kB) |████████████████████████████████| 65 kB 784 kB/s Collecting nvidia-curand-cu117>=10.2 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-curand-cu117/nvidia_curand_cu117-10.2.10.50-py3-none-manylinux1_x86_64.whl (54.6 MB) |████████████████████████████████| 54.6 MB 443 kB/s Collecting nvidia-cusparse-cu117>=11.7 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-cusparse-cu117/nvidia_cusparse_cu117-11.7.3.50-py3-none-manylinux1_x86_64.whl (169.6 MB) |████████████████████████████████| 169.6 MB 422 kB/s Collecting nvidia-cudnn-cu116>=8.4 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-cudnn-cu116/nvidia_cudnn_cu116-8.4.0.27-py3-none-manylinux1_x86_64.whl (719.3 MB) |████████████████████████████████| 719.3 MB 167 kB/s Collecting grpcio>=1.8.6 Downloading grpcio-1.47.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB) |████████████████████████████████| 4.5 MB 239 kB/s WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response'))': /compute/redist/tensorflow-estimator/ Collecting tensorflow-estimator==1.15.1 Downloading tensorflow_estimator-1.15.1-py2.py3-none-any.whl (503 kB) |████████████████████████████████| 503 kB 200 kB/s Collecting termcolor>=1.1.0 Downloading termcolor-1.1.0.tar.gz (3.9 kB) Collecting numpy>=1.20.0 Downloading numpy-1.23.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.1 MB) |████████████████████████████████| 17.1 MB 267 kB/s Collecting nvidia-cuda-cupti-cu117>=11.7 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-cuda-cupti-cu117/nvidia_cuda_cupti_cu117-11.7.50-py3-none-manylinux1_x86_64.whl (11.8 MB) |████████████████████████████████| 11.8 MB 267 kB/s Collecting six>=1.10.0 Downloading six-1.16.0-py2.py3-none-any.whl (11 kB) Collecting h5py==2.10.0 Downloading h5py-2.10.0-cp38-cp38-manylinux1_x86_64.whl (2.9 MB) |████████████████████████████████| 2.9 MB 260 kB/s Collecting nvidia-cufft-cu117>=10.7 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-cufft-cu117/nvidia_cufft_cu117-10.7.2.50-py3-none-manylinux1_x86_64.whl (102.8 MB) |████████████████████████████████| 102.8 MB 535 kB/s Collecting keras-applications>=1.0.8 Downloading Keras_Applications-1.0.8-py3-none-any.whl (50 kB) |████████████████████████████████| 50 kB 318 kB/s Collecting nvidia-dali-nvtf-plugin==1.14.0+nv22.06 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-dali-nvtf-plugin/nvidia_dali_nvtf_plugin-1.14.0%2Bnv22.06-5077300-cp38-cp38-linux_x86_64.whl (120 kB) |████████████████████████████████| 120 kB 623 kB/s Collecting nvidia-cusolver-cu117>=11.3 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-cusolver-cu117/nvidia_cusolver_cu117-11.3.5.50-py3-none-manylinux1_x86_64.whl (118.8 MB) |████████████████████████████████| 118.8 MB 672 kB/s Collecting keras-preprocessing>=1.0.5 Downloading Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB) |████████████████████████████████| 42 kB 619 kB/s Collecting nvidia-cublas-cu117>=11.10 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-cublas-cu117/nvidia_cublas_cu117-11.10.1.25-py3-none-manylinux1_x86_64.whl (333.1 MB) |████████████████████████████████| 333.1 MB 666 kB/s Collecting nvidia-horovod==0.24.3+nv22.06 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-horovod/nvidia_horovod-0.24.3%2Bnv22.06-5077300-cp38-cp38-linux_x86_64.whl (25.0 MB) |████████████████████████████████| 25.0 MB 602 kB/s Collecting nvidia-dali-cuda110==1.14.0 Downloading https://developer.download.nvidia.com/compute/redist/nvidia-dali-cuda110/nvidia_dali_cuda110-1.14.0-4921308-py3-none-manylinux2014_x86_64.whl (316.3 MB) |████████████████████████████████| 316.3 MB 660 kB/s Collecting cloudpickle Downloading cloudpickle-2.1.0-py3-none-any.whl (25 kB) Collecting psutil Downloading psutil-5.9.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (284 kB) |████████████████████████████████| 284 kB 405 kB/s Collecting pyyaml Downloading PyYAML-6.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (701 kB) |████████████████████████████████| 701 kB 1.2 MB/s Requirement already satisfied: setuptools in ./anaconda3/envs/tf1.15/lib/python3.8/site-packages (from nvidia-cublas-cu117>=11.10->nvidia-tensorflow[horovod]) (61.2.0) Building wheels for collected packages: termcolor Building wheel for termcolor (setup.py) ... done Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4848 sha256=edb5e2be6bd2bf711624be6fb37bdb2e614cfd81477d2edc7fe7658e16ffb160 Stored in directory: /tmp/pip-ephem-wheel-cache-vgk480nx/wheels/a0/16/9c/5473df82468f958445479c59e784896fa24f4a5fc024b0f501 Successfully built termcolor Installing collected packages: six, numpy, nvidia-dali-cuda110, h5py, wrapt, termcolor, tensorflow-estimator, tensorboard, pyyaml, psutil, protobuf, opt-einsum, nvidia-nccl-cu116, nvidia-dali-nvtf-plugin, nvidia-cusparse-cu117, nvidia-cusolver-cu117, nvidia-curand-cu117, nvidia-cufft-cu117, nvidia-cudnn-cu116, nvidia-cuda-runtime-cu117, nvidia-cuda-nvcc-cu117, nvidia-cuda-cupti-cu117, nvidia-cublas-cu117, keras-preprocessing, keras-applications, grpcio, google-pasta, gast, cloudpickle, astunparse, astor, absl-py, nvidia-tensorflow, nvidia-horovod Successfully installed absl-py-1.2.0 astor-0.8.1 astunparse-1.6.3 cloudpickle-2.1.0 gast-0.3.3 google-pasta-0.2.0 grpcio-1.47.0 h5py-2.10.0 keras-applications-1.0.8 keras-preprocessing-1.1.2 numpy-1.23.1 nvidia-cublas-cu117-11.10.1.25 nvidia-cuda-cupti-cu117-11.7.50 nvidia-cuda-nvcc-cu117-11.7.64 nvidia-cuda-runtime-cu117-11.7.60 nvidia-cudnn-cu116-8.4.0.27 nvidia-cufft-cu117-10.7.2.50 nvidia-curand-cu117-10.2.10.50 nvidia-cusolver-cu117-11.3.5.50 nvidia-cusparse-cu117-11.7.3.50 nvidia-dali-cuda110-1.14.0 nvidia-dali-nvtf-plugin-1.14.0+nv22.6 nvidia-horovod-0.24.3+nv22.6 nvidia-nccl-cu116-2.12.12 nvidia-tensorflow-1.15.5+nv22.6 opt-einsum-3.3.0 protobuf-3.20.1 psutil-5.9.1 pyyaml-6.0 six-1.16.0 tensorboard-1.15.0 tensorflow-estimator-1.15.1 termcolor-1.1.0 wrapt-1.14.1
装完以后的包版本如下:
验证gpu是可用的。
tensorflow2.6配置
最近调试代码,发现tensorflow1的静态图真是反人类,有必要迁移一下代码到tf2了。。。
对于tf2,conda安装tensorflow也会自动安装对应的cudatoolkit和cudnn,但是conda只支持tensorflow2.4及以前的版本,tensorflow2.5及以后的版本只支持pip。而tf2.5以后的版本才支持cuda11。
1. conda和pip查询包的可用版本方法:
conda search package-name pip index versions package-name
2. conda先装cuda=11.3.1,cudnn=8.2.1,再装tensorflow-gpu=2.6.5
conda install cuda==11.3.1 conda installcudnn==8.2.1 pip install tensorflow-gpu==2.6.5 -i https://pypi.douban.com/simple
通过tf.test.is_gpu_available()验证gpu是True.
Be First to Comment