From 80961d2da66005efdd96ffcbd091f9fb0b97b053 Mon Sep 17 00:00:00 2001 From: Tai An Date: Fri, 1 May 2026 01:56:24 -0700 Subject: [PATCH] feat(backends/python): use tempfile.gettempdir() instead of hardcoded /tmp (#9629) Closes #9601 Makes the temporary scratch paths in vllm, vllm-omni, tinygrad, and pocket-tts backends configurable via the standard TMPDIR env var, instead of always writing to /tmp. This is a one-line change per call site that calls tempfile.gettempdir() for the directory and keeps the same filename suffix. Users who run on systems with a small root partition (or want to relocate scratch files to a larger volume) can now redirect these by setting TMPDIR (e.g. TMPDIR=/data/tmp), without affecting the existing LOCALAI_GENERATED_CONTENT_PATH or LOCALAI_UPLOAD_PATH options that already cover other temp paths. Files touched: - backend/python/vllm/backend.py (1 site: video base64 scratch) - backend/python/tinygrad/backend.py (1 site: image fallback dst) - backend/python/pocket-tts/backend.py (1 site: tts wav fallback dst) - backend/python/vllm-omni/backend.py (2 sites: video + audio scratch) --- backend/python/pocket-tts/backend.py | 3 ++- backend/python/tinygrad/backend.py | 3 ++- backend/python/vllm-omni/backend.py | 5 +++-- backend/python/vllm/backend.py | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/python/pocket-tts/backend.py b/backend/python/pocket-tts/backend.py index d7678636b..d372d0d11 100644 --- a/backend/python/pocket-tts/backend.py +++ b/backend/python/pocket-tts/backend.py @@ -8,6 +8,7 @@ import argparse import signal import sys import os +import tempfile import traceback import scipy.io.wavfile import backend_pb2 @@ -204,7 +205,7 @@ class BackendServicer(backend_pb2_grpc.BackendServicer): # Save audio to file output_path = request.dst if not output_path: - output_path = "/tmp/pocket-tts-output.wav" + output_path = os.path.join(tempfile.gettempdir(), "pocket-tts-output.wav") # Ensure output directory exists output_dir = os.path.dirname(output_path) diff --git a/backend/python/tinygrad/backend.py b/backend/python/tinygrad/backend.py index c5867de4f..bb09e9e49 100644 --- a/backend/python/tinygrad/backend.py +++ b/backend/python/tinygrad/backend.py @@ -33,6 +33,7 @@ import json import os import signal import sys +import tempfile import time from concurrent import futures from pathlib import Path @@ -668,7 +669,7 @@ class BackendServicer(backend_pb2_grpc.BackendServicer): ) arr = img_tensor.numpy() image = Image.fromarray(arr) - dst = request.dst or "/tmp/tinygrad_image.png" + dst = request.dst or os.path.join(tempfile.gettempdir(), "tinygrad_image.png") image.save(dst) return backend_pb2.Result(success=True, message=dst) except Exception as exc: diff --git a/backend/python/vllm-omni/backend.py b/backend/python/vllm-omni/backend.py index 646af2a2e..e03c6c6d4 100644 --- a/backend/python/vllm-omni/backend.py +++ b/backend/python/vllm-omni/backend.py @@ -19,6 +19,7 @@ import base64 import io import json import gc +import tempfile from PIL import Image import torch @@ -117,7 +118,7 @@ class BackendServicer(backend_pb2_grpc.BackendServicer): # Try base64 decode try: timestamp = str(int(time.time() * 1000)) - p = f"/tmp/vl-{timestamp}.data" + p = os.path.join(tempfile.gettempdir(), f"vl-{timestamp}.data") with open(p, "wb") as f: f.write(base64.b64decode(video_path)) video = VideoAsset(name=p).np_ndarrays @@ -137,7 +138,7 @@ class BackendServicer(backend_pb2_grpc.BackendServicer): audio_data = base64.b64decode(audio_path) # Save to temp file and load timestamp = str(int(time.time() * 1000)) - p = f"/tmp/audio-{timestamp}.wav" + p = os.path.join(tempfile.gettempdir(), f"audio-{timestamp}.wav") with open(p, "wb") as f: f.write(audio_data) audio_signal, sr = librosa.load(p, sr=16000) diff --git a/backend/python/vllm/backend.py b/backend/python/vllm/backend.py index fcdbb96cd..967c4420c 100644 --- a/backend/python/vllm/backend.py +++ b/backend/python/vllm/backend.py @@ -10,6 +10,7 @@ import os import json import time import gc +import tempfile from typing import List from PIL import Image @@ -602,7 +603,7 @@ class BackendServicer(backend_pb2_grpc.BackendServicer): """ try: timestamp = str(int(time.time() * 1000)) # Generate timestamp - p = f"/tmp/vl-{timestamp}.data" # Use timestamp in filename + p = os.path.join(tempfile.gettempdir(), f"vl-{timestamp}.data") with open(p, "wb") as f: f.write(base64.b64decode(video_path)) video = VideoAsset(name=p).np_ndarrays