Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Understanding `CmdStanModel` Behavior with `os.fork`

オープン
#780 コメント 11 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python

調査の方向性

まず、CmdStanModel.sample、cpp_options={"STAN_THREADS": True}、およびレポートに示されている os.fork パスの相互作用から始めます。最小限の実行可能な例で2つのケースを再現し、その後 fork 後のチェーンのスケジューリングを比較します。差異が説明され、必要な動作またはドキュメントの変更が回帰テストでカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

I've run into a somewhat odd (and likely edge-case) situation where CmdStanModel.sample behaves unexpectedly after a call to os.fork. I'm providing pseudocode now in the hopes that there is a fairly simple explanation, but happy to make a minimum working example if need be.

Say I run something structured like the following:

import os
from cmdstanpy import CmdStanModel

def run_job():
    # Compile the model
    mod = CmdStanModel(stanfile, cpp_options={"STAN_THREADS": True})
    
    # Run sampling on a detached child process
    pid = os.fork()
    if pid == 0:
        os.setsid()
        mod.sample(data = data, chains=4)
        os._exit()
    else:
        return pid

Even though my CPU has 32 cores, this will only run two chains at once--specifically, Chains 1 and 3 run, then Chains 2 and 4 run. If, however, I remove the cpp_options={"STAN_THREADS": True} kwarg, then everything behaves as expected: all chains sample in parallel.

Is there any immediate explanation for this discrepancy in behavior?

主要言語
Python
スター
198
フォーク
82
平均マージ
6日 15時間
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

stan-dev/cmdstanpy のほかの issue

stan-dev/cmdstanpy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。