Instructions to use zai-org/cogvlm2-llama3-chat-19B-tgi with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zai-org/cogvlm2-llama3-chat-19B-tgi with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="zai-org/cogvlm2-llama3-chat-19B-tgi", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("zai-org/cogvlm2-llama3-chat-19B-tgi", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use zai-org/cogvlm2-llama3-chat-19B-tgi with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "zai-org/cogvlm2-llama3-chat-19B-tgi" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/cogvlm2-llama3-chat-19B-tgi", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/zai-org/cogvlm2-llama3-chat-19B-tgi
- SGLang
How to use zai-org/cogvlm2-llama3-chat-19B-tgi with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "zai-org/cogvlm2-llama3-chat-19B-tgi" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/cogvlm2-llama3-chat-19B-tgi", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "zai-org/cogvlm2-llama3-chat-19B-tgi" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/cogvlm2-llama3-chat-19B-tgi", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use zai-org/cogvlm2-llama3-chat-19B-tgi with Docker Model Runner:
docker model run hf.co/zai-org/cogvlm2-llama3-chat-19B-tgi
CogVLM2
👋 Join us on WeChat
📍Experience the larger-scale CogVLM model on the ZhipuAI Open Platform.
Model introduction
We launch a new generation of CogVLM2 series of models and open source two models built with Meta-Llama-3-8B-Instruct. Compared with the previous generation of CogVLM open source models.
This is a TGI format model.
Quick Start
here is a simple example of how to use the model to chat with the CogVLM2 TGI model.
import requests
import json
import base64
import os
requests.packages.urllib3.disable_warnings()
BAD_RESPONSE = "<error></error>"
def image_to_base64(image_path):
with open(image_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
return encoded_string.decode('utf-8')
def history_to_prompt(query):
answer_format = 'Answer:'
prompt = ''
prompt += 'Question: {} {}'.format(query, answer_format)
return prompt
def get_response(image_path, question):
image_extension = os.path.splitext(image_path)[1][1:]
base64_img = image_to_base64(image_path)
url = 'http://127.0.0.1:8080'
headers = {
'Content-Type': 'application/json',
}
prompt = history_to_prompt(question)
payload = {
"inputs": f"{prompt}",
"stream": False,
"parameters": {
"best_of": 1,
"decoder_input_details": False,
"details": False,
"repetition_penalty": 1.1,
"do_sample": True,
"max_new_tokens": 1000,
"return_full_text": False,
"temperature": 0.8,
"top_p": 0.4,
"top_k": 1
}
}
try_times = 0
while try_times < 3:
try_times += 1
try:
response = requests.post(url, headers=headers, stream=False, data=json.dumps(payload), verify=False)
if response.status_code == 200:
try:
output = response.json()[0]["generated_text"].strip()
return output
except Exception as e:
pass
else:
print(f"Received bad status code: {response.status_code}")
except requests.exceptions.ConnectionError as errc:
print("Error Connecting:", errc)
except requests.exceptions.Timeout as errt:
print("Timeout Error:", errt)
except requests.exceptions.RequestException as err:
print("Something Else:", err)
return BAD_RESPONSE
if __name__ == "__main__":
from glob import glob
files = glob("demo.jpeg")
for file in files:
print(file)
print(get_response(
image_path=file,
question="who is this",
))
License
This model is released under the CogVLM2 LICENSE. For models built with Meta Llama 3, please also adhere to the LLAMA3_LICENSE.
Citation
If you find our work helpful, please consider citing the following papers
@misc{wang2023cogvlm,
title={CogVLM: Visual Expert for Pretrained Language Models},
author={Weihan Wang and Qingsong Lv and Wenmeng Yu and Wenyi Hong and Ji Qi and Yan Wang and Junhui Ji and Zhuoyi Yang and Lei Zhao and Xixuan Song and Jiazheng Xu and Bin Xu and Juanzi Li and Yuxiao Dong and Ming Ding and Jie Tang},
year={2023},
eprint={2311.03079},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
- Downloads last month
- 214