Repository navigation
fix(native-build): give the build child the image's library search path, and report why the torch probe failed - #2912
Conversation
…rt why it failed probe_torch_abi parsed the probe's whole stdout as one JSON document and dropped stderr. Any extra stdout line (a banner or warning printed while torch imports) or a failing `import torch` (a missing shared library in a reduced environment, the wrong interpreter) came back as an empty torch_version, so the preflight said "host torch is not a ROCm build (torch=)" with nothing to act on. - The probe prints its facts on one line prefixed with HYPERLOOM_TORCH_ABI= and only that line is parsed; other stdout is ignored (an unmarked JSON line is still accepted). - torch is a ROCm build when torch.version.hip is set or its version carries a +rocmN label (2.11.0+rocm10.0.0). - A failed probe (non-zero exit, no facts, timeout, interpreter that cannot start) returns an `error` with the return code and the tail of stderr, and the targeted-build preflight puts it in its summary. - probe_torch_abi takes an optional env.
Code metrics gate: PASSEDJudged: the 16 files this change touches. Files it does not touch never fail it; anything found there is listed under Outside this change for information.
Module length warning: over 800 lines, within the 1200-line failure limit (not failing): 2
Thresholds and sources: |
The image's torch imports amdsmi, which loads libamd_smi.so from a ROCm
SDK directory that only the image's LD_LIBRARY_PATH names. The isolated
build child ran with PATH/HOME/TMPDIR/LC_ALL only, so its preflight's
`import torch` failed ("libamd_smi.so: cannot open shared object file")
and the prewarm reported a non-ROCm torch; the compile step, whose
environment is built the same way, would have failed the same import.
- The child's environment carries LD_LIBRARY_PATH (IMAGE_ENV_NAMES, the
variable the local template already carries for the image) where this
process sets it; nothing else of this process. Under bubblewrap its
directories are bound read-only like PATH's.
- A native recipe's compile environment carries it as well.
…d's variables CI runners set LD_LIBRARY_PATH, which the build child is now given: the toolbox test that lists the child's variables allows it, and the bubblewrap test that names every variable runs with it unset.
aiter's narrow-N overlay of the a4w4 table selects Triton and FlyDSL kernels in a table with no libtype column. The CK codegen drops rows whose kernel starts with _ZN, triton_ or flydsl_ and builds the CK kernel a row names as fallbackKernelName instead. The coverage check skipped only _ZN rows, so a module built from the image's own tables was refused by the prewarm and moved aside by the serving preflight. Skip the same prefixes and require the CK fallback kernels.
…hing A preflight that found the image's modules covering its tables, or that could not run, left no line in the runner's log, so a run could not show whether it ran. Log its summary at INFO for skip and noop; a preflight that moves modules aside stays a warning.
chaojhou
left a comment
There was a problem hiding this comment.
PR #2912 -- fix(native-build): give the build child the image's library search path, and report why the torch probe failed
What it does: The aiter prewarm compiles in an isolated child whose environment was four variables. On an image whose torch loads a library that only LD_LIBRARY_PATH names, import torch failed there and the preflight said only that the host torch is not a ROCm build. The child and the compile now also carry the service's LD_LIBRARY_PATH, and a failed torch probe names its return code and the tail of its error. Two more changes found on the same image ride along: the a4w4 coverage check follows aiter's CK codegen for Triton, FlyDSL and ASM rows (it requires their CK fallback, not their own name), and the runner logs one line when its serving preflight moved nothing.
Scenario: on an image whose torch imports amdsmi, which loads libamd_smi.so from a directory only LD_LIBRARY_PATH names, the prewarm's build preflight runs in the isolated child. At the merge base the child's environment is PATH, HOME, TMPDIR and LC_ALL, a failing import comes back as empty facts, and the preflight reports host torch is not a ROCm build (torch=). At the head merged with main the child also holds the service's LD_LIBRARY_PATH, and a probe that still fails is reported as the torch probe of <python> failed (rc=1): ... libamd_smi.so: cannot open shared object file.
Layer: producer for each part (_child_environment, src/hyperloom/measure/runner/native/isolated.py:461-476; probe_torch_abi, src/hyperloom/orchestrator/enablement/runtime/build_utils.py:290-325; csv_jit_kernel_rows, src/hyperloom/orchestrator/actions/executors/_aiter_jit.py:671-681) -> the same frames: they build the child's environment, the probe's result and the list of kernels a module must hold.
Risk: medium -- src/hyperloom/measure/runner/native/isolated.py decides what reaches the unprivileged child that compiles a candidate's code
Decisions for a human:
- src/hyperloom/measure/runner/native/isolated.py, src/hyperloom/measure/runner/native/recipes.py -- the untrusted build child is now given the service's
LD_LIBRARY_PATHas it stands, relative and empty entries included (run), asPATHalready was; credentials, proxies,LD_PRELOADandPYTHONPATHstay out. The list of what passes is the local runner template's constant, so a name added there later also reaches the child -- accept the shared list, or give the isolation one of its own? - src/hyperloom/orchestrator/enablement/runtime/build_utils.py -- a torch whose version carries
+rocmNnow counts as a ROCm build when it reports no HIP version, which the stated failure does not need (the image's torch reports one). Such a torch passes the preflight, and on the native path a compile failure after it is recorded as the candidate's -- keep the label rule? - src/hyperloom/orchestrator/actions/executors/_aiter_jit.py, src/hyperloom/measure/runner/run.py -- three behaviours land together under a title that names the first. The coverage change also newly requires the CK fallback of a libtype-less ASM row, which was skipped whole; aiter builds it -- accept one PR for the three?
Blocking issues: 1
- [X3] The reference and the module docstring still give the build child's old environment [verified]
Problem: docs/reference/environment-variables.md:1088-1089 says of the isolated compile "its environment is onlyPATH,HOME,TMPDIRandLC_ALL", which was exact before this change; the child now also gets the service'sLD_LIBRARY_PATH(src/hyperloom/measure/runner/native/isolated.py:469-475). src/hyperloom/measure/runner/native/isolated.py:8-9, the module's own statement of the isolation, still says the child runs "with none of this process's variables". The diff changes no docs file and rewrites the function's docstring only.
Impact: the page an operator reads to learn what reaches the unprivileged compile lists four variables where there are five, the fifth a loader search path copied from the service.
Action: add the library search path to the sentence at docs/reference/environment-variables.md:1088-1089 (where the service sets it; its directories read-only under bubblewrap) and to src/hyperloom/measure/runner/native/isolated.py:8-9.
Trim in this PR:
- src/hyperloom/orchestrator/enablement/runtime/build_utils.py:280 -- the unmarked-JSON branch of
_abi_line(or [line for line in lines if line.startswith("{")]) -- the probe script is this module's own and always prints the marker; only test fakes print without it - src/hyperloom/orchestrator/enablement/runtime/build_utils.py:294 -- the
envparameter ofprobe_torch_abi-- its one production caller passes none; only tests set it - src/hyperloom/measure/runner/native/isolated.py:461 -- the
environparameter of_child_environment-- its one production call passes the work directory alone; only tests set it
Checked: the whole diff (15 files) on the tree merged with main 1b568c8. What the four-variable environment withheld, who sets LD_LIBRARY_PATH (the service's own environment; nothing of a candidate), and what the bubblewrap policy does with its entries: the existing rule binds absolute ones read-only and masks credential locations. Where the probe runs and with which environment; every caller of the probe and of the coverage rows; that nothing parses the old preflight text. The coverage rule against aiter's CK codegen for the a4w4 table (the three prefixes, the fallback conditions, the separate fallback entry) and against the other tables the function reads. Of the candidates, the stale sentences were upheld by all four refuters; a weakened isolation and an incomplete module accepted were dropped. R6: no security finding beyond the first decision. X9: no internal reference. CI at f13c8ff: every check succeeded. | Ran: in WSL on f13c8ff merged with main 1b568c8, the merge base as control. Four host environments through _child_environment, fourteen row shapes through csv_jit_kernel_rows and twelve probe outputs through probe_torch_abi, on both trees. The head's nine test files over the merge base's production code: twenty cases fail, across seven files and all three parts. The touched test files: 390 passed, 3 skipped (369 at the base); the tests naming native, aiter, jit, prewarm, preflight, recipe, targeted build, isolation or confinement: 4005 passed, none failing on the merge only. lint-imports: 17 kept, 0 broken. Nineteen mutants: fifteen fail a named test; four pass every test (the child also given LD_PRELOAD, a fallback of 0 required, a fallback sharing its row's entry with CK rows, a failed probe's facts read anyway). internal-refs.sh: no hit. Not run: scripts/code_metrics.py (its duplicate-code tool has no binary on this host; the CI job passed); the measurement on the image itself. A workflow of three first readers and two refuters per blocking candidate | Skill: c11e54f4ee37 | Model: claude-fable-5-2 | Base: 40b68c4 | Head: f13c8ff
…m by torch.version.hip The isolated build child and its compile now pass only their own list of service variables (LD_LIBRARY_PATH), not the local runner template's, so a name added there later does not reach the untrusted compile. The torch ABI probe decides ROCm by torch.version.hip alone, reads only its marked line, and takes its environment from the caller's process. The environment reference and the isolation's module docstring now name the library search path the child is given.
|
Addressed the review of f13c8ff in cf2f13a (then merged main; head 73ba57c). Decisions
Blocking
Trims
Surviving mutants, each now failing a named test (checked by applying the mutant)
Local: the touched test files plus |
Round 2 at 73ba57c: the X3 finding is fixed in docs/reference/environment-variables.md and the isolated.py module docstring; see the new card.
PR #2912 -- fix(native-build): give the build child the image's library search path, and report why the torch probe failedWhat it does: the aiter prewarm compiles in an isolated child whose environment was four variables. On an image whose torch loads a library that only Scenario: on an image whose torch imports Risk: medium -- src/hyperloom/measure/runner/native/isolated.py decides what reaches the unprivileged child that compiles a candidate's code
Blocking issues: none Checked: the one commit since f13c8ff as new code, the merge of main, then the whole diff on the head merged with main. The prior finding against both texts and a run of the confinement: an absolute existing directory of the library path is bound read-only, a relative, empty, missing or work-tree entry is not bound, and a credential location is refused. What reaches the child and the compile, end to end: the pass list is the only source of a service variable besides LGTM |
Problem
The aiter prewarm on an image with torch
2.11.0+rocm10.0.0(Python 3.12, gfx950) failed its build preflight with:An empty
torch=meansprobe_torch_abigot nothing usable: it parsed the probe's entire stdout as a single JSON document and discarded stderr, so a failingimport torchand a stray stdout line both produced this message, and the message could not tell them apart.Root cause (confirmed)
The isolated build child runs with
PATH,HOME,TMPDIRandLC_ALLonly. In that imagetorch/cuda/__init__.pyimportsamdsmi, which loadslibamd_smi.sofrom a ROCm SDK directory that only the image'sLD_LIBRARY_PATHnames (.../site-packages/_rocm_sdk_devel/lib). Without itimport torchfails, the probe exits non-zero, and the preflight reported an empty torch version.Measured inside the image, with the image's interpreter, as uid 65534:
PATH/HOME/TMPDIR/LC_ALLonly (the build child's):import torchfails inamdsmiwithKeyError: 'libamd_smi.so'/cannot open shared object file.LD_LIBRARY_PATH:import torchsucceeds (2.11.0+rocm10.0.0, hip7.15.26333).The compile step's environment is built the same way and would have failed the same import.
Change
LD_LIBRARY_PATHwhere it is set, from the isolation's own pass listCHILD_PASSED_ENV_NAMES = ("LD_LIBRARY_PATH",)(inmeasure/runner/native/recipes.py, becauseisolated.pyimports that module), not the local runner template'sIMAGE_ENV_NAMES; nothing else of this process (no credentials, proxies,LD_PRELOAD,PYTHONPATHor key paths). Under bubblewrap its absolute directories are bound read-only.docs/reference/environment-variables.mdand the module docstring ofisolated.pyname the library search path the child is given.HYPERLOOM_TORCH_ABI=; only that line is parsed, other stdout is ignored.torch.version.hipis set.errorwith the return code and the tail of stderr, and none of the facts it may have printed; the targeted-build preflight puts it in its failure summary, so a failure names its cause.Tests
LD_LIBRARY_PATHand no other variable of this process; under bubblewrap its directory is bound read-only; the existing "only its own environment" test runs withLD_LIBRARY_PATHunset.torchthat imports only when a library directory is onLD_LIBRARY_PATH: the real probe fails naminglibamd_smi.soin the old reduced environment and passes in the child's.LD_LIBRARY_PATHonly where it is set.LD_PRELOAD(nor a credential, proxy orPYTHONPATH), and the pass list is exactlyLD_LIBRARY_PATH.+rocmversion withouthip(not ROCm), a CUDA torch, an unmarked JSON line (a failure), a probe that printed facts and then exited non-zero (facts not read), a failing import with a long stderr, timeout and missing interpreter, plus a real run against a stubtorchthat prints on import.measure/runner/native/tests(except two bubblewrap timeout tests that also fail on the base commit on the local host, which cannot start bubblewrap) and the touchedorchestrator/enablement/runtimetests pass.Follow-up: a4w4 coverage check vs aiter's narrow-N overlay
With the torch probe fixed, the prewarm built
module_gemm_a4w4_blockscaleon the same image and then refused it:and the serving preflight moved the module aside for the same reason.
Cause: aiter (ROCm/aiter#7317) added
configs/model_configs/narrow_n_a4w4_blockscale_tuned_gemm.csv, which is merged into the defaultAITER_CONFIG_GEMM_A4W4table. Its 43 gfx950/256 rows selecttriton_preshuffle_*andflydsl_mxpsh_*kernels, with nolibtypecolumn, and some name afallbackKernelName. aiter's CK codegen (get_tune_dictincsrc/ck_gemm_a4w4_blockscale/gen_instances.py) drops rows whose kernel starts with_ZN,triton_orflydsl_, and builds each CKfallbackKernelNameinstead.csv_jit_kernel_rowsdropped only_ZNrows, so it asked the CK module for the Triton/FlyDSL kernel names, which no module holds.Change:
csv_jit_kernel_rowsskips libtype-less rows with the same prefixes (FOREIGN_KERNEL_PREFIXES) and, for such a row, requires its CKfallbackKernelName(not_ZN/Triton/FlyDSL, not empty or0), keyed apart from the CK rows' dispatch entries as aiter's separate fallback registry is. This fixes both the prewarm's check and the serving preflight's.Tests: rows copied from the real narrow-N CSV (header and rows as in aiter): the rows give only their CK fallbacks for gfx950/256 and nothing for another CU count; a module with those fallbacks covers the table and one without them does not; a fallback of
0is not required; a CK row and a fallback of the same shape are both required (neither replaces the other); the prewarm installs an a4w4 module built from an image with the narrow-N overlay when it holds the CK fallback, and refuses it naming the overlay when it does not (this case fails before the change).Real-image evidence
Same image (gfx950, CU 256) and the same recipe both times; the recipe sets no
AITER_CONFIG_*.fd9b690207(probe fixed): the build child imported torch and builtmodule_gemm_a4w4_blockscale, then the coverage check refused it against the narrow-N overlay (above), and the serving preflight moved the image's own module aside. That was the second cause.12fea4eaf3(coverage check fixed): no prewarm was needed. The image'smodule_gemm_a4w4_blockscalepasses the corrected check and is no longer moved aside; nothing was moved, nothing was built before the test, and nothing was built at the first prefill.In run 2 the runner logged nothing about the preflight:
_build_image_own_onceonly logged when the preflight moved modules aside, so a preflight that found the image's modules covering its tables (skip) and one that could not run (noop, e.g. no card target or no aiter JIT directory) both left no trace.Log what the preflight decided
_build_image_own_oncenow logs one INFO line per test with the preflight's summary forskipandnoop(e.g.aiter serving preflight before the test: the serving .so covers the CSVs this boot loads for gfx950; nothing moved, or...: nothing checked: <reason>); a preflight that moves modules aside stays a WARNING. Test: one line per decision, at INFO for skip and noop and WARNING for invalidate.Review decisions (round 2)
CHILD_PASSED_ENV_NAMES, onlyLD_LIBRARY_PATH) for both the child and the compile; it no longer shares the local runner template'sIMAGE_ENV_NAMES.+rocmNversion-label rule is dropped: ROCm is decided bytorch.version.hiponly.Trims: the unmarked-JSON branch of
_abi_line, theenvparameter ofprobe_torch_abiand theenvironparameter of_child_environmentare removed; their tests now setos.environ(monkeypatch) or wrap the probe'srun.