Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions bindings/python/tests/bindings/test_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,15 @@ def test_multiprocessing_with_parallelism(self):
multiprocessing_with_parallelism(tokenizer, True)

def test_multithreaded_concurrency(self):
# Thread worker functions
# Create a single shared tokenizer instance (thread-safe)
shared_tokenizer = Tokenizer(BPE())

# Thread worker functions that use the SAME tokenizer instance
def encode_batch(batch):
tokenizer = Tokenizer(BPE())
return tokenizer.encode_batch(batch)
return shared_tokenizer.encode_batch(batch)

def encode_batch_fast(batch):
tokenizer = Tokenizer(BPE())
return tokenizer.encode_batch_fast(batch)
return shared_tokenizer.encode_batch_fast(batch)

# Create some significant workload
batches = [
Expand All @@ -594,7 +595,7 @@ def encode_batch_fast(batch):
["my name is ringo " * 50] * 20,
]

# Many encoding operations to run concurrently
# Many encoding operations to run concurrently using the same tokenizer
tasks = [
(encode_batch, batches[0]),
(encode_batch_fast, batches[1]),
Expand Down
Loading