MCPcopy Create free account
hub / github.com/huggingface/sentence-transformers / ComputeMultiProcessTest

Class ComputeMultiProcessTest

tests/test_multi_process.py:10–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import numpy as np
9
10class 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected