Last active
May 26, 2023 20:42
-
-
Save oliverholworthy/d3fc899c3e88dae96ec4de252b2aa132 to your computer and use it in GitHub Desktop.
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
import numpy as np | |
import tensorflow as tf | |
def test_random_embeddings(): | |
query_embeddings = tf.random.uniform((16, 48)).numpy() | |
item_embeddings = tf.random.uniform((100, 48)).numpy() | |
with tf.device("/gpu:0"): | |
preds_gpu = tf.matmul(tf.constant(query_embeddings), tf.transpose(tf.constant(item_embeddings))) | |
with tf.device("/cpu:0"): | |
preds_cpu = tf.matmul(tf.constant(query_embeddings), tf.transpose(tf.constant(item_embeddings))) | |
np.testing.assert_allclose(preds_gpu.numpy(), preds_cpu.numpy(), atol=1e-4) | |
if __name__ == "__main__": | |
test_random_embeddings() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment