cuda113 cudnn821 兼容 pytorch tensorlow的方案 pytorch1.10 tensor2.6.0

cuda113 cudnn821

重点内容前置

9 代码实现log

(py38torchtf) C:\Users\A_A>conda create -n py38torchtf python=3.8

(torch0508) C:\Users\A_A>conda activate py38torchtf
    
(py38torchtf) C:\Users\A_A>conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge

(py38torchtf) C:\Users\A_A>python
Python 3.8.16 (default, Mar  2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True

(py38torchtf) C:\Users\A_A>pip install tensorflow-gpu==2.6.0 -i https://pypi.douban.com/simple


>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
    from tensorflow.python.eager import context
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\python\eager\context.py", line 32, in <module>
    from tensorflow.core.framework import function_pb2
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\function_pb2.py", line 16, in <module>
    from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\attr_value_pb2.py", line 16, in <module>
    from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\tensor_pb2.py", line 16, in <module>
    from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\resource_handle_pb2.py", line 16, in <module>
    from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\tensor_shape_pb2.py", line 36, in <module>
    _descriptor.FieldDescriptor(
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\google\protobuf\descriptor.py", line 561, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
>>> exit()

(py38torchtf) C:\Users\A_A>pip install protobuf==3.20.1 -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple


(py38torchtf) C:\Users\A_A>python
Python 3.8.16 (default, Mar  2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.test.is_gpu_available()
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2023-05-09 21:02:58.664337: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-05-09 21:03:00.923971: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /device:GPU:0 with 2149 MB memory:  -> device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5
True
>>> tf.test.is_built_with_cuda()
True
>>> exit()

(py38torchtf) C:\Users\A_A>


(py38torchtf) C:\Users\A_A>pip install ipykernel -i https://pypi.douban.com/simple


(py38torchtf) C:\Users\A_A>python -m ipykernel install --user --name py38torchtf

Installed kernelspec py38torchtf in C:\Users\A_A\AppData\Roaming\jupyter\kernels\py38torchtf


(py38torchtf) C:\Users\A_A>


(py38torchtf) C:\Users\A_A>cd /d D:\Auser

(py38torchtf) D:\Auser>jupyter notebook



## 剩下的虚拟环境报错说http等原因,仍然没能解决,以后用上面的install来做吧

当前windows中有NVIDIA GeForce GTX 1650 ,驱动版本:512.89, 需要配套哪个版本的cuda和cudnn,用来兼容安装pytorch-gpu和tensorflow-gpu,并给出兼容的pytorch-GPU版本和tensorflow-GPU版本

总结:

1)当conda安装提示需要更新numpy才可以安装tensor,并尝试numpy安装仍然不成功之后需要用pip的方式安装tensor;仍然有问题,根据提示安装相关包即可。

2)完成上述工作需要将上述内容总结,并完成虚拟环境配置的复制,尽量整理到封装的docker之类的信息中。


2. 正题:选择cuda11.3 cudnn 8.2.1

很完整cuda和cudnn安装的参考资料:https://blog.csdn.net/m0_45447650/article/details/123704930

一次性安装tensorflow torch参考资料:https://blog.csdn.net/xiao_yun_zi/article/details/124046964

cuda:https://developer.nvidia.com/cuda-toolkit-archive

cudnn:https://developer.nvidia.com/rdp/cudnn-archive

cudnn安装成功提示:https://blog.csdn.net/qq_40968179/article/details/124240224

3. 安装pytorch1.10.0 GPU tensorflow-GPU 2.6.0

Pytorch官网

https://pytorch.org/get-started/previous-versions/

(torch0508) C:\Users\A_A>conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge


    
(torch0508) C:\Users\A_A>pip install tensorflow-gpu==2.6.0 -i https://pypi.douban.com/simplepy

        
==> 这里还要添加  pip install protobuf==3.20.1  具体看下一步import tensorflow之后的信息

安装pytorch 成功

>>>torch.cuda.is_available()
True
>>>torch.__version__
'1.10.0'

安装tensorflow-gpu2.6.0 成功

测试参考文献:https://blog.csdn.net/yuan2019035055/article/details/129901579

>>> tf.test.is_gpu_available()
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2023-05-09 01:39:58.018763: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-05-09 01:40:07.189620: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /device:GPU:0 with 2149 MB memory:  -> device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5
True
>>>tf.config.list_physical_devices('GPU')  
>>>True

import tensorflow as tf
print(tf.test.is_built_with_cuda())
print(tf.test.is_gpu_available())

tensorflow 和cuda对照表:

https://tensorflow.google.cn/install/source_windows?hl=zh-cn#gpu

pytorch: 离线安装参考文献:

https://blog.csdn.net/Despereaux_/article/details/129322034


4.虚拟环境文件打包复制:

虚拟文件打包迁移参考文件:https://www.codenong.com/cd7c0e626aedc335011d/

将windows中的conda虚拟环境删除

conda remove --name <env_name> --all

备份虚拟环境,以防止当前环境因为后期开发问题导致使用失败:

To copy a conda virtual environment in Windows, you can follow these steps:

  1. Open the Anaconda prompt or any command prompt that has access to conda.
  2. Activate the source environment that you want to copy by typing the following command: conda activate source_env where “source_env” is the name of the environment that you want to copy.
  3. Export the environment specifications to a YAML file using the following command: conda env export > environment.yml
  4. Create a new environment with the same packages and dependencies as the source environment by running the following command: conda env create -f environment.yml -n new_env where “new_env” is the name of the new environment that you want to create.
  5. Activate the new environment by running the following command: conda activate new_env

实测:

(torch0508) C:\Users\A_A>conda env export > cuda113cudnn821torch10tensor26.yml

5 具体dbug过程

使用pip安装tensorflow:

(torch0508) C:\Users\A_A>pip install tensorflow-gpu==2.6.0 -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple
Collecting tensorflow-gpu==2.6.0
  Downloading https://pypi.doubanio.com/packages/2f/ad/c16cfadfc4c80e13a8679d556aa849fc34dcd2f2ba078d224a68a0809743/tensorflow_gpu-2.6.0-cp38-cp38-win_amd64.whl (423.3 MB)
     ---------------------------------------- 423.3/423.3 MB 1.5 MB/s eta 0:00:00
Requirement already satisfied: grpcio<2.0,>=1.37.0 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (1.51.1)
Collecting absl-py~=0.10
  Using cached https://pypi.doubanio.com/packages/97/75/f5e61fb67ecbe45c31035b17562464e11b91a2b8a351bae5ca0db2969e3b/absl_py-0.15.0-py3-none-any.whl (132 kB)
Requirement already satisfied: wheel~=0.35 in d:\aworkstation\anaconda3\envs\torch0508\lib\site-packages (from tensorflow-gpu==2.6.0) (0.38.4)
Requirement already satisfied: google-pasta~=0.2 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (0.2.0)
Collecting flatbuffers~=1.12.0
  Using cached https://pypi.doubanio.com/packages/eb/26/712e578c5f14e26ae3314c39a1bdc4eb2ec2f4ddc89b708cf8e0a0d20423/flatbuffers-1.12-py2.py3-none-any.whl (15 kB)
Collecting wrapt~=1.12.1
  Using cached wrapt-1.12.1-cp38-cp38-win_amd64.whl
Collecting termcolor~=1.1.0
  Using cached termcolor-1.1.0-py3-none-any.whl
Requirement already satisfied: keras-preprocessing~=1.1.2 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (1.1.2)
Requirement already satisfied: gast==0.4.0 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (0.4.0)
Collecting six~=1.15.0
  Using cached https://pypi.doubanio.com/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting clang~=5.0
  Using cached clang-5.0-py3-none-any.whl
Collecting h5py~=3.1.0
  Using cached https://pypi.doubanio.com/packages/93/3a/f94b993a8db766983b972f5905cb3f0e655bcb6620088fa2b9141e74ff36/h5py-3.1.0-cp38-cp38-win_amd64.whl (2.7 MB)
Collecting keras~=2.6
  Using cached https://pypi.doubanio.com/packages/d5/80/34e55d7e3ed9cf18020929460f969de1bf82cf2f509c639b358ae2b25618/keras-2.12.0-py2.py3-none-any.whl (1.7 MB)
Collecting typing-extensions~=3.7.4
  Using cached https://pypi.doubanio.com/packages/60/7a/e881b5abb54db0e6e671ab088d079c57ce54e8a01a3ca443f561ccadb37e/typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
Collecting tensorboard~=2.6
  Using cached https://pypi.doubanio.com/packages/aa/80/f7233129f75d0d1b35e67df3a48010fffd21ccde124847e3c33d503fef01/tensorboard-2.12.2-py3-none-any.whl (5.6 MB)
Collecting protobuf>=3.9.2
  Using cached https://pypi.doubanio.com/packages/25/ca/79af03ceec0f9439d8fb5c2c8d99454c5c4f8c7fe00c8e7dbb280a8177c8/protobuf-4.22.3-cp38-cp38-win_amd64.whl (420 kB)
Requirement already satisfied: opt-einsum~=3.3.0 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (3.3.0)
Collecting tensorflow-estimator~=2.6
  Using cached https://pypi.doubanio.com/packages/d1/e1/c3596da404e2c47561a2bb392397208925e65be6f61bd3081e630371d5e8/tensorflow_estimator-2.12.0-py2.py3-none-any.whl (440 kB)
Collecting numpy~=1.19.2
  Using cached https://pypi.doubanio.com/packages/5a/13/25a83b9aae5fe9460b1997f5ba48814783d7f460bbbd8cadd96e1481ddf0/numpy-1.19.5-cp38-cp38-win_amd64.whl (13.3 MB)
Requirement already satisfied: astunparse~=1.6.3 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (1.6.3)
Requirement already satisfied: setuptools>=41.0.0 in d:\aworkstation\anaconda3\envs\torch0508\lib\site-packages (from tensorboard~=2.6->tensorflow-gpu==2.6.0) (66.0.0)
Collecting google-auth-oauthlib<1.1,>=0.5
  Using cached https://pypi.doubanio.com/packages/4a/07/8d9a8186e6768b55dfffeb57c719bc03770cf8a970a074616ae6f9e26a57/google_auth_oauthlib-1.0.0-py2.py3-none-any.whl (18 kB)
Collecting tensorboard-plugin-wit>=1.6.0
  Using cached https://pypi.doubanio.com/packages/e0/68/e8ecfac5dd594b676c23a7f07ea34c197d7d69b3313afdf8ac1b0a9905a2/tensorboard_plugin_wit-1.8.1-py3-none-any.whl (781 kB)
Requirement already satisfied: markdown>=2.6.8 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorboard~=2.6->tensorflow-gpu==2.6.0) (3.4.1)
Requirement already satisfied: werkzeug>=1.0.1 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorboard~=2.6->tensorflow-gpu==2.6.0) (2.2.2)
Collecting tensorboard-data-server<0.8.0,>=0.7.0
  Using cached https://pypi.doubanio.com/packages/9d/cc/6f07c0043b44b3c3879ecfec1b8a450b6f5e3f8dccfedc9f5f1bc2c650e6/tensorboard_data_server-0.7.0-py3-none-any.whl (2.4 kB)
Collecting google-auth<3,>=1.6.3
  Using cached https://pypi.doubanio.com/packages/da/cc/13eb3d0b151252e1d2bafc52f412be05c3789b0f655caf5eed298cf8056c/google_auth-2.17.3-py2.py3-none-any.whl (178 kB)
Requirement already satisfied: requests<3,>=2.21.0 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorboard~=2.6->tensorflow-gpu==2.6.0) (2.28.2)
Collecting pyasn1-modules>=0.2.1
  Downloading https://pypi.doubanio.com/packages/cd/8e/bea464350e1b8c6ed0da3a312659cb648804a08af6cacc6435867f74f8bd/pyasn1_modules-0.3.0-py2.py3-none-any.whl (181 kB)
     ---------------------------------------- 181.3/181.3 kB 3.6 MB/s eta 0:00:00
Collecting cachetools<6.0,>=2.0.0
  Using cached https://pypi.doubanio.com/packages/db/14/2b48a834d349eee94677e8702ea2ef98b7c674b090153ea8d3f6a788584e/cachetools-5.3.0-py3-none-any.whl (9.3 kB)
Collecting rsa<5,>=3.1.4
  Using cached https://pypi.doubanio.com/packages/49/97/fa78e3d2f65c02c8e1268b9aba606569fe97f6c8f7c2d74394553347c145/rsa-4.9-py3-none-any.whl (34 kB)
Requirement already satisfied: requests-oauthlib>=0.7.0 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from google-auth-oauthlib<1.1,>=0.5->tensorboard~=2.6->tensorflow-gpu==2.6.0) (1.3.1)
Requirement already satisfied: importlib-metadata>=4.4 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from markdown>=2.6.8->tensorboard~=2.6->tensorflow-gpu==2.6.0) (6.0.0)
Collecting urllib3<1.27,>=1.21.1
  Using cached https://pypi.doubanio.com/packages/7b/f5/890a0baca17a61c1f92f72b81d3c31523c99bec609e60c292ea55b387ae8/urllib3-1.26.15-py2.py3-none-any.whl (140 kB)
Requirement already satisfied: certifi>=2017.4.17 in d:\aworkstation\anaconda3\envs\torch0508\lib\site-packages (from requests<3,>=2.21.0->tensorboard~=2.6->tensorflow-gpu==2.6.0) (2022.12.7)
Requirement already satisfied: idna<4,>=2.5 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from requests<3,>=2.21.0->tensorboard~=2.6->tensorflow-gpu==2.6.0) (3.4)
Collecting charset-normalizer<4,>=2
  Using cached https://pypi.doubanio.com/packages/26/20/83e1804a62b25891c4e770c94d9fd80233bbb3f2a51c4fadee7a196e5a5b/charset_normalizer-3.1.0-cp38-cp38-win_amd64.whl (96 kB)
Requirement already satisfied: MarkupSafe>=2.1.1 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from werkzeug>=1.0.1->tensorboard~=2.6->tensorflow-gpu==2.6.0) (2.1.2)
Collecting zipp>=0.5
  Using cached https://pypi.doubanio.com/packages/5b/fa/c9e82bbe1af6266adf08afb563905eb87cab83fde00a0a08963510621047/zipp-3.15.0-py3-none-any.whl (6.8 kB)
Collecting pyasn1<0.6.0,>=0.4.6
  Downloading https://pypi.doubanio.com/packages/14/e5/b56a725cbde139aa960c26a1a3ca4d4af437282e20b5314ee6a3501e7dfc/pyasn1-0.5.0-py2.py3-none-any.whl (83 kB)
     ---------------------------------------- 83.9/83.9 kB 4.6 MB/s eta 0:00:00
Collecting oauthlib>=3.0.0
  Using cached https://pypi.doubanio.com/packages/7e/80/cab10959dc1faead58dc8384a781dfbf93cb4d33d50988f7a69f1b7c9bbe/oauthlib-3.2.2-py3-none-any.whl (151 kB)
Installing collected packages: wrapt, typing-extensions, termcolor, tensorboard-plugin-wit, flatbuffers, clang, zipp, urllib3, tensorflow-estimator, tensorboard-data-server, six, pyasn1, protobuf, oauthlib, numpy, keras, charset-normalizer, cachetools, rsa, pyasn1-modules, h5py, absl-py, google-auth, google-auth-oauthlib, tensorboard, tensorflow-gpu
  Attempting uninstall: typing-extensions
    Found existing installation: typing_extensions 4.5.0
    Uninstalling typing_extensions-4.5.0:
      Successfully uninstalled typing_extensions-4.5.0
  Attempting uninstall: numpy
    Found existing installation: numpy 1.24.3
    Uninstalling numpy-1.24.3:
      Successfully uninstalled numpy-1.24.3
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchtext 0.15.1 requires tqdm, which is not installed.
spacy 3.4.4 requires catalogue<2.1.0,>=2.0.6, which is not installed.
spacy 3.4.4 requires cymem<2.1.0,>=2.0.2, which is not installed.
spacy 3.4.4 requires jinja2, which is not installed.
spacy 3.4.4 requires langcodes<4.0.0,>=3.2.0, which is not installed.
spacy 3.4.4 requires murmurhash<1.1.0,>=0.28.0, which is not installed.
spacy 3.4.4 requires packaging>=20.0, which is not installed.
spacy 3.4.4 requires pathy>=0.3.5, which is not installed.
spacy 3.4.4 requires preshed<3.1.0,>=3.0.2, which is not installed.
spacy 3.4.4 requires smart-open<7.0.0,>=5.2.1, which is not installed.
spacy 3.4.4 requires spacy-legacy<3.1.0,>=3.0.10, which is not installed.
spacy 3.4.4 requires spacy-loggers<2.0.0,>=1.0.0, which is not installed.
spacy 3.4.4 requires srsly<3.0.0,>=2.4.3, which is not installed.
spacy 3.4.4 requires thinc<8.2.0,>=8.1.0, which is not installed.
spacy 3.4.4 requires tqdm<5.0.0,>=4.38.0, which is not installed.
spacy 3.4.4 requires wasabi<1.1.0,>=0.9.1, which is not installed.
matplotlib 3.6.3 requires contourpy>=1.0.1, which is not installed.
matplotlib 3.6.3 requires cycler>=0.10, which is not installed.
matplotlib 3.6.3 requires fonttools>=4.22.0, which is not installed.
matplotlib 3.6.3 requires packaging>=20.0, which is not installed.
matplotlib 3.6.3 requires pillow>=6.2.0, which is not installed.
matplotlib 3.6.3 requires pyparsing>=2.2.1, which is not installed.
matplotlib 3.6.3 requires python-dateutil>=2.7, which is not installed.
imbalanced-learn 0.9.1 requires joblib>=1.0.0, which is not installed.
imbalanced-learn 0.9.1 requires scikit-learn>=1.1.0, which is not installed.
imbalanced-learn 0.9.1 requires scipy>=1.3.2, which is not installed.
imbalanced-learn 0.9.1 requires threadpoolctl>=2.0.0, which is not installed.
d2l 0.17.5 requires pandas==1.2.4, which is not installed.
torchtext 0.15.1 requires torch==2.0.0, but you have torch 1.10.0 which is incompatible.
torchdata 0.6.0 requires torch==2.0.0, but you have torch 1.10.0 which is incompatible.
d2l 0.17.5 requires matplotlib==3.5.1, but you have matplotlib 3.6.3 which is incompatible.
d2l 0.17.5 requires numpy==1.21.5, but you have numpy 1.19.5 which is incompatible.
d2l 0.17.5 requires requests==2.25.1, but you have requests 2.28.2 which is incompatible.
Successfully installed absl-py-0.15.0 cachetools-5.3.0 charset-normalizer-3.1.0 clang-5.0 flatbuffers-1.12 google-auth-2.17.3 google-auth-oauthlib-1.0.0 h5py-3.1.0 keras-2.12.0 numpy-1.19.5 oauthlib-3.2.2 protobuf-4.22.3 pyasn1-0.5.0 pyasn1-modules-0.3.0 rsa-4.9 six-1.15.0 tensorboard-2.12.2 tensorboard-data-server-0.7.0 tensorboard-plugin-wit-1.8.1 tensorflow-estimator-2.12.0 tensorflow-gpu-2.6.0 termcolor-1.1.0 typing-extensions-3.7.4.3 urllib3-1.26.15 wrapt-1.12.1 zipp-3.15.0

