| 8 | import numpy as np |
| 9 | |
| 10 | class ComputeMultiProcessTest(unittest.TestCase): |
| 11 | def setUp(self): |
| 12 | self.model = SentenceTransformer('paraphrase-distilroberta-base-v1') |
| 13 | |
| 14 | def test_multi_gpu_encode(self): |
| 15 | # Start the multi-process pool on all available CUDA devices |
| 16 | pool = self.model.start_multi_process_pool(['cpu', 'cpu']) |
| 17 | |
| 18 | sentences = ["This is sentence {}".format(i) for i in range(1000)] |
| 19 | |
| 20 | # Compute the embeddings using the multi-process pool |
| 21 | emb = self.model.encode_multi_process(sentences, pool, chunk_size=50) |
| 22 | assert emb.shape == (len(sentences), 768) |
| 23 | |
| 24 | emb_normal = self.model.encode(sentences) |
| 25 | |
| 26 | |
| 27 | diff = np.max(np.abs(emb - emb_normal)) |
| 28 | print("Max multi proc diff", diff) |
| 29 | assert diff < 0.001 |
| 30 | |
| 31 | |
| 32 |
nothing calls this directly
no outgoing calls
no test coverage detected