CoolFace
Modelpublic

nikravan/glm-4vq

sourceHugging Faceupdated 2y agoView on Hugging Face
38likes69downloads
Model Card

MultiModal MultiLingual (3ML)

This model is 4bit quantized of glm-4v-9b Model (Less than 9G).

It excels in document, image, chart questioning answering and delivers superior performance over GPT-4-turbo-2024-04-09, Gemini 1.0 Pro, Qwen-VL-Max, and Claude 3 Opus.

Some part of the original Model changed and It can excute on free version of google colab.

Try it: ![Open In Colab](https://colab.research.google.com/drive/1aZGX9f5Yw1WbiOrS3TpvPkUJUPyYQU?usp=sharing)

[![Github Source]](https://github.com/nikravan1/3ML)

Note: For optimal performance with document and image understanding, please use English or Chinese. The model can still handle chat in any supported language.

About GLM-4V-9B

GLM-4V-9B is a multimodal language model with visual understanding capabilities. The evaluation results of its related classic tasks are as follows:

**MMBench-EN-Test****MMBench-CN-Test****SEEDBench_IMG****MMStar****MMMU****MME****HallusionBench****AI2D****OCRBench**
英文综合中文综合综合能力综合能力学科综合感知推理幻觉性图表理解文字识别
GPT-4o, 2024051383.482.177.163.969.22310.35584.6736
GPT-4v, 202404098180.2735661.72070.243.978.6656
GPT-4v, 202311067774.472.349.753.81771.546.575.9516
InternVL-Chat-V1.582.380.775.257.146.82189.647.480.6720
LlaVA-Next-Yi-34B81.17975.751.648.82050.234.878.9574
Step-1V80.779.970.35049.92206.448.479.2625
MiniCPM-Llama3-V2.577.673.872.351.845.82024.642.478.4725
Qwen-VL-Max77.675.772.749.5522281.741.275.7684
GeminiProVision73.674.370.738.6492148.945.772.9680
Claude-3V Opus63.359.26445.754.91586.837.870.6694
GLM-4v-9B81.179.476.858.747.22163.846.681.1786

This repository is the model repository of 4bit quantized of GLM-4V-9B model, supporting `8K` context length.

Quick Start

Use colab model or this python script.

python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from PIL import Image

device = "cuda"

modelPath="nikravan/glm-4vq"
tokenizer = AutoTokenizer.from_pretrained(modelPath, trust_remote_code=True)

model = AutoModelForCausalLM.from_pretrained(
    modelPath,
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
    trust_remote_code=True,
    device_map="auto"
)



query ='explain all the details in this picture'
image = Image.open("a3.png").convert('RGB')
#image=""
inputs = tokenizer.apply_chat_template([{"role": "user", "image": image, "content": query}],
                                       add_generation_prompt=True, tokenize=True, return_tensors="pt",
                                       return_dict=True)  # chat with image mode

inputs = inputs.to(device)

gen_kwargs = {"max_length": 2500, "do_sample": True, "top_k": 1}
with torch.no_grad():
    outputs = model.generate(**inputs, **gen_kwargs)
    outputs = outputs[:, inputs['input_ids'].shape[1]:]
    print(tokenizer.decode(outputs[0]))