Update README.md
Browse files
README.md
CHANGED
@@ -47,51 +47,8 @@ We will release the training code in some time.
|
|
47 |
Clone the following repo and following instructions for a CLI based inference.
|
48 |
https://github.com/Tensoic-AI/Cerule
|
49 |
|
50 |
-
```shell
|
51 |
-
pip install torch transformers accelerate pillow
|
52 |
-
```
|
53 |
|
54 |
-
|
55 |
-
```python
|
56 |
-
import torch
|
57 |
-
import transformers
|
58 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
59 |
-
from PIL import Image
|
60 |
-
import warnings
|
61 |
-
|
62 |
-
transformers.logging.set_verbosity_error()
|
63 |
-
transformers.logging.disable_progress_bar()
|
64 |
-
warnings.filterwarnings('ignore')
|
65 |
-
|
66 |
-
torch.set_default_device('cuda') # or 'cpu'
|
67 |
-
|
68 |
-
model = AutoModelForCausalLM.from_pretrained(
|
69 |
-
'Tensoic/Cerule',
|
70 |
-
torch_dtype=torch.float16,
|
71 |
-
device_map='auto',
|
72 |
-
trust_remote_code=True)
|
73 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
74 |
-
'Tensoic/Cerule',
|
75 |
-
trust_remote_code=True)
|
76 |
-
|
77 |
-
# text prompt
|
78 |
-
prompt = 'Who are these charecters?'
|
79 |
-
text = f"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\n{prompt} ASSISTANT:"
|
80 |
-
text_chunks = [tokenizer(chunk).input_ids for chunk in text.split('<image>')]
|
81 |
-
input_ids = torch.tensor(text_chunks[0] + [-200] + text_chunks[1], dtype=torch.long).unsqueeze(0)
|
82 |
-
|
83 |
-
image = Image.open('examples/mario.png')
|
84 |
-
image_tensor = model.process_images([image], model.config).to(dtype=model.dtype)
|
85 |
-
|
86 |
-
# generate
|
87 |
-
output_ids = model.generate(
|
88 |
-
input_ids,
|
89 |
-
images=image_tensor,
|
90 |
-
max_new_tokens=100,
|
91 |
-
use_cache=False)[0] #keep use_cache=False or else it might run into some torch dim error
|
92 |
-
|
93 |
-
print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=False).strip())
|
94 |
-
```
|
95 |
|
96 |
## License
|
97 |
Model subject to Gemma(base model license) terms of use along with the underlying datasets(LAOIN and SVIT) subject to their respective licenses. All codes are Apache 2.0
|
|
|
47 |
Clone the following repo and following instructions for a CLI based inference.
|
48 |
https://github.com/Tensoic-AI/Cerule
|
49 |
|
|
|
|
|
|
|
50 |
|
51 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
## License
|
54 |
Model subject to Gemma(base model license) terms of use along with the underlying datasets(LAOIN and SVIT) subject to their respective licenses. All codes are Apache 2.0
|