Any-to-Any
Transformers
ONNX
Safetensors
minicpmo
feature-extraction
minicpm-o
minicpm-v
multimodal
full-duplex
custom_code
Instructions to use openbmb/MiniCPM-o-4_5 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM-o-4_5 with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("openbmb/MiniCPM-o-4_5", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update modeling_minicpmo.py
#18
by cherry77-cloud - opened
- modeling_minicpmo.py +31 -9
modeling_minicpmo.py
CHANGED
|
@@ -762,17 +762,39 @@ class MiniCPMO(MiniCPMOPreTrainedModel):
|
|
| 762 |
for i in range(bs):
|
| 763 |
audio_embs = audio_embeddings[i]
|
| 764 |
bounds = audio_bounds[i]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 765 |
for embs, bound in zip(audio_embs, bounds):
|
| 766 |
-
|
| 767 |
-
input_embeddings.device
|
|
|
|
| 768 |
)
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 776 |
elif self.training:
|
| 777 |
for i in range(bs):
|
| 778 |
# dummy audio_embedings
|
|
|
|
| 762 |
for i in range(bs):
|
| 763 |
audio_embs = audio_embeddings[i]
|
| 764 |
bounds = audio_bounds[i]
|
| 765 |
+
|
| 766 |
+
one_to_one_match = len(audio_embs) == len(bounds) and all(
|
| 767 |
+
embs.shape[0] == int(bound[1] - bound[0])
|
| 768 |
+
for embs, bound in zip(audio_embs, bounds)
|
| 769 |
+
)
|
| 770 |
+
|
| 771 |
+
if one_to_one_match:
|
| 772 |
for embs, bound in zip(audio_embs, bounds):
|
| 773 |
+
input_embeddings[i, bound[0] : bound[1]] = embs.to(
|
| 774 |
+
device=input_embeddings.device,
|
| 775 |
+
dtype=input_embeddings.dtype,
|
| 776 |
)
|
| 777 |
+
else:
|
| 778 |
+
flat_audio_embs = torch.cat(audio_embs, dim=0).to(
|
| 779 |
+
device=input_embeddings.device,
|
| 780 |
+
dtype=input_embeddings.dtype,
|
| 781 |
+
)
|
| 782 |
+
|
| 783 |
+
total_bound_len = sum(int(bound[1] - bound[0]) for bound in bounds)
|
| 784 |
+
|
| 785 |
+
if flat_audio_embs.shape[0] != total_bound_len:
|
| 786 |
+
raise ValueError(
|
| 787 |
+
f"Audio total length mismatch: {flat_audio_embs.shape[0]} != {total_bound_len}"
|
| 788 |
+
)
|
| 789 |
+
|
| 790 |
+
offset = 0
|
| 791 |
+
for bound in bounds:
|
| 792 |
+
audio_len = int(bound[1] - bound[0])
|
| 793 |
+
input_embeddings[i, bound[0] : bound[1]] = flat_audio_embs[
|
| 794 |
+
offset : offset + audio_len
|
| 795 |
+
]
|
| 796 |
+
offset += audio_len
|
| 797 |
+
|
| 798 |
elif self.training:
|
| 799 |
for i in range(bs):
|
| 800 |
# dummy audio_embedings
|