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

P2P网站怎么建设苏州网站建设 网络推广公司

P2P网站怎么建设,苏州网站建设 网络推广公司,怎么做发卡网站,网页设计论文大纲部署Kimi-VL-A3B-Instruct视频推理 契机 ⚙ 最近国内AI公司月之暗面推出了Kimi-VL开源视觉模型。模型参数16.4B,但是推理时候激活参数2.8B。看了huggingface主页的Full comparison,在多项Benchmark的时候都展示出了不俗的实力。由于业务中使用了qwen-v…

部署Kimi-VL-A3B-Instruct视频推理

契机

⚙ 最近国内AI公司月之暗面推出了Kimi-VL开源视觉模型。模型参数16.4B,但是推理时候激活参数2.8B。看了huggingface主页的Full comparison,在多项Benchmark的时候都展示出了不俗的实力。由于业务中使用了qwen-vl-2.5-7B,所以测试下Kimi-VL-A3B-Instruct是否在更小的部署资源中拥有更好的表现。

moonshotai/Kimi-VL-A3B-Instruct · Hugging Face

安装

conda create --name Kimi-VL python=3.11.0
conda activate Kimi-VL
git clone https://github.com/MoonshotAI/Kimi-VL.git
pip install -r requirements.txt
#额外安装视频推理所需依赖
pip install opencv-python
#flash-attn的安装会访问github,如果网络没有魔法,建议尝试其他办法
pip install -U flash-attn --use-pep517 --no-build-isolation#模型下载
moonshotai/Kimi-VL-A3B-Instruct#运行期间用以下命令查看显卡资源,按照0.5s刷新一次
nvidia-smi -l 0.5

图片推理测试

代码

from tracemalloc import start
from PIL import Image
from transformers import AutoModelForCausalLM, AutoProcessor
import torch
import timemodel_path = "moonshotai/Kimi-VL-A3B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_path,torch_dtype=torch.bfloat16,device_map="auto",trust_remote_code=True,attn_implementation="flash_attention_2"
)
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)while True:time.sleep(1)start = time.time()image_path = "Kimi-VL/figures/demo1.png"image = Image.open(image_path)messages = [{"role": "user", "content": [{"type": "image", "image": image_path}, {"type": "text", "text": "20字描述图片"}]}]text = processor.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")inputs = processor(images=image, text=text, return_tensors="pt", padding=True, truncation=True).to(model.device)generated_ids = model.generate(**inputs, max_new_tokens=512)generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]response = processor.batch_decode(generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]print(response)print(time.time() - start)

输入输出

请添加图片描述

多次输出如下:
城市天际线,高楼林立,交通繁忙,夕阳余晖。
1.8491706848144531
城市天际线,高楼林立,交通繁忙,夕阳余晖。
1.2099909782409668
城市天际线,高楼林立,交通繁忙,夕阳余晖。
1.1886250972747803
城市天际线,高楼林立,交通繁忙,夕阳余晖。
1.1849017143249512
城市天际线,高楼林立,交通繁忙,夕阳余晖。
1.1930198669433594

资源占用

请添加图片描述

视频推理测试

代码

