Views
No views yet
1# Download Project Code
2git clone https://github.com/ByungKwanLee/Phantom
3
4# Virtual Environment
5conda create -n trol python=3.11 -y
6conda activate trol
7
8# install torch
9pip3 install torch torchvision
10
11# install requiresments
12pip install -r requirements.txt
13
14# flash attention
15pip install flash-attn --no-build-isolation
16
17# all cache deleted
18conda clean -a && pip cache purgedemo.py)1# model selection
2size = '3.8b' # [Select One] '0.5b' (transformers more recent version) | '1.8b' | '3.8b' (transformers==4.37.2) | '7b'
3
4# User prompt
5prompt_type="with_image" # Select one option "text_only", "with_image"
6img_path='figures/demo.png'
7question="Describe the image in detail"
8
9# loading model
10model, tokenizer = load_model(size=size)
11
12# prompt type -> input prompt
13if prompt_type == 'with_image':
14 # Image Load
15 image = pil_to_tensor(Image.open(img_path).convert("RGB"))
16 inputs = [{'image': image, 'question': question}]
17elif prompt_type=='text_only':
18 inputs = [{'question': question}]
19
20# cpu -> gpu
21for param in model.parameters():
22 if not param.is_cuda:
23 param.data = param.cuda()
24
25# Generate
26with torch.inference_mode():
27
28 # Model
29 _inputs = model.eval_process(inputs=inputs,
30 data='demo',
31 tokenizer=tokenizer,
32 device='cuda:0')
33 generate_ids = model.generate(**_inputs, do_sample=False, max_new_tokens=256)
34answer = tokenizer.batch_decode(generate_ids, skip_special_tokens=True)[0]
35print(answer)