Upload README.md
Browse files
README.md
CHANGED
|
@@ -7,13 +7,7 @@ license: apache-2.0
|
|
| 7 |
在运行脚本之前,首先安装如下必要的依赖。
|
| 8 |
|
| 9 |
```shell
|
| 10 |
-
pip install
|
| 11 |
-
pip install torch transformers==4.40.0
|
| 12 |
-
pip install sentencepiece protobuf
|
| 13 |
-
pip install accelerate pillow
|
| 14 |
-
pip install ninja
|
| 15 |
-
pip install packaging
|
| 16 |
-
pip install flash-attn --no-build-isolation
|
| 17 |
```
|
| 18 |
|
| 19 |
```python
|
|
@@ -24,6 +18,26 @@ from PIL import Image
|
|
| 24 |
import warnings
|
| 25 |
import numpy as np
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def tokenizer_image_token(prompt, tokenizer, image_token_index, return_tensors=None):
|
| 29 |
prompt_chunks = [tokenizer(chunk).input_ids for chunk in prompt.split('<image>')]
|
|
@@ -45,27 +59,7 @@ def tokenizer_image_token(prompt, tokenizer, image_token_index, return_tensors=N
|
|
| 45 |
return torch.tensor(input_ids, dtype=torch.long)
|
| 46 |
raise ValueError(f'Unsupported tensor type: {return_tensors}')
|
| 47 |
return input_ids
|
| 48 |
-
|
| 49 |
-
# set device
|
| 50 |
-
device = 'cuda' # or cpu
|
| 51 |
-
torch.set_default_device(device)
|
| 52 |
-
|
| 53 |
-
# create model
|
| 54 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 55 |
-
'NaughtyDog97/FormalEnhencedGPS-9B',
|
| 56 |
-
torch_dtype=torch.float16, # float32 for cpu
|
| 57 |
-
device_map='auto',
|
| 58 |
-
trust_remote_code=True)
|
| 59 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 60 |
-
'NaughtyDog97/FormalEnhencedGPS-9B',
|
| 61 |
-
use_fast=False,
|
| 62 |
-
trust_remote_code=True)
|
| 63 |
-
|
| 64 |
-
# text prompt
|
| 65 |
-
img_path = 'sample/4927.png'
|
| 66 |
-
qs = 'As shown in the diagram, AE/AB=1/4, M is the midpoint of segment AC, BE is parallel to CP, EA is parallel to CP. Find the ratio of the length of line BC to the length of line CD.'
|
| 67 |
-
prompt = f'Using the provided geometric image and question, first predict the construction_cdl and image_cdl. Then, give a detailed step-by-step solution.\nThe question is:\n{qs}'
|
| 68 |
-
text = f'<|im_start|>user\n<image>\n{prompt}<|im_end|>\n<|im_start|>assistant\n'
|
| 69 |
input_ids = tokenizer_image_token(text, tokenizer, -200, return_tensors='pt').unsqueeze(0).cuda()
|
| 70 |
|
| 71 |
# image, sample images can be found in images folder
|
|
|
|
| 7 |
在运行脚本之前,首先安装如下必要的依赖。
|
| 8 |
|
| 9 |
```shell
|
| 10 |
+
pip install torch transformers==4.40.0 accelerate pillow sentencepiece
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
```
|
| 12 |
|
| 13 |
```python
|
|
|
|
| 18 |
import warnings
|
| 19 |
import numpy as np
|
| 20 |
|
| 21 |
+
# set device
|
| 22 |
+
device = 'cuda' # or cpu
|
| 23 |
+
torch.set_default_device(device)
|
| 24 |
+
|
| 25 |
+
# create model
|
| 26 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 27 |
+
'NaughtyDog97/FormalEnhencedGPS-9B',
|
| 28 |
+
torch_dtype=torch.float16, # float32 for cpu
|
| 29 |
+
device_map='auto',
|
| 30 |
+
trust_remote_code=True)
|
| 31 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 32 |
+
'NaughtyDog97/FormalEnhencedGPS-9B',
|
| 33 |
+
use_fast=False,
|
| 34 |
+
trust_remote_code=True)
|
| 35 |
+
|
| 36 |
+
# text prompt
|
| 37 |
+
img_path = 'sample/4927.png'
|
| 38 |
+
qs = 'As shown in the diagram, AE/AB=1/4, M is the midpoint of segment AC, BE is parallel to CP, EA is parallel to CP. Find the ratio of the length of line BC to the length of line CD.'
|
| 39 |
+
prompt = f'Using the provided geometric image and question, first predict the construction_cdl and image_cdl. Then, give a detailed step-by-step solution.\nThe question is:\n{qs}'
|
| 40 |
+
text = f'<|im_start|>user\n<image>\n{prompt}<|im_end|>\n<|im_start|>assistant\n'
|
| 41 |
|
| 42 |
def tokenizer_image_token(prompt, tokenizer, image_token_index, return_tensors=None):
|
| 43 |
prompt_chunks = [tokenizer(chunk).input_ids for chunk in prompt.split('<image>')]
|
|
|
|
| 59 |
return torch.tensor(input_ids, dtype=torch.long)
|
| 60 |
raise ValueError(f'Unsupported tensor type: {return_tensors}')
|
| 61 |
return input_ids
|
| 62 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
input_ids = tokenizer_image_token(text, tokenizer, -200, return_tensors='pt').unsqueeze(0).cuda()
|
| 64 |
|
| 65 |
# image, sample images can be found in images folder
|