当前位置: 首页 > news >正文

显存占用 显存测试

目录

显存测试

显存占用示例

一个模型多卡占用


显存测试

import torch# 计算张量的大小(例如:每个 float 占用 4 字节)
# 40GB = 40 * 1024 * 1024 * 1024 字节
# 每个 float 4 字节,因此需要的 float 数量为 (40 * 1024 * 1024 * 1024) / 4
num_elements = (40 * 1024 * 1024 * 1024) // 4# 创建一个在 GPU 上的张量
tensor = torch.empty(num_elements, dtype=torch.float32, device='cuda')print(tensor)

显存占用示例

42G和62G显存


import timeimport torch# 设置张量的大小
num_elements = (10 * 1024 * 1024 * 1024) // 4  # 42GB 大小
# num_elements = (15 * 1024 * 1024 * 1024) // 4  # 62GB 大小# 创建两个随机数张量,存放在 GPU 上
tensor_a = torch.rand(num_elements, dtype=torch.float32, device='cuda:3')
tensor_b = torch.rand(num_elements, dtype=torch.float32, device='cuda:3')# 创建一个用于存储结果的张量
# result_tensor = torch.empty(num_elements, dtype=torch.float32, device='cuda')
index=0
while True:result_tensor=tensor_a + tensor_b# tensor_a + tensor_btime.sleep(0.01)index+=1print(index)

一个模型多卡占用

import timeimport torch
import torch.nn as nn# 设置张量的大小
num_elements = (6 * 1024 * 1024 * 1024) // 4  # 40GB 大小# 确保有两个可用的 GPU
if torch.cuda.device_count() < 2:raise RuntimeError("至少需要两块 GPU")# 创建两个随机数张量,存放在 GPU 上
tensor_a = torch.rand(num_elements , dtype=torch.float32, device='cuda:0')
tensor_b = torch.rand(num_elements , dtype=torch.float32, device='cuda:0')# 创建一个用于存储结果的张量
result_tensor = torch.empty(num_elements , dtype=torch.float32, device='cuda:1')class AddModel(nn.Module):def forward(self, tensor_a, tensor_b):return tensor_a + tensor_b# 实例化模型并使用 DataParallel
model = AddModel().cuda()
model = nn.DataParallel(model)index=0
# 不断相加的循环
while True:# 使用 DataParallel 进行加法result_tensor = model(tensor_a, tensor_b)# 将结果存储在第一个 GPU 上result_tensor = result_tensor.to('cuda:1')time.sleep(0.01)index += 1print(index)

http://www.lryc.cn/news/476784.html

相关文章:

  • 快速入门CSS
  • AcWing 1073 树的中心 树形dp (详解)
  • modelscope下载Qwen2.5 72B 模型方法
  • 重学SpringBoot3-整合 Elasticsearch 8.x (二)使用Repository
  • 为什么说模拟电路的难点就在开通过程和关断过程?难在什么地方?
  • CubeIDE BUG-project‘hello‘has no explict encoding set hello
  • 在线PDF转图片网站
  • ps和top的区别
  • 自动驾驶上市潮中,会诞生下一个“英伟达”吗?
  • CSS 计数器:深入解析与高级应用
  • 【真题笔记】15年系统架构设计师要点总结
  • 斗破C++编程入门系列之三十九:多态性:纯虚函数和抽象类(四星斗师)
  • 目前美国的互联网环境
  • 从最小作用量原理推导牛顿三大定律
  • 【系统集成项目管理工程师教程】第4章 信息系统架构
  • docker下迁移elasticsearch的问题与解决方案
  • 占地1.1万平,2亿投资的智能仓储系统:高架库、AGV、码垛机器人……
  • 一个小程序如何对接多个收款账户?
  • L2G4000 InternVL 部署微调实践闯关任务
  • asynDriver-6-端口驱动
  • [免费]基于Python的Django+Vue3在线考试系统【论文+源码+SQL脚本】
  • Python使用爬虫
  • CommunityToolkit.Mvvm如何使用
  • Python小游戏20——超级玛丽
  • 配置文件格式(xml、properties、yml/yaml)
  • CentOS 7 软件/程序安装示例
  • Python绘制正弦函数图形
  • 【LVGL-列表部件 lv_list_create】
  • 【P2-6】ESP8266 WIFI模块在STA模式下实现UDP与电脑/手机网络助手通信——UDP数据透传
  • 从零学习大模型(十)-----剪枝基本概念