forked from kingoflolz/CLIP_JAX
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check TPU support and benchmark, add vscode run config for tpu ssh re…
…mote development
- Loading branch information
1 parent
61a82fd
commit e9a65cb
Showing
8 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ __pycache__/ | |
*.egg-info | ||
.pytest_cache | ||
.ipynb_checkpoints | ||
venv/ | ||
|
||
thumbs.db | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
|
||
{ | ||
"name": "Python: Current File", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${file}", | ||
"console": "integratedTerminal" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.pythonPath": "/usr/bin/python3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ regex | |
tqdm | ||
torch~=1.7.1 | ||
torchvision~=0.8.2 | ||
git+https://github.com/deepmind/dm-haiku | ||
dm-haiku | ||
jax | ||
jaxlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import numpy as np | ||
from PIL import Image | ||
import jax | ||
import time | ||
|
||
import clip_jax | ||
|
||
image_fn, text_fn, jax_params, jax_preprocess = clip_jax.load('ViT-B/32', "cpu") | ||
|
||
batch_size = 2048 | ||
|
||
devices = jax.local_devices() | ||
|
||
print(f"jax devices: {devices}") | ||
|
||
jax_params = jax.device_put_replicated(jax_params, devices) | ||
image_fn = jax.pmap(image_fn) | ||
text_fn = jax.pmap(text_fn) | ||
|
||
jax_image = np.expand_dims(jax_preprocess(Image.open("CLIP.png")), (0, 1)) | ||
jax_image = np.repeat(jax_image, len(devices), axis=0) | ||
jax_image = np.repeat(jax_image, batch_size, axis=1) | ||
|
||
jax_text = np.expand_dims(clip_jax.tokenize(["a diagram"]), 0) | ||
jax_text = np.repeat(jax_text, len(devices), axis=0) | ||
jax_text = np.repeat(jax_text, batch_size, axis=1) | ||
|
||
start = time.time() | ||
jax_image_embed = image_fn(jax_params, jax_image) | ||
jax_text_embed = text_fn(jax_params, jax_text) | ||
total = time.time() - start | ||
print(f"{total:.06}s to compile model") | ||
|
||
start = time.time() | ||
for i in range(16): | ||
jax_image_embed = np.array(image_fn(jax_params, jax_image)) | ||
jax_text_embed = np.array(text_fn(jax_params, jax_text)) | ||
|
||
total = time.time() - start | ||
|
||
print(f"{total:.06}s for 16 batches@bs={batch_size} per core") | ||
print(f"{16*len(devices) * batch_size/total:.06} examples/s") | ||
|
||
print("done!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pip3 install --upgrade --user jax jaxlib==0.1.61 | ||
pip3 install -r requirements.txt | ||
pip3 install -e . | ||
pip3 install git+https://github.com/openai/CLIP.git |