import time
import cv2
import argparse
import torch
import os 
from PIL import Image
from transformers import AutoModelForCausalLM, AutoProcessor# Function to extract frames from video, save them, and return paths
def extract_frames(video_path, save_dir, target_fps=1, max_frames=1):"""Extracts up to max_frames from a video file at target FPS, saves them, and returns their paths."""frame_paths = []# Create save directory if it doesn't existos.makedirs(save_dir, exist_ok=True)try:cap = cv2.VideoCapture(video_path)if not cap.isOpened():print(f"Error: Could not open video file: {video_path}")return frame_pathsvideo_fps = cap.get(cv2.CAP_PROP_FPS)if video_fps <= 0:print(f"Warning: Could not get video FPS for {video_path}. Assuming 30 FPS.")video_fps = 30frame_interval = max(1, int(round(video_fps / target_fps)))frame_count = 0saved_frame_count = 0while cap.isOpened() and saved_frame_count < max_frames:ret, frame = cap.read()if not ret:breakif frame_count % frame_interval == 0:# Convert BGR (OpenCV) to RGB (PIL)frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)img = Image.fromarray(frame_rgb)# Save frame to diskframe_filename = f"frame_{saved_frame_count:04d}.png"frame_filepath = os.path.join(save_dir, frame_filename)try:img.save(frame_filepath)frame_paths.append(frame_filepath)saved_frame_count += 1except Exception as save_e:print(f"Error saving frame {frame_filepath}: {save_e}")# Optionally continue to next frame or breakframe_count += 1cap.release()print(f"Extracted and saved {len(frame_paths)} frames to {save_dir} from {video_path} at ~{target_fps} FPS.")except Exception as e:print(f"An error occurred during frame extraction: {e}")if 'cap' in locals() and cap.isOpened():cap.release()return frame_paths# --- Argument Parsing ---
# parser = argparse.ArgumentParser(description="Describe video frame(s) using Kimi-VL model.")
# parser.add_argument("video_path", help="Path to the input video file.")
# parser.add_argument("--max_frames", type=int, default=1, help="Maximum number of frames to extract and process.")
# parser.add_argument("--save_dir", default="./test-frames", help="Directory to save extracted frames.")
# parser.add_argument("--prompt", default="Describe this video", help="Text prompt for the model.")
# parser.add_argument("--target_fps", type=float, default=1.0, help="Target frames per second for extraction.")
# args = parser.parse_args()# --- Frame Extraction & Saving ---
# extracted_frame_paths = extract_frames(args.video_path, args.save_dir, target_fps=args.target_fps, max_frames=args.max_frames)
extracted_frame_paths = extract_frames("test.mp4", "./test_kimi_frames", target_fps=4, max_frames=40)if not extracted_frame_paths:print("No frames were extracted or saved. Exiting.")exit()# --- Model Loading ---
model_path = "moonshotai/Kimi-VL-A3B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_path,torch_dtype=torch.bfloat16,device_map="auto",trust_remote_code=True,attn_implementation="flash_attention_2"
)
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)# --- Prepare Input for Model --- 
# Load images from the saved paths
loaded_images = []
for frame_path in extracted_frame_paths:if os.path.exists(frame_path):loaded_images.append(Image.open(frame_path))else:print(f"Warning: Saved frame path not found: {frame_path}")print(f'Loaded {len(loaded_images)} images for processing.')# Construct the messages list
content = []
for frame_path in extracted_frame_paths:content.append({"type": "image", "image": frame_path})
# content.append({"type": "text", "text": args.prompt})
content.append({"type": "text", "text": '描述视频'})messages = [{"role": "user", "content": content}
]print('Messages:')
print(messages)# Process text and image paths
text = processor.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")# --- Model Generation ---
while True:time.sleep(1)try:start =time.time()# Use the loaded images in the processor callinputs = processor(images=loaded_images[0] if len(loaded_images) == 1 else loaded_images, text=text, return_tensors="pt", padding=True, truncation=True).to(model.device)generated_ids = model.generate(**inputs, max_new_tokens=512)generated_ids_trimmed = [out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]response = processor.batch_decode(generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]print("--- Model Response ---")print(response)print(time.time()-start)except Exception as e:print(f"An error occurred during model generation: {e}")

输入输出

7s视频,每秒4帧
Extracted and saved 26 frames to ./test_kimi_frames from test.mp4 at ~4 FPS--- Model Response ---
视频开始时展示了一片宁静的海洋和蓝天,海面上波光粼粼,天空中散布着几朵白云。随后,一个世界地图的图像逐渐浮现,地图上标注了不同国家的边界。地图上方有一行日文文字,解释了蓝色代表墨卡托投影法,红色代表实际大小。地图下方有一个按钮,显示为“Show Mercator Size”,暗示可以通过点击按钮来切换地图的显示方式。整个画面给人一种宁静而开阔的感觉,仿佛置身于大海之中,同时通过地图的对比,引发对地理和地图投影的思考。
13.988295316696167
--- Model Response ---
视频开始时展示了一片宁静的海洋和蓝天,海面上波光粼粼,天空中散布着几朵白云。随后,一个世界地图的图像逐渐浮现,地图上标注了不同国家的边界。地图上方有一行日文文字,解释了蓝色代表墨卡托投影法,红色代表实际大小。地图下方有一个按钮,显示为“Show Mercator Size”,暗示可以通过点击按钮来切换地图的显示方式。整个画面给人一种宁静而开阔的感觉,仿佛置身于大海之中,同时通过地图的对比,引发对地理和地图投影的思考。
13.980722665786743
--- Model Response ---
视频开始时展示了一片宁静的海洋和蓝天,海面上波光粼粼,天空中散布着几朵白云。随后,一个世界地图的图像逐渐浮现,地图上标注了不同国家的边界。地图上方有一行日文文字,解释了蓝色代表墨卡托投影法,红色代表实际大小。地图下方有一个按钮,显示为“Show Mercator Size”,暗示可以通过点击按钮来切换地图的显示方式。整个画面给人一种宁静而开阔的感觉,仿佛置身于大海之中,同时通过地图的对比,引发对地理和地图投影的思考。
13.964439153671265
--- Model Response ---
视频开始时展示了一片宁静的海洋和蓝天,海面上波光粼粼,天空中散布着几朵白云。随后,一个世界地图的图像逐渐浮现,地图上标注了不同国家的边界。地图上方有一行日文文字,解释了蓝色代表墨卡托投影法,红色代表实际大小。地图下方有一个按钮,显示为“Show Mercator Size”,暗示可以通过点击按钮来切换地图的显示方式。整个画面给人一种宁静而开阔的感觉,仿佛置身于大海之中,同时通过地图的对比,引发对地理和地图投影的思考。
13.99526834487915

