Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from PIL import Image
4import requests
5from io import BytesIO
6
7url = "https://huggingface.co/qresearch/llama-3-vision-alpha-hf/resolve/main/assets/demo-2.jpg"
8response = requests.get(url)
9image = Image.open(BytesIO(response.content))
10
11
12model = AutoModelForCausalLM.from_pretrained(
13 "qresearch/llama-3.1-8B-vision-378",
14 trust_remote_code=True,
15 torch_dtype=torch.float16,
16).to("cuda")
17
18tokenizer = AutoTokenizer.from_pretrained("qresearch/llama-3.1-8B-vision-378", use_fast=True,)
19
20print(
21 model.answer_question(
22 image, "Briefly describe the image", tokenizer, max_new_tokens=128, do_sample=True, temperature=0.3
23 ),
24)1import torch
2from PIL import Image
3from transformers import AutoModelForCausalLM, AutoTokenizer
4from transformers import BitsAndBytesConfig
5import requests
6from io import BytesIO
7
8
9url = "https://huggingface.co/qresearch/llama-3-vision-alpha-hf/resolve/main/assets/demo-2.jpg"
10response = requests.get(url)
11image = Image.open(BytesIO(response.content))
12
13bnb_cfg = BitsAndBytesConfig(
14 load_in_4bit=True,
15 bnb_4bit_compute_dtype=torch.float16,
16 llm_int8_skip_modules=["mm_projector", "vision_model"],
17)
18
19model = AutoModelForCausalLM.from_pretrained(
20 "qresearch/llama-3.1-8B-vision-378",
21 trust_remote_code=True,
22 torch_dtype=torch.float16,
23 quantization_config=bnb_cfg,
24)
25
26tokenizer = AutoTokenizer.from_pretrained(
27 "qresearch/llama-3.1-8B-vision-378",
28 use_fast=True,
29)
30
31print(
32 model.answer_question(
33 image, "Briefly describe the image", tokenizer, max_new_tokens=128, do_sample=True, temperature=0.3
34 ),
35) .x+=:.
z` ^% .uef^"
.u . . <k .u . :d88E
.u@u .d88B :@8c .u .@8Ned8" .u u .d88B :@8c . `888E
.zWF8888bx ="8888f8888r ud8888. .@^%8888" ud8888. us888u. ="8888f8888r .udR88N 888E .z8k
.888 9888 4888>'88" :888'8888. x88: `)8b. :888'8888. .@88 "8888" 4888>'88" <888'888k 888E~?888L
I888 9888 4888> ' d888 '88%" 8888N=*8888 d888 '88%" 9888 9888 4888> ' 9888 'Y" 888E 888E
I888 9888 4888> 8888.+" %8" R88 8888.+" 9888 9888 4888> 9888 888E 888E
I888 9888 .d888L .+ 8888L @8Wou 9% 8888L 9888 9888 .d888L .+ 9888 888E 888E
`888Nx?888 ^"8888*" '8888c. .+ .888888P` '8888c. .+ 9888 9888 ^"8888*" ?8888u../ 888E 888E
"88" '888 "Y" "88888% ` ^"F "88888% "888*""888" "Y" "8888P' m888N= 888>
88E "YP' "YP' ^Y" ^Y' "P' `Y" 888
98> J88"
'8 @%
` :"