Skip to content

Instantly share code, notes, and snippets.

@oliverholworthy
Last active May 26, 2023 20:42
Show Gist options
  • Save oliverholworthy/d3fc899c3e88dae96ec4de252b2aa132 to your computer and use it in GitHub Desktop.
Save oliverholworthy/d3fc899c3e88dae96ec4de252b2aa132 to your computer and use it in GitHub Desktop.
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