Views
No views yet

transformers library.transformers library:pip install transformers>=4.57.11from transformers import AutoProcessor, AutoModelForImageTextToText
2import torch
3
4messages = [
5 {
6 "role": "user",
7 "content": [
8 {
9 "type": "image",
10 "url": "https://raw.githubusercontent.com/thu-coai/Glyph/main/assets/Little_Red_Riding_Hood.png"
11 },
12 {
13 "type": "text",
14 "text": "Who pretended to be Little Red Riding Hood's grandmother"
15 }
16 ],
17 }
18]
19processor = AutoProcessor.from_pretrained("zai-org/Glyph")
20model = AutoModelForImageTextToText.from_pretrained(
21 pretrained_model_name_or_path="zai-org/Glyph",
22 torch_dtype=torch.bfloat16,
23 device_map="auto",
24)
25inputs = processor.apply_chat_template(
26 messages,
27 tokenize=True,
28 add_generation_prompt=True,
29 return_dict=True,
30 return_tensors="pt"
31).to(model.device)
32generated_ids = model.generate(**inputs, max_new_tokens=8192)
33output_text = processor.decode(generated_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False)
34print(output_text)@article{cheng2025glyphscalingcontextwindows,
title={Glyph: Scaling Context Windows via Visual-Text Compression},
author={Jiale Cheng and Yusen Liu and Xinyu Zhang and Yulin Fei and Wenyi Hong and Ruiliang Lyu and Weihan Wang and Zhe Su and Xiaotao Gu and Xiao Liu and Yushi Bai and Jie Tang and Hongning Wang and Minlie Huang},
journal={arXiv preprint arXiv:2510.17800},
year={2025}
}