Skip to content

Commit

Permalink
chore: sample code runs
Browse files Browse the repository at this point in the history
  • Loading branch information
xhiroga committed Oct 25, 2024
1 parent 596e080 commit df0eef2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 49 deletions.
10 changes: 10 additions & 0 deletions software-engineering/openai/clip/_src/text-encoder-only/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Use Text Encoder Only

```shell
uv sync
uv run python main.py
```

## References

- <https://github.com/openai/CLIP/issues/113>
11 changes: 11 additions & 0 deletions software-engineering/openai/clip/_src/text-encoder-only/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import torch
import clip

device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = clip.load("ViT-B/32", device=device)

text = clip.tokenize(["a diagram", "a dog", "a cat"]).to(device)

with torch.no_grad():
text_features = model.encode_text(text)
print(f"{text_features.shape}")
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
# torch==2.5.0 causes "Error: No execution plans support the graph."
dependencies = [
"clip",
"ftfy>=6.3.0",
"regex>=2024.9.11",
"torch==2.5.0+cu124",
"torchvision==0.20.0+cu124",
"torch==2.4.1+cu124",
"torchvision==0.19.1+cu124",
"tqdm>=4.66.5",
]

Expand Down
80 changes: 33 additions & 47 deletions software-engineering/openai/clip/_src/text-encoder-only/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit df0eef2

Please sign in to comment.