Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@

logger = logging.getLogger(__name__)

# Create a shared manager and lock for thread-safe access
manager = Manager()
global_cache = manager.dict()
# Lazily initialized on first use so that importing this module does not
# spawn a subprocess at import time (which breaks Windows multiprocessing).
_manager = None
global_cache = None
lock = Lock()


def _ensure_manager():
global _manager, global_cache
if _manager is None:
_manager = Manager()
global_cache = _manager.dict()


def multiprocessing_cache(max_calls):
"""
A decorator that creates a global cache shared between multiple processes.
Expand All @@ -28,10 +36,14 @@ def multiprocessing_cache(max_calls):
"""

def decorator(func):
call_count = manager.Value("i", 0) # Shared integer for call counting
call_count = None # Initialized lazily alongside the manager

@wraps(func)
def wrapper(*args, **kwargs):
nonlocal call_count
_ensure_manager()
if call_count is None:
call_count = _manager.Value("i", 0)
key = (func.__name__, args, frozenset(kwargs.items()))

with lock:
Expand Down
4 changes: 2 additions & 2 deletions nemo_retriever/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dependencies = [
"nemotron-page-elements-v3>=0.dev0",
"nemotron-graphic-elements-v1>=0.dev0",
"nemotron-table-structure-v1>=0.dev0",
"nemotron-ocr>=0.dev0",
"nemotron-ocr>=0.dev0; sys_platform == 'linux'",
"markitdown",
"timm==1.0.22",
"tqdm",
Expand All @@ -76,7 +76,7 @@ dependencies = [
"soundfile>=0.12.0",
"scipy>=1.11.0",
"nvidia-ml-py",
"vllm==0.16.0",
"vllm==0.16.0; sys_platform == 'linux'",
]

[project.optional-dependencies]
Expand Down
Loading