Skip to content

Commit 80961d2

Browse files
authored
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)
1 parent 9c4c3f9 commit 80961d2

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

backend/python/pocket-tts/backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import signal
99
import sys
1010
import os
11+
import tempfile
1112
import traceback
1213
import scipy.io.wavfile
1314
import backend_pb2
@@ -204,7 +205,7 @@ def TTS(self, request, context):
204205
# Save audio to file
205206
output_path = request.dst
206207
if not output_path:
207-
output_path = "/tmp/pocket-tts-output.wav"
208+
output_path = os.path.join(tempfile.gettempdir(), "pocket-tts-output.wav")
208209

209210
# Ensure output directory exists
210211
output_dir = os.path.dirname(output_path)

backend/python/tinygrad/backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import os
3434
import signal
3535
import sys
36+
import tempfile
3637
import time
3738
from concurrent import futures
3839
from pathlib import Path
@@ -668,7 +669,7 @@ async def GenerateImage(self, request, context):
668669
)
669670
arr = img_tensor.numpy()
670671
image = Image.fromarray(arr)
671-
dst = request.dst or "/tmp/tinygrad_image.png"
672+
dst = request.dst or os.path.join(tempfile.gettempdir(), "tinygrad_image.png")
672673
image.save(dst)
673674
return backend_pb2.Result(success=True, message=dst)
674675
except Exception as exc:

backend/python/vllm-omni/backend.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io
2020
import json
2121
import gc
22+
import tempfile
2223

2324
from PIL import Image
2425
import torch
@@ -117,7 +118,7 @@ def _load_video(self, video_path):
117118
# Try base64 decode
118119
try:
119120
timestamp = str(int(time.time() * 1000))
120-
p = f"/tmp/vl-{timestamp}.data"
121+
p = os.path.join(tempfile.gettempdir(), f"vl-{timestamp}.data")
121122
with open(p, "wb") as f:
122123
f.write(base64.b64decode(video_path))
123124
video = VideoAsset(name=p).np_ndarrays
@@ -137,7 +138,7 @@ def _load_audio(self, audio_path):
137138
audio_data = base64.b64decode(audio_path)
138139
# Save to temp file and load
139140
timestamp = str(int(time.time() * 1000))
140-
p = f"/tmp/audio-{timestamp}.wav"
141+
p = os.path.join(tempfile.gettempdir(), f"audio-{timestamp}.wav")
141142
with open(p, "wb") as f:
142143
f.write(audio_data)
143144
audio_signal, sr = librosa.load(p, sr=16000)

backend/python/vllm/backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import json
1111
import time
1212
import gc
13+
import tempfile
1314
from typing import List
1415
from PIL import Image
1516

@@ -602,7 +603,7 @@ def load_video(self, video_path: str):
602603
"""
603604
try:
604605
timestamp = str(int(time.time() * 1000)) # Generate timestamp
605-
p = f"/tmp/vl-{timestamp}.data" # Use timestamp in filename
606+
p = os.path.join(tempfile.gettempdir(), f"vl-{timestamp}.data")
606607
with open(p, "wb") as f:
607608
f.write(base64.b64decode(video_path))
608609
video = VideoAsset(name=p).np_ndarrays

0 commit comments

Comments
 (0)