资源占用

请添加图片描述

总结

  • 这个显存占用也不低啊
  • 纯记录

写到最后

请添加图片描述


文章转载自:

http://wXO6SlT0.tqxtx.cn
http://U3k3zDat.tqxtx.cn
http://40tyRvdR.tqxtx.cn
http://lvqxgVKq.tqxtx.cn
http://O7XI4PVs.tqxtx.cn
http://uE1hK4Yo.tqxtx.cn
http://yO2nNmmB.tqxtx.cn
http://50XZsJxQ.tqxtx.cn
http://0CWLD4iZ.tqxtx.cn
http://6rOFPvon.tqxtx.cn
http://phhYRudR.tqxtx.cn
http://RRBqg4a7.tqxtx.cn
http://9q1IIS0U.tqxtx.cn
http://CJEEfwKJ.tqxtx.cn
http://JOyle0qN.tqxtx.cn
http://Su2DKVHr.tqxtx.cn
http://oUNDzk5t.tqxtx.cn
http://68PFjWl9.tqxtx.cn
http://ve2hqmuY.tqxtx.cn
http://d5HdmRpm.tqxtx.cn
http://0rls9Vz7.tqxtx.cn
http://dGiuEBfR.tqxtx.cn
http://nuwhtHhQ.tqxtx.cn
http://hPltDCVm.tqxtx.cn
http://LqhUcctW.tqxtx.cn
http://lFL0YSBk.tqxtx.cn
http://X8i3GgSE.tqxtx.cn
http://SG3nQrd3.tqxtx.cn
http://uKuLMzgE.tqxtx.cn
http://rOYQJ3xp.tqxtx.cn
http://www.dtcms.com/wzjs/765707.html

相关文章:

  • 电销如何介绍网站建设鞍山制作网站
  • 想做一个网站学编程课对孩子有什么好处
  • wordpress 可视化建站网页中网站设计规划流程
  • 山东网站设计公司网站建设 中企动力 石家庄
  • 你注册过的那些网站龙岗专业做网站
  • 最新站长seo网站外链发布平台南宁建站公司
  • 一个阿里云服务器可以放几个网站网站建设ningqueseo
  • 青海省住房建设厅网站辽源网站建设
  • 东莞销售网站建设工作室主题网站模板
  • 网站制作的困难与解决方案wordpress更改站点名称
  • 两个网站做反向代理自己免费做网站的流程
  • 仿制网站的后台wordpress后台目录无法访问
  • 网站的访问速度和什么有关系南通做网站优化
  • 快速学习网站建设廊坊建设网站公司
  • 响应式网站建设福州微信小程序数据库搭建
  • 网站开发人员篡改客户数据网站开发规格
  • 网站修改关键词黑色企业网站
  • 精品资料网站中国设计联盟网服务内容
  • 网站前端设计招聘怎么做好网站搜索引擎优化
  • 安徽省工程建设工程信息网站域名购买成功后网站怎么建设
  • 银川网站设计公司hdwiki做网站
  • 用腾讯云做淘宝客网站视频流程网络营销是什么时候兴起的
  • wordpress 站中站企业网站实验报告
  • 北京网站建设外包公司排名创新的网站建站
  • 中国神鹰网站建设郑州网站建设zzmshl
  • 共享vps可以做网站吗国航网站建设
  • 网上书城网站建设目的规模以上工业企业利润总额
  • 公司网站开发招标书境外网站
  • 购物网站详细设计株洲百度推广公司
  • 找聊城做网站网页设计实训报告总结1000字免费