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

自己编写网站vs做网站用3层架构

自己编写网站,vs做网站用3层架构,学校ui设计培训,坡头网站开发公司1、模型下载魔搭社区 2、运行环境: 1、硬件 RTX 3090*1 云主机[普通性能] 8核15G 200G 免费 32 Mbps付费68Mbps ubuntu22.04 cuda12.4 2、软件: flash_attn(好像不用装 忘记了) numpy Pillow10.3.0 Requests2.31.0 transfo…

1、模型下载魔搭社区

2、运行环境:
 

1、硬件

RTX 3090*1  云主机[普通性能]

8核15G 200G

免费 32 Mbps+付费68Mbps  

ubuntu22.04

cuda12.4 

2、软件:

flash_attn(好像不用装 忘记了)
numpy
Pillow==10.3.0
Requests==2.31.0
transformers==4.43.0
accelerate==0.30.0
torch==2.5.0(自己去下载另一个库)

modelscope==1.25.0
 


(base) root@ubuntu22:/opt# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Tue_Feb_27_16:19:38_PST_2024
Cuda compilation tools, release 12.4, V12.4.99
Build cuda_12.4.r12.4/compiler.33961263_0

3、运行代码如下

import math
import numpy as np
import torch
import torchvision.transforms as T
from decord import VideoReader, cpu
from PIL import Image
from torchvision.transforms.functional import InterpolationMode
from modelscope import AutoModel, AutoTokenizer
from transformers import AutoConfig
import os
import timeIMAGENET_MEAN = (0.485, 0.456, 0.406)
IMAGENET_STD = (0.229, 0.224, 0.225)def build_transform(input_size):MEAN, STD = IMAGENET_MEAN, IMAGENET_STDtransform = T.Compose([T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),T.ToTensor(),T.Normalize(mean=MEAN, std=STD)])return transformdef find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):best_ratio_diff = float('inf')best_ratio = (1, 1)area = width * heightfor ratio in target_ratios:target_aspect_ratio = ratio[0] / ratio[1]ratio_diff = abs(aspect_ratio - target_aspect_ratio)if ratio_diff < best_ratio_diff:best_ratio_diff = ratio_diffbest_ratio = ratioelif ratio_diff == best_ratio_diff:if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:best_ratio = ratioreturn best_ratiodef dynamic_preprocess(image, min_num=1, max_num=12, image_size=448, use_thumbnail=False):orig_width, orig_height = image.sizeaspect_ratio = orig_width / orig_height# calculate the existing image aspect ratiotarget_ratios = set((i, j) for n in range(min_num, max_num + 1) for i in range(1, n + 1) for j in range(1, n + 1) ifi * j <= max_num and i * j >= min_num)target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])# find the closest aspect ratio to the targettarget_aspect_ratio = find_closest_aspect_ratio(aspect_ratio, target_ratios, orig_width, orig_height, image_size)# calculate the target width and heighttarget_width = image_size * target_aspect_ratio[0]target_height = image_size * target_aspect_ratio[1]blocks = target_aspect_ratio[0] * target_aspect_ratio[1]# resize the imageresized_img = image.resize((target_width, target_height))processed_images = []for i in range(blocks):box = ((i % (target_width // image_size)) * image_size,(i // (target_width // image_size)) * image_size,((i % (target_width // image_size)) + 1) * image_size,((i // (target_width // image_size)) + 1) * image_size)# split the imagesplit_img = resized_img.crop(box)processed_images.append(split_img)assert len(processed_images) == blocksif use_thumbnail and len(processed_images) != 1:thumbnail_img = image.resize((image_size, image_size))processed_images.append(thumbnail_img)return processed_imagesdef load_image(image_file, input_size=448, max_num=12):image = Image.open(image_file).convert('RGB')transform = build_transform(input_size=input_size)images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)pixel_values = [transform(image) for image in images]pixel_values = torch.stack(pixel_values)return pixel_valuesdef split_model(model_name):device_map = {}world_size = torch.cuda.device_count()config = AutoConfig.from_pretrained('OpenGVLab/InternVL3-8B', trust_remote_code=True)num_layers = config.llm_config.num_hidden_layers# Since the first GPU will be used for ViT, treat it as half a GPU.num_layers_per_gpu = math.ceil(num_layers / (world_size - 0.5))num_layers_per_gpu = [num_layers_per_gpu] * world_sizenum_layers_per_gpu[0] = math.ceil(num_layers_per_gpu[0] * 0.5)layer_cnt = 0for i, num_layer in enumerate(num_layers_per_gpu):for j in range(num_layer):device_map[f'language_model.model.layers.{layer_cnt}'] = ilayer_cnt += 1device_map['vision_model'] = 0device_map['mlp1'] = 0device_map['language_model.model.tok_embeddings'] = 0device_map['language_model.model.embed_tokens'] = 0device_map['language_model.output'] = 0device_map['language_model.model.norm'] = 0device_map['language_model.model.rotary_emb'] = 0device_map['language_model.lm_head'] = 0device_map[f'language_model.model.layers.{num_layers - 1}'] = 0return device_map# If you set `load_in_8bit=True`, you will need two 80GB GPUs.
# If you set `load_in_8bit=False`, you will need at least three 80GB GPUs.
path = 'OpenGVLab/InternVL3-8B'
device_map = split_model('InternVL3-8B')
model = AutoModel.from_pretrained(path,torch_dtype=torch.bfloat16,load_in_8bit=False,low_cpu_mem_usage=True,use_flash_attn=True,trust_remote_code=True,device_map=device_map).eval()
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)while True:image_path = input("请输入图片路径(输入 'q' 退出):")if image_path.lower() == 'q':breakif not os.path.exists(image_path):print("图片不存在,跳过本次问答。")continuequestion = input("请输入问题:")start_time = time.time()# set the max number of tiles in `max_num`pixel_values = load_image(image_path, max_num=12).to(torch.bfloat16).cuda()generation_config = dict(max_new_tokens=1024, do_sample=True)# single-image single-round conversation (单图单轮对话)question = f'<image>\n{question}'response = model.chat(tokenizer, pixel_values, question, generation_config)end_time = time.time()execution_time = end_time - start_timeprint(f'User: {question}\nAssistant: {response}')print(f'本次代码执行时间: {execution_time:.2f} 秒')# 释放单次资源缓存del pixel_valuestorch.cuda.empty_cache()    

