load safetensors version in clip
This commit is contained in:
parent
d57daf938a
commit
c2bdbb6ded
|
|
@ -12,6 +12,7 @@ from tqdm import tqdm
|
||||||
|
|
||||||
from .model import build_model
|
from .model import build_model
|
||||||
from .simple_tokenizer import SimpleTokenizer as _Tokenizer
|
from .simple_tokenizer import SimpleTokenizer as _Tokenizer
|
||||||
|
from safetensors import safe_open
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from torchvision.transforms import InterpolationMode
|
from torchvision.transforms import InterpolationMode
|
||||||
|
|
@ -124,6 +125,10 @@ def load(name: str, device: Union[str, torch.device] = "cuda" if torch.cuda.is_a
|
||||||
raise RuntimeError(f"Model {name} not found; available models = {available_models()}")
|
raise RuntimeError(f"Model {name} not found; available models = {available_models()}")
|
||||||
|
|
||||||
with open(model_path, 'rb') as opened_file:
|
with open(model_path, 'rb') as opened_file:
|
||||||
|
if model_path.endswith('.safetensors'):
|
||||||
|
with safe_open(model_path, framework="pt", device="cpu") as f:
|
||||||
|
state_dict = {key: f.get_tensor(key) for key in f.keys()}
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
# loading JIT archive
|
# loading JIT archive
|
||||||
model = torch.jit.load(opened_file, map_location=device if jit else "cpu").eval()
|
model = torch.jit.load(opened_file, map_location=device if jit else "cpu").eval()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue