LazyHuman10 commited on
Commit ·
fa60426
1
Parent(s): d2894ff
Patch MiniCPM tied weights compatibility
Browse files- model_engine.py +17 -0
model_engine.py
CHANGED
|
@@ -13,9 +13,26 @@ from typing import Any
|
|
| 13 |
import spaces
|
| 14 |
import torch
|
| 15 |
from transformers import AutoModel, AutoTokenizer
|
|
|
|
| 16 |
from PIL import Image
|
| 17 |
|
| 18 |
MODEL_ID = "openbmb/MiniCPM-V-2_6"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
model = AutoModel.from_pretrained(
|
| 20 |
MODEL_ID,
|
| 21 |
trust_remote_code=True,
|
|
|
|
| 13 |
import spaces
|
| 14 |
import torch
|
| 15 |
from transformers import AutoModel, AutoTokenizer
|
| 16 |
+
from transformers.modeling_utils import PreTrainedModel
|
| 17 |
from PIL import Image
|
| 18 |
|
| 19 |
MODEL_ID = "openbmb/MiniCPM-V-2_6"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
if not hasattr(PreTrainedModel, "all_tied_weights_keys"):
|
| 23 |
+
@property
|
| 24 |
+
def all_tied_weights_keys(self) -> dict:
|
| 25 |
+
"""Compatibility bridge for MiniCPM remote code on newer Transformers."""
|
| 26 |
+
tied_keys = getattr(self, "_tied_weights_keys", None)
|
| 27 |
+
if tied_keys is None:
|
| 28 |
+
return {}
|
| 29 |
+
if isinstance(tied_keys, dict):
|
| 30 |
+
return tied_keys
|
| 31 |
+
return {key: None for key in tied_keys}
|
| 32 |
+
|
| 33 |
+
PreTrainedModel.all_tied_weights_keys = all_tied_weights_keys
|
| 34 |
+
|
| 35 |
+
|
| 36 |
model = AutoModel.from_pretrained(
|
| 37 |
MODEL_ID,
|
| 38 |
trust_remote_code=True,
|