4、测试效果:

问题和耗时如图

5、资源占用

不释放资源会一直涨显存。总体还算满意,我试了好多个图理解大模型,就属它牛一点

附图一张

补充,测试InternVL3-2B的结果

http://www.dtcms.com/wzjs/553188.html

相关文章:

  • 提供常州微信网站建设微信营销系统
  • 新站如何快速收录包装设计网页
  • 建设网站宣传外贸一般用什么平台
  • 长沙企业建站在线咨询空间登录
  • 一个虚拟主机绑定2个网站长春网站建设解决方案
  • 网页设计大赛网站开发网站空间管理权限
  • vue做网站前台网站建设贰金手指科捷9
  • 网站留白佛山营销网站开发
  • 中山网站建设招聘网络规划设计师岗位
  • 济南网络公司建站海南网络电视台
  • 网站推广的方法枫子公众号开发者id在哪里查看
  • 电脑本地网站建设安阳县事业单位招聘2021
  • 网站编程赚钱网站维护需要什么技能
  • 黑龙江网站开发长沙旅游攻略美食
  • 东莞做网站公司首选北京房产网58同城网
  • 个人网站需要备案吗电商指的是什么行业
  • 网站百度没收录自治区住房和城乡建设部网站
  • 百度主机做视频网站怎么样广元网站开发
  • 余江区建设局网站老薛主机wordpress模板
  • 网站建设平台选用网页传奇app
  • 自己搞网站建设北京市中关村有哪家可以做网站维护
  • 模版网站建设步骤详解苏州的互联网企业
  • 全栈网站开发者ui一般用什么软件做
  • 成都网站建设开发百度竞价排名是哪种方式
  • 网站开发技术服务费合同深圳的网站建设公司的外文名是
  • 网站做淘客免费做企业推广的网站
  • 装饰工程施工郑州网站建设方案优化
  • php能区别电脑网站和手机网站吗怎么嵌入到phpcms北京网站建设企业网站制作
  • 建设网站一定要会代码吗网站怎么上传代码吗
  • 租车行网站模版电商公司怎么注册营业执照