Merge branch 'f-1402-v' into f-1402

This commit is contained in:
Niko1221 committed 2026-10-07 03:59:01 +02:00
commit 5adacbc4e1
14 files changed
+1856 -48

No files matched your search

+49 -6
View File
@@ -16,12 +16,55 @@ rem All of it in one block: cmd reads a .bat file while it runs it, and the git
exit /b 1
)
echo Getting the newest Strata ^(git pull^) ...
git pull --ff-only || (
echo.
echo git pull did not succeed ^(the reason is above^): nothing was updated. Files you changed here can stop it:
echo "git status" lists them.
pause
exit /b 1
git pull --ff-only
if errorlevel 1 (
rem The history was rewritten on 2026-10-06, see #1276: a clone from before has no commit in common with origin/main.
set "REWR="
git merge-base HEAD origin/main >nul 2>nul
if errorlevel 1 set "REWR=1"
git rev-parse --is-shallow-repository 2>nul | findstr /x true >nul && set "REWR="
if defined REWR (
echo.
echo This clone is on the repository's old history ^(cleaned up on 2026-10-06^): it has no commit in common
echo with origin/main, so it cannot be updated by git pull.
set "DIRTY="
for /f "delims=" %%i in ('git status --porcelain --untracked-files^=no') do set "DIRTY=1"
if defined DIRTY (
echo You have local changes to tracked files here, so nothing was touched. To move to the new history
echo yourself ^(your untracked files, models and settings stay where they are^):
echo git branch pre-cleanup-backup ^&^& git stash push
echo git checkout -B main origin/main
echo then run UPDATE.bat again.
pause
exit /b 1
)
set "BK=pre-cleanup-backup"
git rev-parse --verify -q refs/heads/pre-cleanup-backup >nul 2>nul && set "BK=pre-cleanup-backup-%RANDOM%"
set "BR=main"
for /f "delims=" %%i in ('git symbolic-ref --short -q HEAD 2^>nul') do set "BR=%%i"
call git branch %%BK%% HEAD
if errorlevel 1 (
echo Could not make the backup branch: nothing was updated.
pause
exit /b 1
)
call git checkout -q -B %%BR%% origin/main
if errorlevel 1 (
echo.
echo Could not move to the new history ^(the reason is above^): nothing was updated. By hand:
echo git checkout -B main origin/main
pause
exit /b 1
)
call echo Moved to the new history. Your old commits are kept in the branch %%BK%%.
echo Untracked files ^(models, settings, the engine^) were not touched.
) else (
echo.
echo git pull did not succeed ^(the reason is above^): nothing was updated. Files you changed here can stop it:
echo "git status" lists them.
pause
exit /b 1
)
)
) else (
echo This copy of Strata was not made with git, so it cannot fetch new files itself. Download the newest one:
+3 -1
View File
@@ -59,7 +59,9 @@ if [ "${REINSTALL:-0}" = "1" ] || [ ! -f "$cfg" ]; then
.venv/bin/python setup.py --setup --yes "$@"
[ -e "/opt/strata/strata-$tag.json" ] && { cmp -s "/opt/strata/strata-$tag.json" "$cfg" || cp -f "/opt/strata/strata-$tag.json" "$cfg"; }
else
[ -e "/opt/strata/strata-$tag.json" ] || ln -s "$cfg" "/opt/strata/strata-$tag.json"
# #1244: the copy on the volume is the one that counts, so a regular file left in /opt/strata by an earlier setup
# (or by an image built with one) must not stand in for it: edits to /data/config would be ignored
ln -sfn "$cfg" "/opt/strata/strata-$tag.json"
fi
# Later starts skip straight here: setup.py finds the installed config and
+7 -5
View File
@@ -29,11 +29,13 @@ the kernel's amdgpu driver (no ROCm install needed):
- **Detection:** setup finds the card through the kernel's KFD topology. Integrated Radeon GPUs are listed as not
supported. On a PC without an NVIDIA card Strata can use, `--backend hip` is chosen automatically.
- **ROCm:** a system ROCm 7 in `/opt/rocm` (or `$ROCM_PATH`) with hipcc and hipBLAS is used when present. Otherwise
(or when it is older than 7.0) ROCm is installed into `.venv` from AMD's TheRock wheels (~10 GB, no sudo), pinned
to the version this backend was tested with, from the card family's index: `gfx110X-dgpu` for gfx1100 / gfx1101,
`gfx120X-all` for gfx1200 / gfx1201, `gfx103X-all` for gfx1030 (`STRATA_ROCM_VERSION` /
`STRATA_ROCM_INDEX` override them; the gfx1030 index is not checked to carry the pinned version: a system
ROCm 7 is the tested path there).
(or when it is older than 7.0) ROCm is installed into `.venv` from AMD's TheRock wheels (~10 GB, no sudo), from the
card family's index: `gfx110X-dgpu` for gfx1100 / gfx1101, `gfx120X-all` for gfx1200 / gfx1201, `gfx103X-all` for
gfx1030, `gfx1151` for Strix Halo. The version is chosen per family: 7.10.0a20251120 where that is on the index,
7.13.0a20260515 for `gfx103X-all` (its index starts at 7.13, #1103) and 7.14.0a20260608 for `gfx1151` (the 7.10 wheel
segfaults on kernel 7.2.8, #1267). When the index no longer offers the version, setup warns and takes the newest of
the same 7.x line, else of the same major. `STRATA_ROCM_VERSION` / `STRATA_ROCM_INDEX` override them; the gfx1030
wheels are unvalidated (a system ROCm 7 is the tested path there).
- **Engine:** compiled on your PC for the card's architecture (10-20 minutes, once; again after a `git pull` that
changes it, or when you pick a card of another architecture). This needs a C++ compiler and git
(`sudo apt install build-essential git`).
+32 -3
View File
@@ -34,6 +34,18 @@ settings; it cannot be turned back on without a reset of Windows), or, if only t
An update keeps the engine it replaced in `engine\.previous` (one generation, about 210 MiB).
`python setup.py --rollback-engine` puts it back (and keeps the newer one there: run it again to go forward) (#670).
**UPDATE.bat / update.sh say "git pull did not succeed", or "has no commit in common" (#1276).**
The repository's history was cleaned up on 2026-10-06, so a clone made before that cannot be updated with `git pull`.
The 0.1.40.2 scripts handle it: when no tracked file is edited they keep your old commits in the branch
`pre-cleanup-backup` and move the clone to the new history; otherwise they print the two commands for you. Your models,
settings and engine are untracked files and are never touched. An older UPDATE.bat / update.sh (before 0.1.40.2) cannot
do this itself: run these once in the Strata folder, then use UPDATE.bat as usual (add `git stash` first if `git status`
lists edited files):
git fetch origin
git branch pre-cleanup-backup
git checkout -B main origin/main
**Python or the build tools could not be installed.**
Install what it names (links are printed), then run it again. Everything already done is kept.
@@ -86,16 +98,33 @@ from 100 to 14 tok/s with only a few hundred slots too many. Use `--expert-cache
The budget is pinned (locked) in RAM, which leaves the OS and the CPU workers little room. `STRATA_RESIDENT_PIN=0` keeps
it pageable; a smaller budget works too.
**Decode got slower in 0.1.40 on a 32 GB PC with `--resident-budget-gib N`, and the drive is read hard (#1194, #1116, #1085).**
The start line "the file tier reads unbuffered" means the experts outside the RAM copy are read straight from the drive.
0.1.40 chose that whenever the free RAM could not hold all of them; but the same few come back token after token, and
a cache a twentieth of their size serves most of the repeats. 0.1.40.2 asks for that much (at least 1.5 GiB beside the
4 GiB headroom) and reads through the cache otherwise, which measured 7% to 118% faster decode with a third to a sixth of
the drive traffic on a 20 to 32 GB box. On 0.1.40 / 0.1.40.1: `STRATA_UNBUFFERED_LOAD=0` does the same, `=1` forces the
unbuffered reads.
**Linux: the start is OOM-killed while the engine allocates the page-locked expert copy (#1250).**
Page-locked pages come from the driver in one go and cannot wait for the kernel to give back file cache, so with the
model files' cache in the way (little really free RAM, much "available") the host could run out. 0.1.40.2 gives back the
cached pages of the model files it mapped before it page-locks the copy; when the really free RAM still does not cover it,
it takes the pages in 1 GiB steps while the RAM available (cgroup limits included) stays above the headroom, page-locks
what it has, and keeps the rest resident but pageable with a warning ("only N of M GiB could be page-locked"): the answers
are the same, only the copies of the pageable part to the GPU go through the CPU. `STRATA_PIN_GUARD=0` turns this off,
`STRATA_PIN_RESERVE_GIB=N` sets the RAM that must stay free (default: `STRATA_RESIDENT_HEADROOM_GIB`, 4 GiB).
**The Windows display driver resets, then the PC blue-screens (0x141, then 0x116 in `nvlddmkm`) during an answer (#961).**
This is the NVIDIA driver, not Strata: the report shows the same wedge with other CUDA programs on that driver (610.88,
RTX 4080 SUPER). Try another driver (a Studio one, or an older one) and a lower power limit; if it only happens with
`--spec 4`, `--spec 0` avoids the verify window while you wait for a driver fix.
**An RTX 50 card (a source build with CUDA 13.2) answers with nonsense, or reads prompts wrongly (#892, #968).**
CUDA 13.2's compiler (nvcc 13.2.51) miscompiles some of the engine's kernels for sm_120: on our RTX 5070 the IQ2_S and IQ3_S
CUDA 13.2.0 and 13.2.1's compiler (nvcc 13.2.51) miscompile some of the engine's kernels for sm_120: on our RTX 5070 the IQ2_S and IQ3_S
products are wrong (relative error 0.5 to 1.0 in the tests) with 13.2 and right with 13.0. The ready-made engine is built
with 13.0. If you compile it yourself, use CUDA 13.0 or 13.1 (it can sit next to 13.2: `STRATA_NVCC=<path to its nvcc>`);
setup warns when it finds 13.2 for such a card, and takes an older 13.x when one is installed.
with 13.0. If you compile it yourself, use CUDA 13.0, 13.1 or 13.2.2 (13.2.2, nvcc build 13.2.86, fixes it; an older one can sit next to a newer: `STRATA_NVCC=<path to its nvcc>`);
setup warns when it finds 13.2.0 or 13.2.1 for such a card, and takes an older 13.x when one is installed.
**Pictures are refused, or slow.**
"this server was started without the vision encoder": the model was set up for text only - run setup again with
+12
View File
@@ -88,6 +88,17 @@ bool host_available_memory(HostMemory& m, const std::string& meminfo = "/proc/me
/// Pass UINT64_MAX for commit when the platform does not report it.
uint64_t clamp_resident_budget(uint64_t requested, uint64_t physical, uint64_t commit, uint64_t headroom);
/// #1250: one cudaHostAlloc of the whole page-locked complement has no way back when the kernel does not give the
/// pages as fast as the driver takes them (the process is OOM-killed, even with MemAvailable high: clean file cache
/// that cannot be reclaimed at that moment). `free_now` is MemFree (pages that are really free), `bytes` the
/// complement, `reserve` what must stay. True when the pages would have to come from reclaimed cache.
bool pin_depends_on_reclaim(uint64_t free_now, uint64_t bytes, uint64_t reserve);
/// The paced registration takes the next `step` bytes only while the RAM available after it (cgroup limits included)
/// is still above `reserve`.
bool pin_step_fits(uint64_t available, uint64_t step, uint64_t reserve);
/// Parses `key` ("MemFree") of a /proc/meminfo text; 0 when absent.
uint64_t meminfo_bytes(const std::string& meminfo_text, const std::string& key);
/// Build compact offsets for experts absent from both the primary GPU cache and an optional second GPU tier.
/// Kept CPU-only so selection and byte accounting can be tested without initializing a GPU.
bool make_cache_complement_plan(
@@ -724,6 +735,7 @@ private:
detail::ExchangeStorage exchange_storage_; // authoritative when active; original arenas still own memory
bool complement_pinned_ = false;
bool complement_partial_ = false; ///< CS-T: only the first complement_pin_limit_ bytes are registered
bool complement_registered_ = false; ///< the arena is ordinary memory registered with cudaHostRegister (not cudaHostAlloc)
uint64_t complement_pin_limit_ = 0;
uint64_t complement_lock_off_ = 0; ///< the working-set lock covers [lock_off, lock_off + locked)
bool complement_ready_ = false;
+12 -2
View File
@@ -37,10 +37,20 @@ uint64_t total_physical_memory();
/// bytes of RAM available. The file tier passes only the expert bytes it really reads from the files (the experts
/// outside its resident RAM copy) and the RAM that copy really holds - not every shard's bytes and the requested
/// budget, which on a 96 GB PC (#577) made the file tier read unbuffered when the cache could keep its reads.
/// #1194: the file tier's reads are a skewed set (the GPU cache and the RAM copy took the hottest experts; the same
/// few of the rest come back token after token), so the cache does not have to hold all `read_bytes` to serve most of
/// them. With `hot_fraction` < 1 it is enough that the room holds that share of them, but never less than
/// `floor_bytes` (below it the cache holds nothing worth having) and never more than every read. The defaults ask for
/// every byte, as the Windows rule does. Measured on Linux (#1194, a Tesla P100 box under 20 to 32 GB cgroups): through
/// the cache beat the unbuffered reads at every room tried, down to 7% of the read bytes (decode +7% to +118%, a third to
/// a sixth of the drive traffic).
inline bool file_cache_keeps(uint64_t avail, uint64_t arena_bytes, uint64_t read_bytes,
uint64_t margin = 4ull << 30) {
uint64_t margin = 4ull << 30, double hot_fraction = 1.0, uint64_t floor_bytes = 0) {
const uint64_t room = avail > arena_bytes + margin ? avail - arena_bytes - margin : 0;
return room >= read_bytes;
uint64_t need = (uint64_t) ((double) read_bytes * hot_fraction);
if (need < floor_bytes) need = floor_bytes;
if (need > read_bytes) need = read_bytes;
return room >= need;
}
/// Whether `advise_willneed` asks the OS for anything: not on Windows, nor with STRATA_READ_AHEAD=0.
+102 -18
View File
@@ -1625,7 +1625,17 @@ ROCM_INDEXES = {"gfx1100": "https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/",
"gfx1031": "https://rocm.nightlies.amd.com/v2/gfx103X-all/",
"gfx1151": "https://rocm.nightlies.amd.com/v2/gfx1151/", # Strix Halo (docs/STRIX_HALO.md)
"gfx1103": "https://rocm.nightlies.amd.com/v2/gfx110X-all/"} # Radeon 780M: only with STRATA_EXPERIMENTAL_GFX1103=1
ROCM_VERSION = os.environ.get("STRATA_ROCM_VERSION", "7.10.0a20251120") # what Strata's HIP build was tested with
# The TheRock nightly indexes are pruned and move on, and each GPU family's index holds its own range (#1103: gfx103X-all
# starts at 7.13.0a20260422 and has no 7.10; #1267: the 7.10 wheel segfaults on a Strix Halo with kernel 7.2.8), so one
# version for every card cannot work. The wheel is chosen per index (the family): a preferred version, tried first; when
# the index no longer offers it, the newest one of the same 7.x line, else of the same major, with a warning (rocm_pick).
# STRATA_ROCM_VERSION still forces one exact version (no lookup).
ROCM_VERSION_DEFAULT = "7.10.0a20251120" # what Strata's HIP build was tested with (gfx120X, gfx110X)
ROCM_FAMILY_PINS = {"gfx103X-all": "7.13.0a20260515", # #1103: 7.13.0a20260515 runs; the 7.14 nightlies time out
"gfx110X-all": "7.10.0a20251121", # the experimental gfx1103: this index has no ...20251120
"gfx1151": "7.14.0a20260608"} # #1267: 7.14.0a20260529 to 20260608 run on kernel 7.2.8; the 7.10 wheel segfaults
ROCM_VERSION_OVERRIDE = os.environ.get("STRATA_ROCM_VERSION") or None
ROCM_VERSION = ROCM_VERSION_OVERRIDE or ROCM_VERSION_DEFAULT # kept for callers that read one version
ROCM_SYSTEM_MIN = (7, 0) # an older system ROCm is passed over for the wheels (gfx1201 needs ROCm 6.4 or newer)
# STRATA_EXPERIMENTAL_GFX1103=1 (opt-in, unsupported): the Radeon 780M / 760M / 740M iGPU (Ryzen 7040 / 8040, gfx1103) is taken
# as a unified-memory AMD card like Strix Halo, with the portable kernels (no WMMA) (measured on one machine: Ryzen 7 255). Unset: unchanged.
@@ -1653,6 +1663,62 @@ def rocm_index(arch):
return os.environ.get("STRATA_ROCM_INDEX") or ROCM_INDEXES[arch]
def rocm_family(index):
"""The family name of a TheRock index url (.../v2/gfx103X-all/ -> gfx103X-all)."""
return index.rstrip("/").rsplit("/", 1)[-1]
def rocm_vkey(version):
"""Sort key of a TheRock version: 7.13.0a20260515 -> (7, 13, 0, 20260515); None when it is not one."""
m = re.fullmatch(r"(\d+)\.(\d+)\.(\d+)(?:[a-z]+(\d+))?", version)
return tuple(int(g or 0) for g in m.groups()) if m else None
def rocm_index_versions(html):
"""The versions of the `rocm` package that a TheRock index page (<index>/rocm/) lists, oldest first."""
return sorted({m for m in re.findall(r"rocm-(\d+\.\d+\.\d+(?:[a-z]+\d+)?)\.(?:tar\.gz|whl)", html or "")
if rocm_vkey(m)}, key=rocm_vkey)
def rocm_pick(available, preferred):
"""(version, note) for an index that lists `available`: `preferred` when it is there, else the newest of the same
7.x line, else the newest of the same major (the note says so); `preferred` unchanged when the list is empty (the
index could not be read: pip then reports its own error) or nothing of that major exists (the note says so)."""
if not available or preferred in available:
return preferred, None
want = rocm_vkey(preferred)
for same, what in ((lambda k: k[:2] == want[:2], "line"), (lambda k: k[0] == want[0], "major")):
hits = [v for v in available if same(rocm_vkey(v))]
if hits:
got = max(hits, key=rocm_vkey)
return got, (f"ROCm {preferred} is not on this index any more: using {got}, the newest of the same {what} "
f"(set STRATA_ROCM_VERSION to choose another)")
return preferred, (f"ROCm {preferred} is not on this index and nothing of its major version is: "
f"{available[0]} to {available[-1]} are (set STRATA_ROCM_VERSION to one of them)")
def rocm_wanted(index, listing=None):
"""(ROCm wheel version, warning or None) for a TheRock index (see ROCM_FAMILY_PINS). `listing` is the index
page's html (None: fetched from <index>/rocm/; a failed fetch keeps the preferred version)."""
if ROCM_VERSION_OVERRIDE:
version, note = ROCM_VERSION_OVERRIDE, None
else:
preferred = ROCM_FAMILY_PINS.get(rocm_family(index), ROCM_VERSION_DEFAULT)
if listing is None:
try:
req = urllib.request.Request(index.rstrip("/") + "/rocm/", headers={"User-Agent": "strata-setup"})
with urllib.request.urlopen(req, timeout=30) as r:
listing = r.read().decode("utf-8", "replace")
except (OSError, ValueError):
listing = ""
version, note = rocm_pick(rocm_index_versions(listing), preferred)
if rocm_family(index) == "gfx1151" and (rocm_vkey(version) or (9, 0))[:2] < (7, 11):
note = ((note + "; ") if note else "") + (
"the ROCm 7.10 wheels segfault in the HSA runtime on a Strix Halo with a new kernel (7.2.8, #1267): "
"the 7.14 line (docs/STRIX_HALO.md) is the one that works")
return version, note
# Strix Halo (Ryzen AI Max 380 / 385 / 390 / 395 + PRO: Radeon 8040S / 8050S / 8060S, RDNA 3.5, gfx1151) and the other
# integrated Radeons it must never be taken for. pci.ids lists ONE device id for the whole Strix Halo family
# ("1586 Strix Halo [Radeon Graphics / Radeon 8050S Graphics / Radeon 8060S Graphics]"; the 8040S shares it: the
@@ -2212,7 +2278,7 @@ def rocm_dev_missing(sysroot: Path) -> list:
def rocm_root(archs):
"""ROCm for compiling and running the HIP engine for `archs` (one arch or a list: the cards of a layer split):
(root, library folders). A system ROCm 7 with hipcc, hipBLAS and the HIP development files (#446), else AMD's
TheRock wheels (ROCM_VERSION, from the card family's index) installed into .venv."""
TheRock wheels (rocm_wanted: a version per card family, from the family's index) installed into .venv."""
archs = [archs] if isinstance(archs, str) else list(archs)
sysroot = Path(os.environ.get("ROCM_PATH") or "/opt/rocm")
if (sysroot / "bin" / "hipcc").exists() and list((sysroot / "lib").glob("libhipblas.so*")):
@@ -2233,13 +2299,21 @@ def rocm_root(archs):
index = indexes[0]
stamp = Path(sys.prefix) / ".strata-rocm.json"
have = json.loads(stamp.read_text(encoding="utf-8")) if stamp.exists() else {}
if have.get("version") != ROCM_VERSION or have.get("index") != index:
say(f" Installing ROCm {ROCM_VERSION} for AMD GPUs into .venv (AMD's TheRock wheels, ~10 GB, no sudo) ...")
wheel = None
if have.get("index") == index and have.get("version") and not ROCM_VERSION_OVERRIDE \
and (Path(sys.executable).parent / "rocm-sdk").exists() and have["version"] == ROCM_FAMILY_PINS.get(rocm_family(index), ROCM_VERSION_DEFAULT):
wheel = have["version"] # the family's pin is installed: no lookup
if wheel is None:
wheel, note = rocm_wanted(index)
if note:
warn(note)
if have.get("version") != wheel or have.get("index") != index:
say(f" Installing ROCm {wheel} for AMD GPUs into .venv (AMD's TheRock wheels, ~10 GB, no sudo) ...")
pip = [sys.executable, "-m", "pip", "install", "--quiet", "--disable-pip-version-check", "--index-url", index]
if have.get("version") == ROCM_VERSION: # the same version for another GPU family: its own libraries
run(pip + ["--force-reinstall", "--no-deps", f"rocm=={ROCM_VERSION}"])
run(pip + [f"rocm[libraries,devel]=={ROCM_VERSION}"])
stamp.write_text(json.dumps({"version": ROCM_VERSION, "index": index}))
if have.get("version") == wheel: # the same version for another GPU family: its own libraries
run(pip + ["--force-reinstall", "--no-deps", f"rocm=={wheel}"])
run(pip + [f"rocm[libraries,devel]=={wheel}"])
stamp.write_text(json.dumps({"version": wheel, "index": index}))
sdk = Path(sys.executable).parent / "rocm-sdk"
root = Path(out([str(sdk), "path", "--root"]).strip())
if not (root / "llvm" / "bin" / "clang++").exists():
@@ -2636,26 +2710,36 @@ def pip_cuda_libs(toolkit=13) -> None:
pip_install(CUDA_WHEELS, "NVIDIA CUDA libraries (cuBLAS, CUDA runtime; ~0.4 GB)")
CUDA_SM120_SUSPECT = (13, 2) # #892 #968: nvcc 13.2.51 for sm_120 made garbage answers (IQ1_S / IQ2_S / IQ3_S) and prompts
CUDA_SM120_SUSPECT = (13, 2) # #892 #968: nvcc 13.2.0 / 13.2.1 (build 13.2.51) for sm_120 made garbage answers (IQ1_S / IQ2_S / IQ3_S) and prompts
# (K-quant MMQ) that the same source compiled with 13.0.88 answers correctly (llama.cpp hit it too)
CUDA_SM120_FIXED_BUILD = 86 # CUDA 13.2.2 (nvcc build 13.2.86) fixes it (ggml-org/llama.cpp#28581, confirmed on a 5090 in #968)
def nvcc_build(nvcc):
"""The build number of an nvcc ("Build cuda_13.2.r13.2/compiler...", "V13.2.86" -> 86); None when it cannot be read."""
m = re.search(r"\bV\d+\.\d+\.(\d+)", out([nvcc, "--version"]) if nvcc else "")
return int(m.group(1)) if m else None
def sm120_nvcc(nvcc, cuda_v, archs):
"""#892 / #968: CUDA 13.2's nvcc for an RTX 50 card (sm_120). Returns (nvcc, cuda_v): an older 13.x toolkit when one is
installed and the user did not name a compiler (STRATA_NVCC), else the one found, with a warning that says what to
do. Recommends, never forces: a user who picked 13.2 keeps it."""
"""#892 / #968: CUDA 13.2.0 / 13.2.1's nvcc for an RTX 50 card (sm_120). Returns (nvcc, cuda_v): an older 13.x toolkit
when one is installed and the user did not name a compiler (STRATA_NVCC), else the one found, with a warning that says
what to do. CUDA 13.2.2 (build 86 or newer) is fine. Recommends, never forces: a user who picked 13.2 keeps it."""
if not nvcc or cuda_v != CUDA_SM120_SUSPECT or max(archs) < 120:
return nvcc, cuda_v
build = nvcc_build(nvcc)
if build is not None and build >= CUDA_SM120_FIXED_BUILD:
return nvcc, cuda_v
if not os.environ.get("STRATA_NVCC"):
alt, alt_v = find_nvcc(below=CUDA_SM120_SUSPECT)
if alt and alt_v and alt_v >= (13, 0):
ok(f"CUDA {alt_v[0]}.{alt_v[1]} is used for the RTX 50 card (sm_120): CUDA 13.2's compiler made wrong answers "
"there (#892, #968); STRATA_NVCC=<nvcc> picks another")
ok(f"CUDA {alt_v[0]}.{alt_v[1]} is used for the RTX 50 card (sm_120): CUDA 13.2.0 / 13.2.1's compiler made wrong "
"answers there (#892, #968); STRATA_NVCC=<nvcc> picks another")
return alt, alt_v
warn("CUDA 13.2's compiler (nvcc) made garbage prompts and answers for RTX 50 cards (sm_120) in two reports "
"(#892, #968): the same source compiled with CUDA 13.0 or 13.1 is right. If the engine answers with "
"nonsense, install CUDA 13.0 next to it (https://developer.nvidia.com/cuda-toolkit-archive) and set "
"STRATA_NVCC to its nvcc; the ready-made engine is built with 13.0")
warn("CUDA 13.2.0 and 13.2.1's compiler (nvcc) made garbage prompts and answers for RTX 50 cards (sm_120) in two "
"reports (#892, #968): the same source compiled with CUDA 13.0, 13.1 or 13.2.2 is right. If the engine answers "
"with nonsense, update to CUDA 13.2.2 or install CUDA 13.0 next to it (https://developer.nvidia.com/cuda-toolkit-archive) "
"and set STRATA_NVCC to its nvcc; the ready-made engine is built with 13.0")
return nvcc, cuda_v
+170 -9
View File
@@ -88,6 +88,30 @@ uint64_t clamp_resident_budget(uint64_t requested, uint64_t physical, uint64_t c
return room > margin ? room - margin : 0;
}
bool pin_depends_on_reclaim(uint64_t free_now, uint64_t bytes, uint64_t reserve) {
return bytes > 0 && free_now < bytes + reserve;
}
bool pin_step_fits(uint64_t available, uint64_t step, uint64_t reserve) {
return available >= step + reserve;
}
uint64_t meminfo_bytes(const std::string& meminfo_text, const std::string& key) {
std::istringstream in(meminfo_text);
std::string line;
const std::string want = key + ":";
while (std::getline(in, line)) {
std::istringstream fields(line);
std::string k, unit;
uint64_t value = 0;
if (fields >> k >> value && k == want) {
fields >> unit;
return unit == "kB" ? value * 1024 : value;
}
}
return 0;
}
bool make_cache_complement_plan(
int64_t n_layers, int64_t n_expert, const std::vector<uint64_t>& layer_blob_bytes,
const std::vector<std::pair<int32_t, int32_t>>& primary_gpu_pairs,
@@ -348,6 +372,21 @@ bool available_memory_bytes(uint64_t& bytes, uint64_t* commit = nullptr) {
return bytes > 0;
}
/// #1250: the pages that are really free (MemFree), not the reclaimable cache MemAvailable counts; false when unknown.
bool free_memory_bytes(uint64_t& bytes) {
#if defined(__linux__)
std::ifstream info("/proc/meminfo");
if (!info) return false;
std::stringstream text;
text << info.rdbuf();
bytes = detail::meminfo_bytes(text.str(), "MemFree");
return bytes > 0;
#else
bytes = 0;
return false;
#endif
}
void log_complement_memory(const char* stage, uint64_t requested) {
#if defined(_WIN32)
MEMORYSTATUSEX status{};
@@ -395,10 +434,14 @@ bool file_tier_unbuffered(const std::vector<std::string>& paths, uint64_t arena_
why = "the available RAM is unknown";
return false;
}
const bool keepable = strata::platform::file_cache_keeps(avail, arena_bytes, read_bytes);
// #1194: the experts read from the files are a skewed set: a cache holding a twentieth of them (at least 1.5 GiB)
// serves most of the repeats, and beat the unbuffered reads at every room measured (it reads 2 to 7 times less from
// the drive). `avail` already has what this process and the cgroup hold taken off, so 1 GiB is left for the rest.
const bool keepable = strata::platform::file_cache_keeps(avail, arena_bytes, read_bytes, 1ull << 30, 0.05,
3ull << 29);
char msg[256];
std::snprintf(msg, sizeof msg, "%.1f GiB available, %.1f GiB of it still to be taken by the RAM copy, %.1f GiB "
"of experts read from the files: the file cache %s keep them",
"of experts read from the files: the file cache %s keep the ones that come back",
(double) avail / (1ull << 30), (double) arena_bytes / (1ull << 30), (double) read_bytes / (1ull << 30),
keepable ? "can" : "cannot");
why = msg;
@@ -857,9 +900,9 @@ void FileExpertSource::close() {
io_stop();
inputs_.clear();
if (complement_arena_ != nullptr) {
if (complement_pinned_ && !complement_partial_) (void) cudaFreeHost(complement_arena_);
if (complement_pinned_ && !complement_registered_) (void) cudaFreeHost(complement_arena_);
else {
if (complement_partial_) (void) cudaHostUnregister(complement_arena_);
if (complement_registered_) (void) cudaHostUnregister(complement_arena_);
if (complement_locked_ > 0)
strata::platform::unlock_resident((uint8_t*) complement_arena_ + complement_lock_off_, complement_locked_);
std::free(complement_arena_);
@@ -885,6 +928,7 @@ void FileExpertSource::close() {
complement_offsets_.clear();
complement_pinned_ = false;
complement_partial_ = false;
complement_registered_ = false;
complement_pin_limit_ = 0;
complement_lock_off_ = 0;
complement_ready_ = false;
@@ -2148,6 +2192,7 @@ bool FileExpertSource::pin_cache_complement(
const uint8_t* host = nullptr;
const uint8_t* device = nullptr;
bool pinned_ok = false;
bool paced = false; ///< #1250: the pages are taken in steps and page-locked afterwards
uint64_t locked = 0;
uint64_t partial_pin = 0; ///< CS-T: a registered prefix of a locked arena
uint64_t lock_off = 0; ///< where the working-set lock starts (after the registered prefix)
@@ -2162,12 +2207,60 @@ bool FileExpertSource::pin_cache_complement(
}
arena = nullptr;
};
#if defined(__linux__)
// #1250: the cached pages of the model files this source maps (the engine read them itself), given back
auto drop_file_cache = [&]() {
auto drop = [](const uint8_t* at, uint64_t len, int fd) {
if (at != nullptr && len > 0) (void) madvise((void*) at, (size_t) len, MADV_DONTNEED);
if (fd >= 0) (void) posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
};
if (maps_.empty()) drop(base_, mapped_bytes_, fd_);
else for (const Map& m : maps_) drop(m.base, m.bytes, m.fd);
};
#endif
if (bytes > 0) {
std::fprintf(stderr, "FileExpertSource: allocating %.2f GiB %s cache complement\n",
(double) bytes / 1073741824.0, pin ? "page-locked" : "pageable resident");
log_complement_memory("before complement allocation", bytes);
std::fflush(stderr);
// #1250: the driver takes page-locked pages in one go and cannot wait for the kernel to reclaim file cache: with
// the cache of the model files the engine read itself in the way (MemFree low, MemAvailable high) a host was
// OOM-killed here. First give those pages back (the engine's own mappings); when what is really free still
// does not cover the complement, register it in steps, each only while the RAM left stays above the reserve.
// STRATA_PIN_GUARD=0 pages-locks in one go as before, =2 always registers in steps (a test); STRATA_PIN_RESERVE_GIB
// is the RAM that must stay above every step (default: the resident headroom, at least 2 GiB)
const uint64_t pace_reserve = [&] {
const char* v = std::getenv("STRATA_PIN_RESERVE_GIB");
return v != nullptr && std::atof(v) > 0 ? (uint64_t) (std::atof(v) * 1073741824.0)
: std::max<uint64_t>(headroom_bytes, 2ull << 30);
}();
#if defined(__linux__)
if (pin) {
static const int guard = [] {
const char* v = std::getenv("STRATA_PIN_GUARD");
return v == nullptr ? 1 : std::atoi(v);
}();
uint64_t free_now = 0;
if (guard == 2) {
paced = true;
std::fprintf(stderr, "FileExpertSource: STRATA_PIN_GUARD=2: page-locking the complement in steps\n");
} else if (guard != 0 && free_memory_bytes(free_now) &&
detail::pin_depends_on_reclaim(free_now, bytes, pace_reserve)) {
drop_file_cache();
const uint64_t before = free_now;
if (free_memory_bytes(free_now))
std::fprintf(stderr, "FileExpertSource: %.2f GiB really free for a %.2f GiB page-locked complement; "
"the model files' cached pages were released: %.2f GiB free\n",
(double) before / 1073741824.0, (double) bytes / 1073741824.0,
(double) free_now / 1073741824.0);
paced = detail::pin_depends_on_reclaim(free_now, bytes, pace_reserve);
if (paced)
std::fprintf(stderr, "FileExpertSource: the rest comes from reclaimed cache of other files: "
"page-locking it in steps, as far as the RAM allows (#1250)\n");
}
}
#endif
if (pin && !paced) {
const cudaError_t allocated = cudaHostAlloc(&arena, (size_t) bytes,
cudaHostAllocMapped | cudaHostAllocPortable);
if (allocated == cudaSuccess) {
@@ -2198,7 +2291,15 @@ bool FileExpertSource::pin_cache_complement(
std::fflush(stderr);
}
errno = 0;
arena = std::malloc((size_t) bytes);
if (paced) { // page-aligned: the steps are registered on page boundaries
#if !defined(_WIN32)
void* aligned = nullptr;
const uint64_t page = 4096;
if (posix_memalign(&aligned, (size_t) page, (size_t) ((bytes + page - 1) / page * page)) == 0) arena = aligned;
#endif
} else {
arena = std::malloc((size_t) bytes);
}
if (arena == nullptr) {
const int allocation_errno = errno;
err = "FileExpertSource: pageable resident complement allocation failed (malloc errno " +
@@ -2226,7 +2327,63 @@ bool FileExpertSource::pin_cache_complement(
const char* v = std::getenv("STRATA_PARTIAL_PIN_GIB");
return (uint64_t) ((v != nullptr && std::atof(v) > 0 ? std::atof(v) : 24.0) * 1073741824.0);
}();
if (budget_bytes > 0 && partial_on) {
if (paced) {
// #1250: the pages are taken in 1 GiB steps by ordinary page faults (which reclaim file cache as
// they need to), each only while the RAM available (the cgroup's room included) stays above the
// reserve; then the pages that are there are page-locked in ONE registration (nothing is
// allocated then, the driver only pins them), so a blob never straddles two registrations. The
// hottest experts come first in the arena: they are the pinned ones; the rest is locked pageable
// memory, as when the driver refuses the page-locking.
constexpr uint64_t kStep = 1ull << 30, kPage = 4096;
uint64_t got = 0;
const char* stop = nullptr;
while (got < bytes) {
const uint64_t step = std::min<uint64_t>(kStep, bytes - got);
uint64_t avail_now = 0;
if (!available_memory_bytes(avail_now) || !detail::pin_step_fits(avail_now, step, pace_reserve)) {
stop = "the RAM left would fall under the reserve";
break;
}
for (uint64_t at = got; at < got + step; at += kPage) ((volatile uint8_t*) arena)[at] = 0;
got += step;
}
// cut at an expert boundary: a blob that runs past the registered range would be refused by a
// cudaMemcpyAsync as not page-locked
uint64_t w = got;
for (size_t i = 0; i < offsets.size() && w < bytes; ++i) {
if (offsets[i] == kNoComplement) continue;
const uint64_t b = layer_blob_bytes_[i / (size_t) n_expert_];
if (offsets[i] < got && offsets[i] + b > got) { w = offsets[i]; break; }
}
if (w > 0) {
if (cudaHostRegister(arena, (size_t) w, cudaHostRegisterMapped | cudaHostRegisterPortable) ==
cudaSuccess) {
void* alias = nullptr;
if (cudaHostGetDevicePointer(&alias, arena, 0) == cudaSuccess && alias != nullptr) {
device = (const uint8_t*) alias;
partial_pin = w;
} else {
(void) cudaGetLastError();
(void) cudaHostUnregister(arena);
if (stop == nullptr) stop = "no device alias";
}
} else {
(void) cudaGetLastError();
if (stop == nullptr) stop = "the driver refused to page-lock it";
}
}
lock_off = partial_pin;
char msg[240];
if (stop != nullptr)
std::snprintf(msg, sizeof msg, "WARNING: only %.2f of %.2f GiB could be page-locked (%s); the rest is "
"resident but pageable, so its copies to the GPU go through the CPU (#1250)",
(double) partial_pin / 1073741824.0, (double) bytes / 1073741824.0, stop);
else
std::snprintf(msg, sizeof msg, "%.2f GiB page-locked after taking the pages in steps",
(double) partial_pin / 1073741824.0);
note += std::string(note.empty() ? "" : "; ") + msg;
if (stop != nullptr) std::fprintf(stderr, "FileExpertSource: %s\n", msg);
} else if (budget_bytes > 0 && partial_on) {
const uint64_t step = 2ull << 30;
for (uint64_t want = std::min(bytes, pin_cap); want >= step; want = want > step ? want - step : 0) {
// cut at an expert boundary: a blob that started inside the registered range and ran past it
@@ -2258,9 +2415,11 @@ bool FileExpertSource::pin_cache_complement(
(double) partial_pin / 1073741824.0);
note += std::string("; ") + msg;
}
lock_off = partial_pin;
if (!paced) lock_off = partial_pin;
// (paced: lock_off was set above)
const strata::platform::LockResult lr =
strata::platform::lock_resident((uint8_t*) arena + lock_off, bytes - lock_off);
lock_off < bytes ? strata::platform::lock_resident((uint8_t*) arena + lock_off, bytes - lock_off)
: strata::platform::LockResult{true, 0, ""};
locked = lr.locked_bytes;
note += (note.empty() ? "" : "; ") + lr.note;
}
@@ -2392,7 +2551,9 @@ bool FileExpertSource::pin_cache_complement(
complement_offsets_ = std::move(offsets);
complement_pinned_ = (pinned_ok || partial_pin > 0) && bytes > 0;
complement_pin_limit_ = pinned_ok ? bytes : partial_pin;
complement_partial_ = !pinned_ok && partial_pin > 0;
complement_registered_ = !pinned_ok && partial_pin > 0;
// a paced registration that covers the whole arena is as good as a cudaHostAlloc'd one
complement_partial_ = complement_registered_ && !(paced && partial_pin >= bytes);
complement_locked_ = locked;
complement_lock_off_ = lock_off;
complement_lent_slots_ = lend ? n_slots - keep_from : 0;
+24
View File
@@ -45,6 +45,30 @@ int file_cache_keeps_cases() {
got == c.keeps ? "" : " <-- WRONG");
fail |= got != c.keeps;
}
// #1194, the Linux file tier: a skewed read set, so a twentieth of it (at least 1.5 GiB) is room enough
const Case linux_cases[] = {
{"#1194: 31 GB + 12 GB GPU, budget 18 built (6.4 avail, 13.6 read)", 6.4, 0.0, 13.6, true},
{"#1194: before the copy (avail 25, arena 18, read 13.6)", 25.0, 18.0, 13.6, true},
{"32 GB cgroup, budget 18, copy built (12.1 avail, 22 read)", 12.1, 0.0, 22.0, true},
{"32 GB cgroup, budget 24, copy built (3.8 avail, 16 read)", 3.8, 0.0, 16.0, true},
{"20 GB cgroup, budget 12, copy built (4.7 avail, 28 read)", 4.7, 0.0, 28.0, true},
{"12 GB cgroup, budget 6, copy built (3.5 avail, 34 read)", 3.5, 0.0, 34.0, true},
{"no room beside the margin (1 avail, 47 read)", 1.0, 0.0, 47.0, false},
{"room under the 1.5 GiB floor (2.4 avail, 47 read)", 2.4, 0.0, 47.0, false},
{"room a twentieth of the reads (3.4 avail, 47 read)", 3.4, 0.0, 47.0, true},
{"room just under that (3.3 avail, 47 read)", 3.3, 0.0, 47.0, false},
{"a big read set needs its twentieth (4 avail, 200 read)", 4.0, 0.0, 200.0, false},
{"a big read set with that room (12 avail, 200 read)", 12.0, 0.0, 200.0, true},
{"read less than the floor (2.5 avail, 1 read)", 2.5, 0.0, 1.0, true},
{"nothing available", 0.0, 0.0, 1.0, false},
{"arena larger than the RAM", 10.0, 20.0, 5.0, false},
};
for (const Case& c : linux_cases) {
const bool got = file_cache_keeps(gib(c.avail), gib(c.arena), gib(c.read), 1ull << 30, 0.05, 3ull << 29);
std::printf("file_cache_keeps (Linux file tier) %-52s -> %s%s\n", c.what, got ? "buffered" : "unbuffered",
got == c.keeps ? "" : " <-- WRONG");
fail |= got != c.keeps;
}
return fail;
}
} // namespace
+19
View File
@@ -322,6 +322,24 @@ void test_resident_exchange() {
require(offsets == before, "exchanging back did not restore the plan");
}
// #1250: when the page-locked complement is registered in steps, and what a meminfo reading says
void test_pin_pacing() {
using namespace strata::core::detail;
constexpr uint64_t GiB = 1ull << 30;
// the reporter's reading: 54 GiB available but 16 GiB really free for a 26 GiB complement
require(pin_depends_on_reclaim(16 * GiB, 26 * GiB, 4 * GiB), "a complement bigger than the free pages was not flagged");
require(!pin_depends_on_reclaim(40 * GiB, 26 * GiB, 4 * GiB), "a complement the free pages cover was flagged");
require(pin_depends_on_reclaim(30 * GiB, 26 * GiB, 4 * GiB) == false, "exactly free = bytes + reserve is enough");
require(!pin_depends_on_reclaim(0, 0, 4 * GiB), "no complement, nothing to pin");
require(pin_step_fits(6 * GiB, 1 * GiB, 4 * GiB) && !pin_step_fits(4 * GiB, 1 * GiB, 4 * GiB),
"a step must leave the reserve");
const std::string info =
"MemTotal: 65011484 kB\nMemFree: 1284096 kB\nMemAvailable: 33463296 kB\nCached: 54507520 kB\n";
require(meminfo_bytes(info, "MemFree") == 1284096ull * 1024, "MemFree was misread");
require(meminfo_bytes(info, "MemAvailable") == 33463296ull * 1024, "MemAvailable was misread");
require(meminfo_bytes(info, "Mem") == 0 && meminfo_bytes(info, "Shmem") == 0, "an absent key was not 0");
}
void test_resident_memory_budget() {
using strata::core::detail::clamp_resident_budget;
constexpr uint64_t GiB = 1ull << 30, margin = 256ull << 20, headroom = 4 * GiB;
@@ -670,6 +688,7 @@ int main(int argc, char** argv) {
test_resident_lend_region();
test_resident_exchange();
test_resident_memory_budget();
test_pin_pacing();
test_cgroup_memory_budget();
test_host_memory();
test_canonical_layout();
+67
View File
@@ -0,0 +1,67 @@
"""docker-entrypoint.sh keeps the install config on the /data volume as the one that counts (#1244): with REINSTALL=0
and a config on the volume, /opt/strata/strata-<tag>.json is a link to it, even when a regular file is already there.
Runs the real script in a temporary tree with a stub for .venv/bin/python (POSIX sh and symlinks needed: skipped on
Windows).
python -m unittest tools.test_docker_entrypoint
"""
from __future__ import annotations
import os
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SH = shutil.which("sh")
@unittest.skipIf(os.name == "nt" or SH is None, "needs POSIX sh and symlinks")
class Entrypoint(unittest.TestCase):
def setUp(self):
self.tmp = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, self.tmp, ignore_errors=True)
self.opt = self.tmp / "opt"
self.data = self.tmp / "data"
(self.opt / ".venv" / "bin").mkdir(parents=True)
(self.data / "config").mkdir(parents=True)
# the stub "python": setup.py --setup writes the config the way setup does; a plain start prints what it would load
stub = self.opt / ".venv" / "bin" / "python"
stub.write_text('#!/bin/sh\nif [ "$2" = "--setup" ]; then echo \'{"args": ["from-setup"]}\' > strata-iq3_s.json\n'
'else echo "STARTED WITH: $(cat strata-iq3_s.json)"; fi\n', encoding="utf-8")
stub.chmod(0o755)
script = (ROOT / "docker-entrypoint.sh").read_text(encoding="utf-8").replace("/opt/strata", str(self.opt))
self.script = self.tmp / "entry.sh"
self.script.write_text(script, encoding="utf-8")
def run_entry(self, reinstall):
env = dict(os.environ, STRATA_DATA=str(self.data), MODEL="IQ3_S", REINSTALL=reinstall)
r = subprocess.run([SH, str(self.script)], env=env, capture_output=True, text=True, timeout=60)
self.assertEqual(r.returncode, 0, r.stderr)
return r.stdout
def test_edited_volume_config_wins_over_a_regular_file_in_opt(self):
(self.data / "config" / "strata-iq3_s.json").write_text('{"args": ["edited", "--kv-resident", "32768"]}\n')
(self.opt / "strata-iq3_s.json").write_text('{"args": ["stale"]}\n') # left by an earlier setup
out = self.run_entry("0")
self.assertIn("edited", out)
self.assertNotIn("stale", out)
self.assertTrue((self.opt / "strata-iq3_s.json").is_symlink())
def test_link_is_made_when_there_is_no_file(self):
(self.data / "config" / "strata-iq3_s.json").write_text('{"args": ["on-volume"]}\n')
self.assertIn("on-volume", self.run_entry("0"))
def test_first_setup_copies_the_config_to_the_volume_and_the_next_start_links_it(self):
out = self.run_entry("0") # no config on the volume: setup runs
self.assertIn("from-setup", out)
cfg = self.data / "config" / "strata-iq3_s.json"
self.assertIn("from-setup", cfg.read_text())
cfg.write_text('{"args": ["edited-later"]}\n')
self.assertIn("edited-later", self.run_entry("0")) # the regular file setup left is replaced by the link
if __name__ == "__main__":
unittest.main()
File diff suppressed because it is too large. Load diff
+166
View File
@@ -0,0 +1,166 @@
"""Tests for the per-family ROCm wheel choice of setup.py (#1103, #1267), against the version lists that AMD's TheRock
indexes really offered on 2026-10-07 (tools/test_setup_rocm_indexes.json), and for the sm_120 compiler warning that
now covers CUDA 13.2.0 / 13.2.1 only (#968). No network, no GPU.
python -m unittest tools.test_setup_rocm_pins
"""
from __future__ import annotations
import json
import sys
import unittest
from pathlib import Path
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
import setup # noqa: E402
LISTINGS = json.loads((ROOT / "tools" / "test_setup_rocm_indexes.json").read_text(encoding="utf-8"))["indexes"]
def page(family):
"""The index page's html as pip sees it, from the saved version list."""
return "<html><body>" + "".join(f'<a href="../rocm-{v}.tar.gz">rocm-{v}.tar.gz</a><br/>' for v in LISTINGS[family]) + "</body></html>"
class RocmPick(unittest.TestCase):
def setUp(self):
p = mock.patch.object(setup, "ROCM_VERSION_OVERRIDE", None)
p.start()
self.addCleanup(p.stop)
def want(self, arch):
index = setup.ROCM_INDEXES[arch]
return setup.rocm_wanted(index, page(setup.rocm_family(index)))
def test_every_family_gets_a_version_its_index_has(self):
for arch in setup.ROCM_INDEXES:
with self.subTest(arch=arch):
version, note = self.want(arch)
self.assertIn(version, LISTINGS[setup.rocm_family(setup.ROCM_INDEXES[arch])])
self.assertIsNone(note, note) # the shipped pins all exist: no warning
def test_gfx103X_has_no_7_10_but_gets_the_7_13_pin(self): # #1103
self.assertFalse([v for v in LISTINGS["gfx103X-all"] if v.startswith("7.10")])
self.assertEqual(self.want("gfx1030"), ("7.13.0a20260515", None))
self.assertEqual(self.want("gfx1031"), ("7.13.0a20260515", None))
def test_gfx120X_and_gfx110X_keep_the_tested_version(self):
for arch in ("gfx1201", "gfx1200", "gfx1100", "gfx1101", "gfx1102"):
self.assertEqual(self.want(arch), ("7.10.0a20251120", None))
def test_gfx1151_is_off_the_7_10_wheel(self): # #1267
version, note = self.want("gfx1151")
self.assertEqual((version, note), ("7.14.0a20260608", None))
self.assertGreaterEqual(setup.rocm_vkey(version)[:2], (7, 11))
def test_pinned_version_gone_falls_back_to_the_same_line_with_a_warning(self):
old = setup.ROCM_FAMILY_PINS["gfx103X-all"]
with mock.patch.dict(setup.ROCM_FAMILY_PINS, {"gfx103X-all": "7.13.0a20260301"}):
version, note = setup.rocm_wanted(setup.ROCM_INDEXES["gfx1030"], page("gfx103X-all"))
self.assertEqual(version, "7.13.0a20260515") # the newest of 7.13, not of 7.14
self.assertIn("7.13.0a20260301", note)
self.assertIn("same line", note)
self.assertEqual(old, "7.13.0a20260515")
def test_whole_line_gone_falls_back_to_the_same_major(self):
# gfx103X-all has no 7.10 line at all: the default 7.10.0a20251120 would land on the newest 7.x there
with mock.patch.dict(setup.ROCM_FAMILY_PINS, {"gfx103X-all": "7.10.0a20251120"}):
version, note = setup.rocm_wanted(setup.ROCM_INDEXES["gfx1030"], page("gfx103X-all"))
self.assertEqual(version, "7.14.0a20260612")
self.assertIn("same major", note)
def test_other_major_is_not_taken(self):
version, note = setup.rocm_pick(["6.5.0rc20250610"], "7.10.0a20251120")
self.assertEqual(version, "7.10.0a20251120")
self.assertIn("nothing of its major", note)
def test_unreadable_index_keeps_the_preferred_version(self):
self.assertEqual(setup.rocm_pick([], "7.10.0a20251120"), ("7.10.0a20251120", None))
with mock.patch.object(setup.urllib.request, "urlopen", side_effect=OSError("offline")):
self.assertEqual(setup.rocm_wanted(setup.ROCM_INDEXES["gfx1030"]), ("7.13.0a20260515", None))
def test_the_index_page_is_read_from_the_rocm_folder(self):
seen = []
class Resp:
def __enter__(self): return self
def __exit__(self, *a): return False
def read(self): return page("gfx103X-all").encode()
def fake(req, timeout=0):
seen.append(req.full_url)
return Resp()
with mock.patch.object(setup.urllib.request, "urlopen", fake):
self.assertEqual(setup.rocm_wanted(setup.ROCM_INDEXES["gfx1030"])[0], "7.13.0a20260515")
self.assertEqual(seen, ["https://rocm.nightlies.amd.com/v2/gfx103X-all/rocm/"])
def test_the_override_is_exact_and_not_looked_up(self):
with mock.patch.object(setup, "ROCM_VERSION_OVERRIDE", "7.12.0a20260311"), \
mock.patch.object(setup.urllib.request, "urlopen", side_effect=AssertionError("no lookup")):
self.assertEqual(setup.rocm_wanted(setup.ROCM_INDEXES["gfx1030"]), ("7.12.0a20260311", None))
with mock.patch.object(setup, "ROCM_VERSION_OVERRIDE", "7.10.0a20251120"): # forced, but still warned about
version, note = setup.rocm_wanted(setup.ROCM_INDEXES["gfx1151"])
self.assertEqual(version, "7.10.0a20251120")
self.assertIn("segfault", note)
def test_gfx1151_on_the_7_10_wheel_warns(self): # #1267 with an override or a fallback
version, note = None, None
with mock.patch.dict(setup.ROCM_FAMILY_PINS, {"gfx1151": "7.10.0a20251120"}):
version, note = setup.rocm_wanted(setup.ROCM_INDEXES["gfx1151"], page("gfx1151"))
self.assertEqual(version, "7.10.0a20251120")
self.assertIn("segfault", note)
def test_version_order(self):
v = setup.rocm_index_versions(page("gfx1151"))
self.assertEqual(v, sorted(v, key=setup.rocm_vkey))
self.assertEqual(v[-1], "7.14.0a20260612")
self.assertLess(setup.rocm_vkey("7.9.0rc20251008"), setup.rocm_vkey("7.10.0a20251009")) # 7.9 before 7.10
class Sm120Compiler(unittest.TestCase):
"""#968: only CUDA 13.2.0 / 13.2.1 (nvcc build 51) are warned about; 13.2.2 (build 86) is accepted."""
def run_sm120(self, build, archs=(120,), cuda_v=(13, 2), env=None):
with mock.patch.object(setup, "nvcc_build", return_value=build), \
mock.patch.object(setup, "find_nvcc", return_value=(None, None)), \
mock.patch.object(setup, "warn") as warn, mock.patch.object(setup, "ok"), \
mock.patch.dict(setup.os.environ, env or {}):
got = setup.sm120_nvcc("nvcc", cuda_v, list(archs))
return got, warn
def test_13_2_0_and_13_2_1_warn(self):
for build in (51, 78, None): # None: a build that cannot be read stays suspect
got, warn = self.run_sm120(build)
self.assertEqual(got, ("nvcc", (13, 2)))
warn.assert_called_once()
self.assertIn("13.2.0", warn.call_args[0][0])
def test_13_2_2_is_accepted_silently(self):
for build in (86, 90):
got, warn = self.run_sm120(build)
self.assertEqual(got, ("nvcc", (13, 2)))
warn.assert_not_called()
def test_13_2_2_keeps_the_newest_toolkit_not_an_older_one(self):
with mock.patch.object(setup, "nvcc_build", return_value=86), \
mock.patch.object(setup, "find_nvcc", side_effect=AssertionError("must not look for an older one")):
self.assertEqual(setup.sm120_nvcc("nvcc", (13, 2), [120]), ("nvcc", (13, 2)))
def test_not_sm120_or_not_13_2_is_untouched(self):
for archs, v in (((86,), (13, 2)), ((120,), (13, 0)), ((120,), (13, 3))):
got, warn = self.run_sm120(51, archs, v)
self.assertEqual(got, ("nvcc", v))
warn.assert_not_called()
def test_build_number_is_read_from_nvcc_output(self):
text = "nvcc: NVIDIA (R) Cuda compiler driver\nCuda compilation tools, release 13.2, V13.2.86\nBuild cuda_13.2.r13.2/compiler.123_0\n"
with mock.patch.object(setup, "out", return_value=text):
self.assertEqual(setup.nvcc_build("nvcc"), 86)
with mock.patch.object(setup, "out", return_value=""):
self.assertIsNone(setup.nvcc_build("nvcc"))
if __name__ == "__main__":
unittest.main()
+34 -4
View File
@@ -14,10 +14,40 @@ main() {
fi
echo "Getting the newest Strata (git pull) ..."
if ! git pull --ff-only; then
echo
echo "git pull did not succeed (the reason is above): nothing was updated. Files you changed here can stop it:"
echo "\"git status\" lists them."
exit 1
# The history of the repository was rewritten on 2026-10-06 (#1276): a clone made before that has no commit in
# common with origin/main, so a fast-forward can never work. Say so, and move it over when nothing is lost.
if [ "$(git rev-parse --is-shallow-repository 2>/dev/null)" != "true" ] && ! git merge-base HEAD origin/main >/dev/null 2>&1; then
echo
echo "This clone is on the repository's old history (cleaned up on 2026-10-06): it has no commit in common"
echo "with origin/main, so it cannot be updated by git pull."
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
echo "You have local changes to tracked files here, so nothing was touched. To move to the new history"
echo "yourself (your untracked files, models and settings stay where they are):"
echo " git branch pre-cleanup-backup && git stash push # keeps the old commits and your edits"
echo " git checkout -B main origin/main"
echo "then run ./update.sh again."
exit 1
fi
bk=pre-cleanup-backup
if git rev-parse --verify -q "refs/heads/$bk" >/dev/null 2>&1; then
bk="pre-cleanup-backup-$(date +%Y%m%d%H%M%S)"
fi
branch=$(git symbolic-ref --short -q HEAD || echo main)
if git branch "$bk" HEAD && git checkout -q -B "$branch" origin/main; then
echo "Moved to the new history. Your old commits are kept in the branch $bk."
echo "Untracked files (models, settings, the engine) were not touched."
else
echo "Could not move to the new history (the reason is above): nothing was updated. By hand:"
echo " git branch pre-cleanup-backup"
echo " git checkout -B main origin/main"
exit 1
fi
else
echo
echo "git pull did not succeed (the reason is above): nothing was updated. Files you changed here can stop it:"
echo "\"git status\" lists them."
exit 1
fi
fi
else
echo "This copy of Strata was not made with git, so it cannot fetch new files itself. Download the newest one:"