(torch0508) C:\Users\A_A>python
Python 3.8.16 (default, Mar  2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
    from tensorflow.python.eager import context
  File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\python\eager\context.py", line 32, in <module>
    from tensorflow.core.framework import function_pb2
  File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\core\framework\function_pb2.py", line 16, in <module>
    from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
  File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\core\framework\attr_value_pb2.py", line 16, in <module>
    from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
  File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\core\framework\tensor_pb2.py", line 16, in <module>
    from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
  File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\core\framework\resource_handle_pb2.py", line 16, in <module>
    from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
  File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\core\framework\tensor_shape_pb2.py", line 36, in <module>
    _descriptor.FieldDescriptor(
  File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\google\protobuf\descriptor.py", line 561, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
>>>

参考解决方案:
https://blog.csdn.net/weixin_44808574/article/details/128225048

pip install protobuf==3.20.1
tf.test.is_gpu_available()

6 更新conda等信息

更新conda:

conda update -n base -c defaults conda

更新pip:

conda upgrade pip
conda upgrade conda

7 其他信息:

当时尝试了很多版本都不成功,主要问题是tensor死活上不去,pytorch没事,包括conda和pip都用了就是不行。

重构计划:将原来显卡的非必要驱动,通过控制面板的程序卸载,将原来的cudnn8.9 改成cudnn8.2.1,重装cuda11.3,使用了某管家清理注册表。

卸载参考:https://blog.csdn.net/weixin_44606139/article/details/127493438

如果遇到http或者等镜像问题,可以参考以下解决方案:

更改镜像源:https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

当时使用env_copy.yml 文件生成新的env的时候,出现了以下信息:
    raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

failed

CondaEnvException: Pip failed

可以考虑更换镜像为国内源。但是我没能成功解决

8 配置jupyter

参考文献:https://blog.csdn.net/qq_43203949/article/details/108524056

# 模板
pip install ipykernel

# 实测:
(torch0508) C:\Users\A_A>pip install ipykernel -i https://pypi.douban.com/simple --user

# 模板
python -m ipykernel install --user --name env_name

# 实测
(torch0508) C:\Users\A_A>python -m ipykernel install --user --name torch0508

Installed kernelspec torch0508 in C:\Users\A_A\AppData\Roaming\jupyter\kernels\torch0508

9 代码实现log

(py38torchtf) C:\Users\A_A>conda create -n py38torchtf python=3.8

(torch0508) C:\Users\A_A>conda activate py38torchtf
    
(py38torchtf) C:\Users\A_A>conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge

(py38torchtf) C:\Users\A_A>python
Python 3.8.16 (default, Mar  2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True

(py38torchtf) C:\Users\A_A>pip install tensorflow-gpu==2.6.0 -i https://pypi.douban.com/simple


>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
    from tensorflow.python.eager import context
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\python\eager\context.py", line 32, in <module>
    from tensorflow.core.framework import function_pb2
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\function_pb2.py", line 16, in <module>
    from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\attr_value_pb2.py", line 16, in <module>
    from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\tensor_pb2.py", line 16, in <module>
    from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\resource_handle_pb2.py", line 16, in <module>
    from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\tensor_shape_pb2.py", line 36, in <module>
    _descriptor.FieldDescriptor(
  File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\google\protobuf\descriptor.py", line 561, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
>>> exit()

(py38torchtf) C:\Users\A_A>pip install protobuf==3.20.1 -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple


(py38torchtf) C:\Users\A_A>python
Python 3.8.16 (default, Mar  2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.test.is_gpu_available()
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2023-05-09 21:02:58.664337: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-05-09 21:03:00.923971: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /device:GPU:0 with 2149 MB memory:  -> device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5
True
>>> tf.test.is_built_with_cuda()
True
>>> exit()

(py38torchtf) C:\Users\A_A>


(py38torchtf) C:\Users\A_A>pip install ipykernel -i https://pypi.douban.com/simple


(py38torchtf) C:\Users\A_A>python -m ipykernel install --user --name py38torchtf

Installed kernelspec py38torchtf in C:\Users\A_A\AppData\Roaming\jupyter\kernels\py38torchtf


(py38torchtf) C:\Users\A_A>


(py38torchtf) C:\Users\A_A>cd /d D:\Auser

(py38torchtf) D:\Auser>jupyter notebook

## 剩下的备份虚拟环境报错说http等原因,仍然没能解决,当前解决方案还是用到新的项目就create 一个新的env,然后再install  tensorflow和torch 比较靠谱
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: PyTorch版本CUDA版本之间的对应关系并不固定,需要查看PyTorch的官方文档。 根据PyTorch的官方文档,在2021年的最新版本PyTorch 1.7.0中,支持CUDA 11.0和11.1。因此,可以使用PyTorch 1.7.0与CUDA 11.1配合使用。 不过,建议您确认您的计算机环境是否符合PyTorch 1.7.0的系统要求,以确保安装和使用的顺利。 ### 回答2: 在CUDA 11.1的情况下,可以使用PyTorch 1.7.0或更高版本进行GPU加速的深度学习任务。PyTorch是一个基于Python的开源机器学习框架,它提供了丰富的工具和库,使得在GPU上进行高效的计算成为可能。 CUDA 11.1是NVIDIA的一个GPU加速计算平台,它提供了用于并行计算的许多功能和工具。PyTorch利用CUDA架构的强大性能,通过与CUDA 11.1的集成,能够在GPU上进行高效的深度学习计算。 PyTorch 1.7.0是支持CUDA 11.1的版本,它支持使用CUDA 11.1进行加速的功能。这个版本是经过pytorch官方团队和社区的努力开发和测试的。使用PyTorch 1.7.0可以利用CUDA 11.1提供的计算能力,使得深度学习任务在GPU上运行得更快。 总而言之,CUDA 11.1与PyTorch 1.7.0是相互兼容的。通过使用PyTorch 1.7.0,可以使用CUDA 11.1提供的强大的GPU加速功能来加速深度学习任务的计算。 ### 回答3: CUDA 11.1 对应PyTorch 版本是 1.7.0。具体来说,这个版本PyTorch是在2020年10月29日发布的,专门为CUDA 11.1进行了优化。此版本PyTorch支持CUDA 11.1的全部功能和特性,可以充分利用CUDA 11.1的性能提升。 PyTorch是一个开源的深度学习框架,提供了灵活的工具和库,用于构建和训练深度神经网络模型。它基于Python语言,利用CUDA加速计算,能够利用GPU的强大计算能力来加速训练过程。 CUDA是NVIDIA提供的一个并行计算平台和编程模型,它可以通过显卡的并行计算单元来加速计算。CUDA 11.1是CUDA平台的一个版本,提供了一些新的功能和性能优化,可以进一步提升GPU计算的速度和效率。 PyTorch1.7.0是针对CUDA 11.1进行了优化的版本,可以充分利用CUDA 11.1的性能提升。用户在使用PyTorch构建深度学习模型时,可以选择使用CUDA 11.1和PyTorch 1.7.0的组合,以充分发挥GPU的计算能力,加快训练速度和提高模型性能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值