Skip to content

Commit

Permalink
Improve temporary directory handling in cuML (#5527)
Browse files Browse the repository at this point in the history
Rely on `pytest` or `tempfile` to create temporary directories instead of hard-coding paths to `/tmp`. This will be more robust across runs and deployments.

Authors:
  - https://github.com/jakirkham

Approvers:
  - Dante Gama Dessavre (https://github.com/dantegd)

URL: #5527
  • Loading branch information
jakirkham authored Jul 31, 2023
1 parent 3c4a758 commit 72b2925
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions python/cuml/benchmark/nvtx_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@

import os
import sys
import tempfile
from subprocess import run
import json


class Profiler:
def __init__(self, tmp_path="/tmp/nsys_report"):
self.nsys_file = tmp_path + "/report.nsys-rep"
self.json_file = tmp_path + "/report.json"
self._execute(["rm", "-rf", tmp_path])
self._execute(["mkdir", "-p", tmp_path])
def __init__(self, tmp_path=None):
self.tmp_dir = tempfile.TemporaryDirectory(dir=tmp_path)
self.nsys_file = os.path.join(self.tmp_dir.name, "report.nsys-rep")
self.json_file = os.path.join(self.tmp_dir.name, "report.json")
self._execute(["rm", "-rf", self.tmp_dir.name])
self._execute(["mkdir", "-p", self.tmp_dir.name])

def __del__(self):
self.tmp_dir.cleanup()
self.tmp_dir = None

@staticmethod
def _execute(command):
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/tests/test_device_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ def test_train_gpu_infer_gpu(test_data):
assert_func(cuml_output, test_data)


def test_pickle_interop(test_data):
pickle_filepath = "/tmp/model.pickle"
def test_pickle_interop(tmp_path, test_data):
pickle_filepath = tmp_path / "model.pickle"

cuEstimator = test_data["cuEstimator"]
if cuEstimator is UMAP:
Expand Down

0 comments on commit 72b2925

Please sign in to comment.