模型简介
模型特点
模型能力
使用案例
🚀 Holo1-7B GGUF模型
Holo1-7B GGUF模型是Surfer-H系统的一部分,可用于视觉文档检索等多模态任务。该模型在处理网页交互、网络监控等方面表现出色,能以较低成本实现较高的准确性。
🚀 快速开始
Holo1模型基于Qwen2.5-VL架构,借助transformers
库实现。以下是一个简单的使用示例,展示了如何加载模型和处理器:
import json
import os
from typing import Any, Literal
from transformers import AutoModelForImageTextToText, AutoProcessor
# 默认:将模型加载到可用设备上
# 建议启用flash_attention_2以实现更好的加速和内存节省。
model = AutoModelForImageTextToText.from_pretrained(
"Hcompany/Holo1-7B",
torch_dtype="auto",
# torch_dtype=torch.bfloat16,
# attn_implementation="flash_attention_2",
device_map="auto",
)
# 默认处理器
processor = AutoProcessor.from_pretrained("Hcompany/Holo1-7B")
# 模型中每张图像的视觉标记数量的默认范围是4 - 1280。
# 可以根据需要设置min_pixels和max_pixels,例如标记范围为256 - 1280,以平衡性能和成本。
# processor = AutoProcessor.from_pretrained(model_dir, min_pixels=min_pixels, max_pixels=max_pixels)
# 运行推理的辅助函数
def run_inference(messages: list[dict[str, Any]]) -> str:
# 推理准备
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(
text=[text],
images=image,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
return processor.batch_decode(generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)
✨ 主要特性
模型背景
该模型是Surfer-H系统的一部分,相关研究成果发表在论文Surfer-H Meets Holo1: Cost-Efficient Web Agent Powered by Open Weights中,更多详情可查看项目页面https://www.surferh.com。
超低比特量化技术
引入了针对超低比特模型(1 - 2比特)的精度自适应量化方法,在Llama - 3 - 8B上经基准测试证明有显著改进。该方法采用特定层策略,在保证极端内存效率的同时保留准确性。
多场景适用性
适用于多种场景,如将模型适配到GPU显存、内存受限的部署、可容忍1 - 2比特误差的CPU和边缘设备,以及超低比特量化研究。
模型格式多样
提供多种模型格式,可根据硬件能力和内存限制选择合适的格式,如BF16、F16、量化模型(Q4_K、Q6_K、Q8等)以及超低比特量化模型(IQ3_XS、IQ3_S、IQ3_M、Q4_K、Q4_0)。
网络监控功能
可用于AI网络监控,包括对实时网络服务进行函数调用、自动化Nmap扫描、量子就绪检查和网络监控任务等。
📦 安装指南
文档未提及具体安装步骤,可参考transformers
库的官方文档进行安装。
💻 使用示例
基础用法
import json
import os
from typing import Any, Literal
from transformers import AutoModelForImageTextToText, AutoProcessor
# default: Load the model on the available device(s)
# We recommend enabling flash_attention_2 for better acceleration and memory saving.
model = AutoModelForImageTextToText.from_pretrained(
"Hcompany/Holo1-7B",
torch_dtype="auto",
# torch_dtype=torch.bfloat16,
# attn_implementation="flash_attention_2",
device_map="auto",
)
# default processor
processor = AutoProcessor.from_pretrained("Hcompany/Holo1-7B")
# The default range for the number of visual tokens per image in the model is 4-1280.
# You can set min_pixels and max_pixels according to your needs, such as a token range of 256-1280, to balance performance and cost.
# processor = AutoProcessor.from_pretrained(model_dir, min_pixels=min_pixels, max_pixels=max_pixels)
# Helper function to run inference
def run_inference(messages: list[dict[str, Any]]) -> str:
# Preparation for inference
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(
text=[text],
images=image,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
return processor.batch_decode(generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)
高级用法
# 准备图像和指令
import requests
from PIL import Image
from transformers.models.qwen2_vl.image_processing_qwen2_vl import smart_resize
# Prepare image and instruction
image_url = "https://huggingface.co/Hcompany/Holo1-7B/resolve/main/calendar_example.jpg"
image = Image.open(requests.get(image_url, stream=True).raw)
# Resize the image so that predicted absolute coordinates match the size of the image.
image_processor = processor.image_processor
resized_height, resized_width = smart_resize(
image.height,
image.width,
factor=image_processor.patch_size * image_processor.merge_size,
min_pixels=image_processor.min_pixels,
max_pixels=image_processor.max_pixels,
)
image = image.resize(size=(resized_width, resized_height), resample=None) # type: ignore
instruction = "Select July 14th as the check-out date"
# 进行定位
def get_localization_promt():
# 此处可根据具体需求完善定位提示逻辑
pass
📚 详细文档
模型生成细节
该模型使用llama.cpp在提交版本71bdbdb5
时生成。
超低比特量化方法
基准测试背景
所有测试均在Llama - 3 - 8B - Instruct上进行,使用标准困惑度评估管道、2048令牌上下文窗口,且所有量化使用相同的提示集。
方法
- 动态精度分配:前/后25%的层使用IQ4_XS(选定层),中间50%使用IQ2_XXS/IQ3_S(提高效率)。
- 关键组件保护:嵌入/输出层使用Q5_K,与标准1 - 2比特量化相比,将误差传播降低38%。
量化性能比较(Llama - 3 - 8B)
量化方式 | 标准困惑度 | DynamicGate困惑度 | 困惑度变化 | 标准大小 | DG大小 | 大小变化 | 标准速度 | DG速度 |
---|---|---|---|---|---|---|---|---|
IQ2_XXS | 11.30 | 9.84 | -12.9% | 2.5G | 2.6G | +0.1G | 234s | 246s |
IQ2_XS | 11.72 | 11.63 | -0.8% | 2.7G | 2.8G | +0.1G | 242s | 246s |
IQ2_S | 14.31 | 9.02 | -36.9% | 2.7G | 2.9G | +0.2G | 238s | 244s |
IQ1_M | 27.46 | 15.41 | -43.9% | 2.2G | 2.5G | +0.3G | 206s | 212s |
IQ1_S | 53.07 | 32.00 | -39.7% | 2.1G | 2.4G | +0.3G | 184s | 209s |
使用场景
适用于将模型适配到GPU显存、内存受限的部署、可容忍1 - 2比特误差的CPU和边缘设备,以及超低比特量化研究。
选择合适的模型格式
模型格式 | 精度 | 内存使用 | 设备要求 | 最佳使用场景 |
---|---|---|---|---|
BF16 | 最高 | 高 | 支持BF16加速的GPU/CPU | 减少内存的高速推理 |
F16 | 高 | 高 | 支持FP16的设备 | BF16不可用时的GPU推理 |
Q4_K | 中低 | 低 | CPU或低显存设备 | 内存受限的环境 |
Q6_K | 中 | 中等 | 内存较多的CPU | 量化模型中较好的准确性 |
Q8_0 | 高 | 中等 | 有足够显存的CPU或GPU | 量化模型中最佳准确性 |
IQ3_XS | 非常低 | 非常低 | 超低内存设备 | 极端内存效率和低准确性 |
Q4_0 | 低 | 低 | ARM或低内存设备 | llama.cpp可针对ARM设备优化 |
包含的文件及详情
文件名 | 说明 |
---|---|
Holo1-7B-bf16.gguf |
模型权重保存为BF16格式,适用于需要重新量化模型或设备支持BF16加速的情况。 |
Holo1-7B-f16.gguf |
模型权重保存为F16格式,适用于设备支持FP16,尤其是BF16不可用的情况。 |
Holo1-7B-bf16-q8_0.gguf |
输出和嵌入层保持为BF16,其他层量化为Q8_0,适用于设备支持BF16且需要量化版本的情况。 |
Holo1-7B-f16-q8_0.gguf |
输出和嵌入层保持为F16,其他层量化为Q8_0。 |
Holo1-7B-q4_k.gguf |
输出和嵌入层量化为Q8_0,其他层量化为Q4_K,适用于内存有限的CPU推理。 |
Holo1-7B-q4_k_s.gguf |
最小的Q4_K变体,以牺牲准确性为代价减少内存使用,适用于极低内存设置。 |
Holo1-7B-q6_k.gguf |
输出和嵌入层量化为Q8_0,其他层量化为Q6_K。 |
Holo1-7B-q8_0.gguf |
完全Q8量化模型,准确性更高,但需要更多内存。 |
Holo1-7B-iq3_xs.gguf |
IQ3_XS量化,针对极端内存效率进行优化,适用于超低内存设备。 |
Holo1-7B-iq3_m.gguf |
IQ3_M量化,提供中等块大小以提高准确性,适用于低内存设备。 |
Holo1-7B-q4_0.gguf |
纯Q4_0量化,针对ARM设备进行优化,适用于低内存环境,建议使用IQ4_NL以获得更好的准确性。 |
模型测试
测试内容
推动小型开源模型在AI网络监控中的极限,包括对实时网络服务进行函数调用、测试模型在处理自动化Nmap扫描、量子就绪检查和网络监控任务时的最小规模。
测试模型
- TestLLM:当前实验模型(llama.cpp在2个CPU线程上),零配置设置,加载时间约30秒(推理慢但无API成本)。
- TurboLLM:使用gpt - 4o - mini进行自定义命令处理器创建、实时网络诊断和监控、安全审计、渗透测试等。
- HugLLM:基于最新的开源模型,在Hugging Face推理API上运行。
示例命令
"Give me info on my websites SSL certificate"
"Check if my server is using quantum safe encyption for communication"
"Run a comprehensive security audit on my server"
"Create a cmd processor to .. (what ever you want)"
🔧 技术细节
模型架构
Holo1模型基于Qwen2.5 - VL架构,该架构得到transformers
库的支持。
推理过程
通过AutoModelForImageTextToText
加载模型,使用AutoProcessor
处理输入,包括文本和图像。推理时,将输入转换为张量并发送到设备上,使用generate
方法生成输出。
📄 许可证
本项目采用Apache 2.0许可证。
重要提示
⚠️ 重要提示
Holo1使用绝对坐标(像素数),而HuggingFace处理器会对图像进行调整大小。为使坐标匹配,需要对图像进行智能调整大小。
使用建议
💡 使用建议
建议启用
flash_attention_2
以实现更好的加速和内存节省。可根据需要设置min_pixels
和max_pixels
来平衡性能和成本。








