mirror of
https://github.com/OpenBMB/MiniCPM-V.git
synced 2026-02-05 02:09:20 +08:00
Fix #11, add support for Mac with Apple silicon
This commit is contained in:
36
README.md
36
README.md
@@ -365,6 +365,42 @@ We can obtain the following results:
|
|||||||
"The interesting aspect of this image is the shape of the chicken nuggets on the pan. The nuggets are shaped like the continents of the world, which is an unusual and creative way to present the food. It adds a fun and playful element to the meal, making it more visually appealing and engaging."
|
"The interesting aspect of this image is the shape of the chicken nuggets on the pan. The nuggets are shaped like the continents of the world, which is an unusual and creative way to present the food. It adds a fun and playful element to the meal, making it more visually appealing and engaging."
|
||||||
|
|
||||||
"In the image, China is located on the right side of the pan. It is one of the nuggets shaped like the continents of the world, and its placement on the right side of the pan is consistent with its geographical location in the real world"
|
"In the image, China is located on the right side of the pan. It is one of the nuggets shaped like the continents of the world, and its placement on the right side of the pan is consistent with its geographical location in the real world"
|
||||||
|
|
||||||
|
### Inference on Mac
|
||||||
|
<details>
|
||||||
|
<summary>Click to view example, OmniLMM-3B (i.e., MiniCPM-V) can run on Mac with MPS (Apple silicon or AMD GPUs). </summary>
|
||||||
|
|
||||||
|
```python
|
||||||
|
# test.py
|
||||||
|
import torch
|
||||||
|
from PIL import Image
|
||||||
|
from transformers import AutoModel, AutoTokenizer
|
||||||
|
|
||||||
|
model = AutoModel.from_pretrained('openbmb/MiniCPM-V', trust_remote_code=True, torch_dtype=torch.bfloat16)
|
||||||
|
model = model.to(device='mps', dtype=torch.float16)
|
||||||
|
|
||||||
|
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V', trust_remote_code=True)
|
||||||
|
model.eval()
|
||||||
|
|
||||||
|
image = Image.open('./assets/worldmap_ck.jpg').convert('RGB')
|
||||||
|
question = 'What is interesting about this image?'
|
||||||
|
msgs = [{'role': 'user', 'content': question}]
|
||||||
|
|
||||||
|
answer, context, _ = model.chat(
|
||||||
|
image=image,
|
||||||
|
msgs=msgs,
|
||||||
|
context=None,
|
||||||
|
tokenizer=tokenizer,
|
||||||
|
sampling=True
|
||||||
|
)
|
||||||
|
print(answer)
|
||||||
|
```
|
||||||
|
Run with command:
|
||||||
|
```shell
|
||||||
|
PYTORCH_ENABLE_MPS_FALLBACK=1 python test.py
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
```
|
```
|
||||||
### Deployment on Mobile Phone
|
### Deployment on Mobile Phone
|
||||||
Currently OmniLMM-3B (i.e., MiniCPM-V) can be deployed on mobile phones with Android and Harmony operating systems. 🚀 Try it out [here](https://github.com/OpenBMB/mlc-MiniCPM).
|
Currently OmniLMM-3B (i.e., MiniCPM-V) can be deployed on mobile phones with Android and Harmony operating systems. 🚀 Try it out [here](https://github.com/OpenBMB/mlc-MiniCPM).
|
||||||
|
|||||||
37
README_zh.md
37
README_zh.md
@@ -373,6 +373,43 @@ print(answer)
|
|||||||
"The interesting aspect of this image is the shape of the chicken nuggets on the pan. The nuggets are shaped like the continents of the world, which is an unusual and creative way to present the food. It adds a fun and playful element to the meal, making it more visually appealing and engaging."
|
"The interesting aspect of this image is the shape of the chicken nuggets on the pan. The nuggets are shaped like the continents of the world, which is an unusual and creative way to present the food. It adds a fun and playful element to the meal, making it more visually appealing and engaging."
|
||||||
|
|
||||||
"In the image, China is located on the right side of the pan. It is one of the nuggets shaped like the continents of the world, and its placement on the right side of the pan is consistent with its geographical location in the real world"
|
"In the image, China is located on the right side of the pan. It is one of the nuggets shaped like the continents of the world, and its placement on the right side of the pan is consistent with its geographical location in the real world"
|
||||||
|
|
||||||
|
### Mac推理
|
||||||
|
<details>
|
||||||
|
<summary>点击查看, OmniLMM-3B (即MiniCPM-V) 可基于Mac MPS运行 (Apple silicon or AMD GPUs). </summary>
|
||||||
|
|
||||||
|
```python
|
||||||
|
# test.py
|
||||||
|
import torch
|
||||||
|
from PIL import Image
|
||||||
|
from transformers import AutoModel, AutoTokenizer
|
||||||
|
|
||||||
|
model = AutoModel.from_pretrained('openbmb/MiniCPM-V', trust_remote_code=True, torch_dtype=torch.bfloat16)
|
||||||
|
model = model.to(device='mps', dtype=torch.float16)
|
||||||
|
|
||||||
|
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V', trust_remote_code=True)
|
||||||
|
model.eval()
|
||||||
|
|
||||||
|
image = Image.open('./assets/worldmap_ck.jpg').convert('RGB')
|
||||||
|
question = 'What is interesting about this image?'
|
||||||
|
msgs = [{'role': 'user', 'content': question}]
|
||||||
|
|
||||||
|
answer, context, _ = model.chat(
|
||||||
|
image=image,
|
||||||
|
msgs=msgs,
|
||||||
|
context=None,
|
||||||
|
tokenizer=tokenizer,
|
||||||
|
sampling=True
|
||||||
|
)
|
||||||
|
print(answer)
|
||||||
|
```
|
||||||
|
运行:
|
||||||
|
```shell
|
||||||
|
PYTORCH_ENABLE_MPS_FALLBACK=1 python test.py
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
### 手机端部署
|
### 手机端部署
|
||||||
OmniLMM-3B (即MiniCPM-V) 目前可以部署在Android和Harmony操作系统的手机上。 🚀 点击[这里](https://github.com/OpenBMB/mlc-MiniCPM)开始手机端部署。
|
OmniLMM-3B (即MiniCPM-V) 目前可以部署在Android和Harmony操作系统的手机上。 🚀 点击[这里](https://github.com/OpenBMB/mlc-MiniCPM)开始手机端部署。
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ seaborn==0.13.0
|
|||||||
shortuuid==1.0.11
|
shortuuid==1.0.11
|
||||||
spacy==3.7.2
|
spacy==3.7.2
|
||||||
timm==0.9.10
|
timm==0.9.10
|
||||||
torch==2.0.1
|
torch==2.1.2
|
||||||
torchvision==0.15.2
|
torchvision==0.16.2
|
||||||
tqdm==4.66.1
|
tqdm==4.66.1
|
||||||
protobuf==4.25.0
|
protobuf==4.25.0
|
||||||
transformers==4.36.0
|
transformers==4.36.0
|
||||||
|
|||||||
Reference in New Issue
Block a user