Record `joblib.cpu_count()` in the Modal stage runner's CPU report

Open Beginner friendly
#1,721 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
tooling

Research direction

Start at _cpu_visibility() in tools/modal_us_stage.py and follow where its result is placed under runner in the stage receipt. Confirm whether that function executes inside the Modal container or on the host, since that decides whether joblib is importable there and what count it reports. Done means each stage receipt's runner block carries joblib.cpu_count(), verified by running one of the three build stages under a 4-CPU limit and reading the receipt.

Written by the indexing model from the issue text.

Description

_cpu_visibility() in tools/modal_us_stage.py records the CPUs a container shows to tools that size their thread pools: os.cpu_count(), the CPU affinity mask and the *_NUM_THREADS variables. Each stage receipt stores these under runner. Neither os.cpu_count() nor the affinity mask reflects a cgroup CPU quota.

Since #1684, when POPULACE_FIT_PREDICT_WORKERS is unset, QRF prediction threads default to joblib.cpu_count(), and fit jobs (n_jobs=-1) resolve to the same count. That count is the smallest of the CPU count, the affinity mask, the cgroup quota (cpu.max or cpu.cfs_quota_us) and LOKY_MAX_CPU_COUNT. No Modal stage records it. The stages run tools/build_us_puf_support_base.py, tools/build_us_acs_multispine_base.py and tools/build_us_acs_local_release.py, and none of them writes the pool builder's audit_thread_controls. So it isn't known what joblib.cpu_count() returns inside a Modal container with a 4-CPU limit.

Proposed change: add joblib.cpu_count() to _cpu_visibility(), so each stage receipt records the thread count QRF fitting and prediction will use. Check that joblib can be imported where _cpu_visibility() runs.

Raised in review of #1684.

Dominant language
Python
Stars
0
Forks
6
Avg merge
1d 17h
Merged PRs (30d)
190

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PolicyEngine/microcosm

All issues in PolicyEngine/microcosm

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.