RuntimeError: Already borrowed

See original GitHub issue

Question I am encountering a strange issue when I try to send multiple request at the same time (I am doing sort of a stress test). I see in the Haystack FAST_API this in the logs: RuntimeError: Already borrowed Anyone got this before ?

Additional context I am using a single machine: 32Go CPU, no GPU.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
tholorcommented, Jul 5, 2021

Let’s keep it open until we have a nicer fix

2reactions
MichaelBitardcommented, Jul 2, 2021

I found a really ugly solutionhack: instanciate multiple pipelines, and ensure they are not used concurrently via mutex.

in rest_api/controller/search.py I replaced the PIPELINE and /query code by:


from random import randrange
from threading import Lock

NUMBER_OF_PIPELINES = 6
PIPELINES = []
MUTEXES = []
for i in range(NUMBER_OF_PIPELINES):
    logger.info(f"Loading pipeline: {i}")
    PIPELINES.append(Pipeline.load_from_yaml(Path(PIPELINE_YAML_PATH), pipeline_name=QUERY_PIPELINE_NAME))
    MUTEXES.append(Lock())
    logger.info(f"Loaded pipeline nodes: {PIPELINES[i].graph.nodes.keys()}")

PIPELINE = PIPELINES[0]
concurrency_limiter = RequestLimiter(CONCURRENT_REQUEST_PER_WORKER)


@router.post("/query", response_model=Response)
def query(request: Request):
    logger.error("QUERY got request")
    with concurrency_limiter.run():
        pipeline_to_use = randrange(NUMBER_OF_PIPELINES)
        logger.error(f"QUERY Running on pipeline {pipeline_to_use}")
        MUTEXES[pipeline_to_use].acquire()
        try:
            logger.error(f'QUERY concurrency limit not reached, using pipeline: {pipeline_to_use}')
            result = _process_request(PIPELINES[pipeline_to_use], request)
            logger.error("QUERY request processed")
            return result
        finally:
            MUTEXES[pipeline_to_use].release()

I needed a quick fix because my client has some tests coming soon, but that’s really not a valid workaround.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RuntimeError: Already borrowed · Issue #537 - GitHub
We're using transformers (3.5.0) with a fast tokenizer (0.9.3) in production, but sometimes a RuntimeError with Already borrowed is raised ...
Read more >
RuntimeError: Already borrowed
RuntimeError : Already borrowed ... There was a nasty bug in huggingface's tokenizers that caused a random runtime error depending on how you...
Read more >
How to use threads for huggingface transformers
RuntimeError : Already borrowed. Could any of you help me to understand how cand I fix it? Hugging face model:
Read more >
RuntimeError: Already borrowed - CSDN博客
问题:之前写的SBERT模型接口部署上线后最近报了RuntimeError: Already borrowed的错误,在这里记录下。现象:具体的报错如下: File ...
Read more >
New pipeline for zero-shot text classification - #79 by lore-26
... I receive an error, same as in this issue on Github https://github.com/huggingface/tokenizers/issues/537: RuntimeError:Already borrowed
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found