log_prob leaves a temporary output directory per call until interpreter exit
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 22/100
Hướng nghiên cứu
The leak is in CmdStanModel.log_prob in cmdstanpy/model.py, where tempfile.mkdtemp creates an output directory under _TMPDIR that is never removed. Read how temp_single_json cleans up the neighbouring input files, then check the linked pull request #869 before starting, since it already targets this fix. Done means the output directory is removed on both the success and RuntimeError paths, and a test shows the _TMPDIR entry count is unchanged after repeated calls.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Each call to CmdStanModel.log_prob creates a new directory under cmdstanpy._TMPDIR and never removes it. _TMPDIR is cleaned only at interpreter exit (atexit), so a long-running process accumulates one directory, holding an output.csv, per call.
Where
cmdstanpy/model.py, CmdStanModel.log_prob (1.3.0):
output_dir = tempfile.mkdtemp(prefix=self.name, dir=_TMPDIR)
output = os.path.join(output_dir, "output.csv")
...
result = pd.read_csv(output, comment="#")
return result
Nothing removes output_dir, on either the success path or the RuntimeError path. The data and params files right beside it use temp_single_json(...) context managers and are cleaned up.
Why it matters
We run log_prob once per optimizer start, as a gradient diagnostic, inside a long-lived worker process. A single fit runs hundreds of starts, and the worker runs indefinitely. The directories grow without bound until the process exits.
Today we work around it by calling the compiled program's log_prob method directly through subprocess, with an output directory we own. That means duplicating cmdstanpy's argument handling, which we would rather not do.
Suggested fix
Let log_prob own its output directory for the duration of the call, as the JSON inputs already do:
with tempfile.TemporaryDirectory(prefix=self.name, dir=_TMPDIR) as output_dir:
output = os.path.join(output_dir, "output.csv")
...
result = pd.read_csv(output, comment="#")
return result
read_csv loads everything before the directory is removed, so the returned DataFrame is unaffected. An optional output_dir= argument, as optimize/sample have, would also let callers keep the CSV when they want it.
We are happy to open a PR with a test, for example asserting that _TMPDIR's entry count is unchanged after N calls.
Versions
cmdstanpy 1.3.0, CmdStan 2.40.0, Python 3.12, Linux x86_64.
- Ngôn ngữ chính
- Python
- Star
- 198
- Fork
- 82
- Merge trung bình
- 4 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của stan-dev/cmdstanpy
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
laplace_sample: expose CmdStan's diagnostic_file (the Hessian at the mode)Có thể đã có người làm @atarutin đã nhận 6 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
-
Release 2.0Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
-
feature
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Tất cả issue của stan-dev/cmdstanpy
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
huggingface/sentence-transformers#4186 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
documentation good first issue
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
sujithputta02/Esapay#13 ·
-
bot-triaged module: correctness (silent) module: mps module: NaNs and Infs triage review
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
README: CI link/badge checkĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
SCIInstitute/SCIRun#2842 ·
Maintainer thường phản hồi trong vòng 3 ngày