Repository navigation
Read memory and cores one way, and add --memory-budget and --max-cores to the US build commands - #1853
Merged
Conversation
…s, and the build's resource options Tests for tracker task 1.8 · 1, with placeholders for the names they call: - microcosm.build.host_resources: the machine's memory and CPU count, cgroup limits, a Modal stage container's requested memory and CPU, free memory bounded by a cgroup or Modal request, and --memory-budget / --max-cores (parsing, the budget, copying the options into MICROCOSM_MEMORY_BUDGET and MICROCOSM_MAX_CORES, and refusing an option that did not reach its variable); - tools/load_host_resources.py, which loads the module from its file; - the thread variables held at or below --max-cores, in every US build command; - the post-export worker formula reading the budget and --max-cores; - telemetry's host figures, the UK tool's memory check, the bakeoff tool's memory wait and the Route A driver, supervisor and sampler reading memory through host_resources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es in the US build commands Tracker task 1.8 · 1. microcosm.build.host_resources is now the one reading of the machine: - total memory: physical memory, or a Linux cgroup memory limit where lower; inside a Modal stage container, the requested memory_mib from MICROCOSM_MODAL_RESOURCES (Modal sets no memory limit and gVisor reports the host's memory); - usable cores: os.process_cpu_count(), or a cgroup CPU quota rounded up where lower; inside a Modal container, the class's CPU limit, or its request when it sets none, rounded up; - free memory: psutil's figure, bounded by the room left under a cgroup limit or a Modal request; - the operator's --memory-budget (a share of total memory from 0 to 1, default 0.75, or an amount such as 24GiB) and --max-cores. The national release, local-area release, base and ACS staging commands copy both options into MICROCOSM_MEMORY_BUDGET and MICROCOSM_MAX_CORES before numpy loads, hold every thread variable at or below --max-cores, and check after parsing that what argparse read reached the variables. The post-export worker formula uses the budget in place of 0.75 x memory and at most --max-cores cores. Without either option no thread or worker count changes. Telemetry's host figures (same values), the UK tool's memory check, the bakeoff tool's memory wait, the QRF leaf-memory measurement and the Route A driver, supervisor and sampler read through the module; the Route A tools and the thread-variable setup load it from its file (tools/load_host_resources.py) so they do not load numpy. route_a.sh exports both settings from route_a.env. The driver's free-memory test now checks a figure only the bounded reading gives, in place of a text match whose expected text lacked a quote mark. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd a cap that binds nothing From review round 1 of tracker task 1.8 · 1: - the release-gate dry run must copy the release argv's --max-cores and --memory-budget into their variables before the release tool loads, as the release command does, or it refuses an argv the release accepts; - a --max-cores at or above the machine's CPU count must fill no thread variable, so it never raises a count above what a library would use; the ACS local-release command's start-up, under a cap that binds, uses the release default it later imports rather than N. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l no thread variable for a cap that binds nothing Fixes from review round 1 of tracker task 1.8 · 1: - tools/dry_run_us_release_gates.py runs the release in its own process, so the release's own start-up never copied --max-cores and --memory-budget into their variables and its check refused them; the dry run now copies them before the release tool and numpy load, and refuses a bad value with its usage error. - set_build_thread_environment fills a command's thread variables from --max-cores alone only when N is below the machine's CPU count, which no library's own count exceeds, so a cap at or above every count changes nothing. The ACS local-release command's start-up, under a cap that binds, starts from the release default it applies later (capped_default_count), held to N, instead of N. - Docs, the option's help, route_a.env.example and the changelog say that a Modal plan sets the variables in its env (its options take only each tool's listed flags), and that --max-cores limits the post-export formula, not a worker count named in MICROCOSM_POST_EXPORT_WORKERS or the POPULACE_FIT_* variables. A budget's line says it came from the option or the variable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r a cap, and the dry run's refusals and early thread setup From review round 2 of tracker task 1.8 · 1: - a cap at or above the CPU count keeps a blank thread variable, as the release default does; one below fills it; - each level of an OpenMP list is held to the cap; a value that is not a count is refused only when the cap binds; - the release-gate dry run returns 64 (no report) and removes a stale report when the release's resource options are refused, instead of argparse's 2, which Route A takes as AT-RISK; - under a cap that binds, the dry run sets the thread variables before it loads numpy, as the release command does; without one it sets none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… refuse the dry run's bad settings with its no-report exit Fixes from review round 2 of tracker task 1.8 · 1: - set_build_thread_environment treats --max-cores as binding only below the machine's CPU count. Only a cap that binds fills a blank variable or refuses a value that is not a count; each level of an OMP_NUM_THREADS list is held to the cap. A cap at or above the CPU count no longer fills blank OpenMP or MKL variables, which left torch at its own count and so the calibration's exact weights unchanged. - tools/dry_run_us_release_gates.py returns 64 (no report) and removes a stale report when the release's resource settings are refused, instead of argparse's 2, which Route A reads as AT-RISK. Under a cap that binds it sets the thread variables before numpy loads, as the release command does; without a cap it sets none, as before. - Docs, help and changelog: a cap that binds nothing changes nothing; the formula plans at least one worker; the export probe loads numpy before the release tool, so the cap reaches only what it loads afterwards; the three readings outside host_resources are named. - Two tests no longer depend on the test machine's CPU count or leave thread variables in the test process. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cap, and the dry run under a cap that binds nothing From review round 3 of tracker task 1.8 · 1: - under a cap below the CPU count, a blank thread variable (the library's own count) is held to N, not set to the release default; - max_cores_binds says whether MICROCOSM_MAX_CORES is below the CPU count; - the release-gate dry run applies a thread setting early only under a cap that binds; with one that binds nothing it waits for the release tool to load, as without the cap. The Route A driver's free-memory test now reports 1 KiB free, so it holds on any machine with more than 1 MiB of memory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… threads early only under a cap that binds Fixes from review round 3 of tracker task 1.8 · 1: - Under a cap below the CPU count, a blank thread variable, which leaves the library its own count, becomes N rather than the release default an unset variable takes; the thread setting still fills a blank with itself. - max_cores_binds says whether MICROCOSM_MAX_CORES is below the CPU count. The release-gate dry run sets thread variables before numpy only when it is, so a thread setting under a cap that binds nothing is applied when the release tool loads, as without the cap. - The dry run's docstring and help say exit 64 also covers refused --memory-budget / --max-cores settings. The runbook and route_a.env.example name the stages that load numpy before any thread variable is set, and the runbook says PYTHON_CPU_COUNT below N makes the cap bind nothing (Python 3.13 applies it to os.cpu_count(); the libraries do not read it). - The dry-run test starts each run from blank variables, as a fresh process would. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… module test_local_builder_parser_accepts_every_allowlisted_option compiles the ACS staging builder's _parse_args into a namespace of its own; the parser now adds --memory-budget and --max-cores through host_resources (standard library only), so the namespace holds it. The test also checks that a plan's argv leaves both unset: a Modal plan sets the two variables in its env. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Empty commit. The push of 699ebba produced no GitHub Actions run after 30 minutes, so this push sends a fresh pull-request event (Anthony's go-ahead, 2 December). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… module The stand-in script copies the ACS staging builder's _parse_args, which now adds --memory-budget and --max-cores through host_resources; it loads the module from its file (tools/load_host_resources.py), as the build commands do, so the runner's parser check and the synthetic stage run can call it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1852
Tracker task 1.8 · 1 (project 15, "US build memory, CPU and run time"): the build reads the machine's memory and usable cores one way, on macOS, in Linux cgroups and in Modal stage containers, and the US build commands take
--memory-budget(a share of total memory or an amount in GiB, default 0.75) and--max-cores.What changes
One reading of the machine:
microcosm.build.host_resources(the module #1775 added, now extended):SC_PHYS_PAGES×SC_PAGE_SIZE,hw.memsizeon macOS), or a Linux cgroup memory limit where lower (v2memory.max, v1memory.limit_in_bytes). Inside a Modal stage container: the requestedmemory_mibfromMICROCOSM_MODAL_RESOURCES, because none of the repository's resource classes sets a memory limit and gVisor reports the host's memory unless the sandbox's cgroup has a smaller limit.os.process_cpu_count(), or a cgroup CPU quota rounded up where lower. Inside a Modal container: the class'scpu_limit, or itscpurequest when it sets none, rounded up.MICROCOSM_MODAL_RESOURCESthat is set but is not the runner's request stops sizing; telemetry still leaves it out, as before.The options. The national release, local-area release, base and ACS staging commands:
--memory-budgetand--max-coresintoMICROCOSM_MEMORY_BUDGETandMICROCOSM_MAX_CORESbefore numpy loads, only when run as a command, so child processes and pool workers inherit them; an option that disagrees with its variable is refused;argparseread that never reached its variable (an abbreviation such as--max-core), then print the resolved budget to standard error.--memory-budgetis a bare number in (0, 1] (a share of total memory) or<number>GiB; a bare number above 1, and a budget above total memory, are refused.What they change before 2.6 · 2's planner exists:
--max-cores Nholds every thread variable (OpenMP, OpenBLAS, MKL, BLIS, vecLib, numexpr,LOKY_MAX_CPU_COUNT) at or below N (tools/us_build_thread_environment.py):MICROCOSM_THREADSor the release default; a variable already above N is lowered (each level of anOMP_NUM_THREADSlist);MICROCOSM_THREADSabove N is refused;tools/dry_run_us_release_gates.py) fill the release default, held to N), does a blank variable become N, and is a value that is not a count refused. A cap that binds nothing changes nothing;LOKY_MAX_CPU_COUNTit also holds the QRF'sjoblib.cpu_count()sizing.--max-corescores (N − 1 workers at most, at least one; a count set inMICROCOSM_POST_EXPORT_WORKERSis used as given). Its record gainsmemory_budgetandmax_cores.tools/dry_run_us_release_gates.py, which runs the release in its own process, copies the release argv's two options into their variables before loading it, sets the thread variables before numpy under a cap that binds, and exits 64 (no report) when a setting is refused.Readers moved to the module (same values where the figure existed before): telemetry's
host.cpu_countandhost.memory_bytes,modal_resources(moved fromtelemetry_identity), the UK tool's memory check, the bakeoff tool's memory wait,tools/measure_qrf_leaf_memory.py's CPU count, and the Route A driver'savail_ram_bytes, supervisor and sampler. The Route A tools and the thread setup load the module from its file (tools/load_host_resources.py) so they never importmicrocosm.build, which loads numpy and pandas (about 1 s and 155 MB here).route_a.shexports both settings whenroute_a.envsets them.Readers left as they are, and why:
microcosm.fit.qrf.default_predict_workers()keepsjoblib.cpu_count():microcosm-fitcannot importmicrocosm-build, joblib already applies the same affinity and quota rules, and--max-coresreaches it throughLOKY_MAX_CPU_COUNT. Switching it would change QRF thread counts on Modal with no option given._cpu_visibility()imports nothing from the workspace's packages by design, and its raw readings are the evidence of what gVisor reports.worker_identity.py's schema-4os.cpu_count()reproduces how old records resolved an unset worker count.Output bytes (decision 1.1 · 1)
With neither option nor variable set, no thread variable, thread count or worker count changes:
set_build_thread_environmenttakes the old path exactly whenMICROCOSM_MAX_CORESis unset; the release default is stillmin(os.cpu_count(), 16). The existing process-level tests (test_release_tool_keeps_its_default_without_the_thread_setting,test_a_started_command_sets_nothing_without_the_thread_setting,test_importing_the_release_tool_still_applies_its_default) are unchanged and run in CI.Fraction(3, 4)of total memory rounded down, equal to the oldmemory * 3 // 4for every non-negative integer (tested on three sizes), so worker counts and caps are unchanged; the existing formula tests are unchanged and run in CI.--max-coresat or above the machine's CPU count, nothing changes either (tested: no variable filled, blank variables kept). Below the count a build would otherwise use, it can change output bytes on Linux (OpenBLAS splits sums between its threads); the option's help and the docs say so.1c22fba08; what is new is the budget line on standard error and the two record keys.Tests
Run locally with only the tests this PR adds or changes, each selected by node ID; CI runs the rest.
5dc83ee3d: tests that fail before the change, with placeholder functions so they reach their assertions. 63 tests (155 cases) intest_host_resources.py,test_us_build_tool_thread_defaults.py,test_us_build_resource_options.py(new),test_route_a_supervisor_memory.py(new),test_us_post_export_pool.py,test_telemetry_identity.py,test_run_uk_cut.py,test_bakeoff_us_support_mix_tool.pyandtest_route_a_driver.py: 138 cases failed and 17 passed (the cases whose expected result is "nothing changes"). Failures were on assertions, except the four commands' start-of-run check (AttributeError: the commands ran into their work) and one parser case (argparse exit 2).dae739de7: the implementation. 154 passed and 1 failed: the driver's free-memory test had a wrong expected text, and could not tell the old reading from the new; rewritten to check a figure only the new reading gives, it passes.5ca2857e7/02c8c6d7b(6 tests),2b94e55d2/f84885c2d(5),2690935e0/028c5e143(4). Each set failed before its fix and passes after.bakeoff_us_support_mix.pyandbuild_us_acs_multispine_base.pyare unformatted onmainand left so).Review
Three rounds of adversarial review, each by a fresh reviewer in its own clone.
tools/dry_run_us_release_gates.py) refused any release argv with--max-coresor--memory-budget(it runs the release in-process, so the options never reached their variables), which would stop Route A at its dry-run stage, which runs by default;--max-corescould raise thread counts (a cap above the CPU count filled N; the ACS local-release start-up pre-empted the release default);--max-coresheld every worker pool;MICROCOSM_MAX_CORES/MICROCOSM_MEMORY_BUDGETare not checked when the plan loads, asMICROCOSM_THREADSis, so a bad value stops the stage only when the tool starts, after its inputs are staged. Checking them would change the Modal runner, which the task's decisions ruled out.AT-RISKverdict (at-risk checks only, no certain failure), leaving a stale report;OMP_NUM_THREADSlist was refused under any cap;MICROCOSM_THREADSwas set;os.cpu_count(), which Python 3.13 takes fromPYTHON_CPU_COUNT; withPYTHON_CPU_COUNTbelow N the cap binds nothing although the libraries, which do not read it, may use more than N threads.Bugs left, by priority: two low ones above (the Modal plan check,
PYTHON_CPU_COUNT). Also by design: under a cap that binds, a command with no count of its own fills N, which can raise torch above its own physical-core count when N lies between that count and the CPU count; the stages that are not build commands (base preflight, probe sample, probe) load numpy before any thread variable is set.Environment variables
No secrets, workflows, Docker images or Terraform change. Three plain environment variables are read; none is a secret.
MICROCOSM_MEMORY_BUDGET,MICROCOSM_MAX_CORES--memory-budget/--max-cores(copied into the variable before numpy loads), the shell, Route A'sroute_a.env, or a Modal plan'senv.route_a.shexports each whenroute_a.envsets it;supervise.pystarts each stage with its own environment plus the stage config'senv; the base tool's step processes getos.environ.copy(); pool workers inherit at spawn; the dry run copies them from the release argv; the Modal runner adds a plan'senvto the tool's environment (tool_environmentintools/modal_us_stage_plan.py), whose name checks acceptMICROCOSM_*names.MICROCOSM_MODAL_RESOURCEStool_environment(resources=plan.resources)); a plan may not set it and the runner removes any value the container holds.os.cpu_count()reports inside a Modal gVisor container, which decides whether a plan'sMICROCOSM_MAX_CORESbinds there (the Modal reading of cores and memory itself comes from this variable, not from the container). A stale value left in an operator's shell would reach Route A's stages, where a malformed one stops them at start.What the merge waits for
main; it builds on no other task's branch. Score US post-export requests in the shared worker pool by default #1775 (1.4 · 7), whosehost_resources.pythis extends, is already merged.telemetry_identity.pyand the release, local-area and base tools; whichever PR merges later resolves the overlap. Their sessions were told which functions this PR changes.🤖 Generated with Claude Code