"lib/bindings/python/vscode:/vscode.git/clone" did not exist on "886506c12d293c8485c9a8781e32d8f6aa016e2d"
Unverified Commit 0ef41ffe authored by dagil-nvidia's avatar dagil-nvidia Committed by GitHub
Browse files

refactor: use tempfile module instead of hardcoded /tmp paths (#5789)


Signed-off-by: default avatarDan Gil <dagil@nvidia.com>
Co-authored-by: default avatarCursor <cursoragent@cursor.com>
parent 3c9ca3fc
......@@ -5,6 +5,7 @@ import asyncio
import logging
import os
import shutil
import tempfile
import time
from dataclasses import dataclass
from typing import AsyncGenerator, AsyncIterator
......@@ -86,6 +87,10 @@ class EncodeWorkerHandler:
self.readables = []
self.embedding_cache = EmbeddingCache()
# Use system temp directory for encoder cache files
self._cache_dir = os.path.join(tempfile.gettempdir(), "encoder_cache")
os.makedirs(self._cache_dir, exist_ok=True)
def cleanup(self):
pass
......@@ -240,16 +245,12 @@ class EncodeWorkerHandler:
f"ENCODER: saving local safetensors file with key {embedding_item.key}, {embedding_item.embeddings_cpu.numel()} * {embedding_item.embeddings_cpu.element_size()} bytes"
)
tensors = {"ec_cache": embedding_item.embeddings_cpu}
safetensors.torch.save_file(
tensors,
f"/tmp/encoder_cache.{embedding_item.key}.safetensors",
cache_path = os.path.join(
self._cache_dir, f"{embedding_item.key}.safetensors"
)
safetensors.torch.save_file(tensors, cache_path)
# [gluo FIXME] need mechanism to clean up local files
request.multimodal_inputs[
idx
].serialized_request = (
f"/tmp/encoder_cache.{embedding_item.key}.safetensors"
)
request.multimodal_inputs[idx].serialized_request = cache_path
else:
descriptor = connect.Descriptor(embedding_item.embeddings_cpu)
self.readables.append(
......
......@@ -20,6 +20,7 @@ import re
import socket
import subprocess
import sys
import tempfile
import time
import uuid
from pathlib import Path
......@@ -546,8 +547,8 @@ async def main():
parser.add_argument(
"--log-dir",
"-l",
default="/tmp/dynamo_logs",
help="Base directory for logs (default: /tmp/dynamo_logs)",
default=os.path.join(tempfile.gettempdir(), "dynamo_logs"),
help=f"Base directory for logs (default: {tempfile.gettempdir()}/dynamo_logs)",
)
parser.add_argument(
"--service-name",
......
......@@ -3,6 +3,9 @@
"""Shared utilities for GPU Memory Service."""
import os
import tempfile
import pynvml
......@@ -16,7 +19,7 @@ def get_socket_path(device: int) -> str:
device: CUDA device index.
Returns:
Socket path (e.g., "/tmp/gms_GPU-12345678-1234-1234-1234-123456789abc.sock").
Socket path (e.g., "<tempdir>/gms_GPU-12345678-1234-1234-1234-123456789abc.sock").
"""
pynvml.nvmlInit()
try:
......@@ -24,4 +27,4 @@ def get_socket_path(device: int) -> str:
uuid = pynvml.nvmlDeviceGetUUID(handle)
finally:
pynvml.nvmlShutdown()
return f"/tmp/gms_{uuid}.sock"
return os.path.join(tempfile.gettempdir(), f"gms_{uuid}.sock")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment