BK-Lee commited on
Commit
2f2f69a
1 Parent(s): 7349a53

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +67 -3
README.md CHANGED
@@ -1,3 +1,67 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+ # Two steps only need.
5
+
6
+ First step. (git clone and install required packages)
7
+ ```bash
8
+ # Download Project Code
9
+ git clone https://github.com/ByungKwanLee/Phantom
10
+
11
+ # Virtual Environment
12
+ conda create -n trol python=3.11 -y
13
+ conda activate trol
14
+
15
+ # install torch
16
+ pip3 install torch torchvision
17
+
18
+ # install requiresments
19
+ pip install -r requirements.txt
20
+
21
+ # flash attention
22
+ pip install flash-attn --no-build-isolation
23
+
24
+ # all cache deleted
25
+ conda clean -a && pip cache purge
26
+ ```
27
+
28
+ Second step. (open, edit, and run `demo.py`)
29
+ ```python
30
+ # model selection
31
+ size = '3.8b' # [Select One] '0.5b' (transformers more recent version) | '1.8b' | '3.8b' (transformers==4.37.2) | '7b'
32
+
33
+ # User prompt
34
+ prompt_type="with_image" # Select one option "text_only", "with_image"
35
+ img_path='figures/demo.png'
36
+ question="Describe the image in detail"
37
+
38
+ # loading model
39
+ model, tokenizer = load_model(size=size)
40
+
41
+ # prompt type -> input prompt
42
+ if prompt_type == 'with_image':
43
+ # Image Load
44
+ image = pil_to_tensor(Image.open(img_path).convert("RGB"))
45
+ inputs = [{'image': image, 'question': question}]
46
+ elif prompt_type=='text_only':
47
+ inputs = [{'question': question}]
48
+
49
+ # cpu -> gpu
50
+ for param in model.parameters():
51
+ if not param.is_cuda:
52
+ param.data = param.cuda()
53
+
54
+ # Generate
55
+ with torch.inference_mode():
56
+
57
+ # Model
58
+ _inputs = model.eval_process(inputs=inputs,
59
+ data='demo',
60
+ tokenizer=tokenizer,
61
+ device='cuda:0')
62
+ generate_ids = model.generate(**_inputs, do_sample=False, max_new_tokens=256)
63
+ answer = tokenizer.batch_decode(generate_ids, skip_special_tokens=True)[0]
64
+ print(answer)
65
+ ```
66
+
67
+ So easy to run the code Let's shout Phantom!