python310 安装 tensorflow-gpu2.10

python310 安装 tensorflow-gpu2.10

工具 miniconda

环境准备

  1. 升级依赖库

    bash 复制代码
    conda update --all
  2. 创建目录

    bash 复制代码
    mkdir gpu-tf
  3. 进入目录

    bash 复制代码
    cd gpu-tf
  4. 创建虚拟环境

    bash 复制代码
    conda create -p tf210-310 python==3.10.16
  5. 激活虚拟环境

    bash 复制代码
    conda activate D:\gpu-tf\tf210-310
  6. 重新安装pip

    bash 复制代码
    python -m pip uninstall pip
    python -m ensurepip --upgrade
  7. 升级 setuptools wheel

    bash 复制代码
    python -m pip install --upgrade pip setuptools wheel

安装cudacudnn

bash 复制代码
conda install cudatoolkit==11.3.1 cudnn==8.2.1

安装 numpy

解决版本兼容

bash 复制代码
pip install numpy==1.26.4

安装 tensorflow-gpu

bash 复制代码
pip install tensorflow-gpu==2.10.1

测试

  1. 控制台输入 python 进入 python 环境后输入以下内容:

    python 复制代码
    import tensorflow as tf
    
    # 打印TensorFlow版本信息
    print("TensorFlow version:", tf.__version__)
    
    # 检查GPU是否可用
    print("GPU is available:", end='\t' )
    print(tf.config.list_physical_devices('GPU'))
  2. 编写 python 文件,代码如下:

    python 复制代码
    import tensorflow as tf
    
    # 打印TensorFlow版本信息
    print("TensorFlow version:", tf.__version__)
    
    # 检查GPU是否可用
    if tf.config.list_physical_devices('GPU'):
        print("GPU is available")
    else:
        print("GPU is not available")
    
    # 使用tf.function装饰器自动将操作分配到GPU(如果可用)
    @tf.function
    def test_gpu():
        a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
        b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
        c = tf.matmul(a, b)
        return c
    
    # 调用函数并打印结果
    result = test_gpu()
    print(result)
  3. 运行刚刚编写的 python 文件,输入内容如下:

相关推荐
Tadas-Gao2 分钟前
Mem0分层记忆系统:大语言模型长期记忆的架构革命与实现范式
人工智能·语言模型·自然语言处理·架构·大模型·llm·transformer
极客小俊8 分钟前
Windows 卸载 OpenClaw
人工智能
吴佳浩 Alben10 分钟前
GPU 生产环境实践:硬件拓扑、显存管理与完整运维体系
运维·人工智能·pytorch·语言模型·transformer·vllm
多年小白11 分钟前
OpenClaw 本周技术更新速递
人工智能·ai·ai编程·openclaw
Oueii24 分钟前
Django全栈开发入门:构建一个博客系统
jvm·数据库·python
深瞳智检26 分钟前
lesson-02 NLP 基础-文本表示与词向量
人工智能·自然语言处理·llm·大语言模型
2401_831824961 小时前
使用Fabric自动化你的部署流程
jvm·数据库·python
njidf1 小时前
Python日志记录(Logging)最佳实践
jvm·数据库·python
twc8291 小时前
大模型生成 QA Pairs 提升 RAG 应用测试效率的实践
服务器·数据库·人工智能·windows·rag·大模型测试
@我漫长的孤独流浪1 小时前
Python编程核心知识点速览
开发语言·数据库·python