Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FlashAttention & Fix load_from_name #58

Merged
merged 5 commits into from
Feb 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix bug in load_from_name to support local file
  • Loading branch information
DtYXs committed Feb 20, 2023
commit 4b78d62d56a5e03ef79e0cb69b0bfe70450e6e67
7 changes: 5 additions & 2 deletions cn_clip/clip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,22 @@ def available_models() -> List[str]:


def load_from_name(name: str, device: Union[str, torch.device] = "cuda" if torch.cuda.is_available() else "cpu",
download_root: str = None):
download_root: str = None, vision_model_name: str = None, text_model_name: str = None):
if name in _MODELS:
model_path = _download(_MODELS[name], download_root or os.path.expanduser("~/.cache/clip"))
model_name = _MODEL_INFO[name]['struct']
elif os.path.isfile(name):
assert vision_model_name and text_model_name, "Please specify specific 'vision_model_name' and 'text_model_name'"
model_path = name
model_name = f'{vision_model_name}@{text_model_name}'
else:
raise RuntimeError(f"Model {name} not found; available models = {available_models()}")

with open(model_path, 'rb') as opened_file:
# loading saved checkpoint
checkpoint = torch.load(opened_file, map_location="cpu")

model = create_model(_MODEL_INFO[name]['struct'], checkpoint)
model = create_model(model_name, checkpoint)
if str(device) == "cpu":
model.float()
else:
Expand Down