Files
lemonade/test/cpp/test_pip_download_parser.cpp
364d071133 Update to ROCm 7.14 (#2768)
* Update to ROCm 7.14

* Update therock download URL to tarball-multi-arch

Co-Authored-By: Claude <[email protected]>

* Update to stable diffusion 7.14 build

* Use upstream llama.cpp rocm 7.14 artifacts

* Install ROCm runtime via pip wheels, falling back to TheRock tarball

Prefer AMD's recommended pip-wheel install (rocm[libraries,device-gfxNNNN])
into a lemonade-managed venv, falling back to the TheRock tarball when
Python/venv/pip is unavailable, the arch has no device wheel, or any step
fails. The wheel builds differ from the tarball, which may resolve the
gfx1151 Windows batched-GEMM (hipErrorInvalidDeviceFunction) failure.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Force copy of HIP library to adjust for search order

* fix(sdcpp): put all TheRock runtime dirs on Windows PATH so sd-server resolves rocBLAS

(cherry picked from commit c6c9f0211c)

* fix(upscale): put all TheRock runtime dirs on Windows PATH so sd-cli resolves rocBLAS for ESRGAN

(cherry picked from commit 7099f036fc)

* Update sdcpp version

* Align llama.cpp version for rocm-stable

* fix(rocm-7.14): address code review feedback from PR #2768

- Route all loader-path sites through join_runtime_dirs(get_therock_lib_paths(...))
  so all wheel runtime dirs (HIP + BLAS) land on PATH/LD_LIBRARY_PATH
- Move LLVM dir discovery into get_therock_lib_paths; remove broken LLVM
  derivation from join_runtime_dirs
- Record install method in method.txt so rocm_install_method mismatch
  (e.g. user switches from wheel to tarball) triggers reinstall
- Track user cancellation during pip so it stops install rather than
  falling back to a ~2 GB tarball
- Add amdhip64_7.dll force-copy to llama-server and sd-cli upscale on
  Windows (system32 DLL shadowed was already mitigated in sd-server)
- Use cleanup_stale_version_dirs helper for wheel cleanup loop
- Remove dead duplicate rocm-stable branch in llamacpp_server.cpp
- Fix validate_llamacpp.yml report label (ggml-org -> lemonade-sdk)

* fix(rocm-7.14): address remaining code review issues

- Change force-copy error logging from WARNING to ERROR for roc-stable
- Download manager: parse pip wheel sizes for real progress bar, emit
  initial 0% event with human label before venv probe, emit progress
  event on 'Installing collected packages' phase
- Verify rocm_install_method in is_therock_installed_for_current_arch
  itself instead of duplicating the check in install_backend
- Clean up unused g_therock_install_method thread-local

* fix(rocm-7.14): fix MSVC build errors in TheRock code paths

MSVC rejects two constructs GCC/Clang accept:

- backend_utils.cpp captured g_therock_wheels_cancelled, a thread_local
  in an anonymous namespace, in the pip log_line lambda. Variables with
  static/thread storage duration cannot appear in a capture list; they
  are accessible directly. Dropping the capture also clears the cascading
  run_process_with_output overload-resolution errors caused by the
  ill-formed closure type.
- server.cpp declared therock_dirs inside the 'if (!rocm_arch.empty())'
  block but used it afterward for the amdhip64_7.dll copy. Hoist the
  declaration to the enclosing rocm-stable block and guard the .front()
  access against an empty vector.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(rocm-7.14): address second-round review (crash, tarball knob, workflow, mediums)

- Fix guaranteed divide-by-zero (SIGFPE) on the streamed wheel install: the
  pip size parser cut the token before the size parens and never matched pip's
  uppercase units, leaving bytes_total at 0. Rewrite as testable
  parse_pip_download_line() and guard the remaining division.
- Honour rocm_install_method=tarball in get_therock_lib_paths() and remove the
  non-selected tree on install so the ISV/OEM knob actually switches runtimes
  (also stops a per-load reinstall loop from a stale method.txt).
- validate_llamacpp.yml: validate/pin rocm-stable against ggml-org (where it is
  served) instead of the lemonade-sdk fork, stopping the weekly silent revert.
- Windows tarball LLVM dir lib->bin; drop dead join_runtime_dirs include_llvm
  param; decode UTF-8 cache paths (+ -X utf8 probe); pip --no-cache-dir; skip
  WindowsApps python stub; readable completed-row label.
- backend_versions.json: gfx908/gfx90a resolve verbatim (their gfx90X-dcgpu
  tarball 403s; verbatim returns 200, verified against repo.amd.com).
- Add unit tests for parse_pip_download_line() and is_concrete_gfx_arch().
- Docs: prefer rocm_bin=builtin over latest on the stable channel; drop the
  inaccurate "multiple ROCm versions concurrently" note.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Fix symlink match

* Fix library search dir from previous changes

* Revert back to lemonade-sdk/llama.cpp for rocm 7.14 builds

* fix(rocm-7.14): consolidate repeated comment explanations

Pre-commit hook flagged 4 concepts being explained at multiple sites:
- ROCm runtime install methods (5 sites) → consolidated to backend_utils.cpp
- Install method tracking (4 sites) → consolidated to backend_utils.cpp
- Prepending TheRock runtime dirs (3 sites) → kept compressed version in llamacpp_server.cpp
- Copying amdhip64_7.dll (3 sites) → kept compressed version in llamacpp_server.cpp

Co-Authored-By: Claude <[email protected]>

* fix(rocm-7.14): correct wheel install progress, cancel, and venv liveness

- Cancelled wheel download no longer reports "TheRock successfully
  installed": install_rocm_runtime throws on cancel so the caller rolls
  back instead of force-reporting completion.
- Per-wheel pip progress events are no longer flagged complete, so the
  download manager stops reporting the whole install done after the
  first of many wheels.
- Wheel venv liveness now checks the wheel's runtime_paths.txt directly
  instead of get_therock_lib_path(), which fell back to the tarball
  layout and reported the venv alive when only a tarball existed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Update ROCm version llamacpp

* fix(rocm-7.14): harden ROCm wheel install idempotency, paths, and markers

Address review findings in the ROCm wheel install path:
- Require runtime liveness (not just version markers) before the wheel
  install short-circuits, so a deleted venv or moved cache reinstalls
  instead of leaving a dead loader path that can't self-heal.
- Decode the UTF-8 runtime dir through path_from_utf8 before iterating so
  the HIP-runtime check works on non-ASCII Windows profile paths.
- Write version.txt last (after method.txt) in both the wheel and tarball
  paths so an interrupted install can't be mistaken for a completed one or
  silently defeat an explicit rocm_install_method preference.
- Use the cached backend_versions_config() in get_therock_lib_paths() and
  cleanup_old_therock_versions() instead of re-reading backend_versions.json
  from disk on every model load.
- Reorder the added <string> include to satisfy the alphabetical rule.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Harkirat Gill <[email protected]>
2026-08-18 16:36:16 +00:00

95 lines
3.5 KiB
C++

// Unit tests for lemon::backends::BackendUtils::parse_pip_download_line().
//
// The streamed ROCm wheel install parses pip's "Downloading <name> (<size>)"
// lines to drive a real progress bar. A parser that fails to extract the size
// leaves the running total at zero, which previously caused an unguarded
// divide-by-zero (SIGFPE) on the flagship install path. These tests pin the
// parser's behaviour against pip's actual output shape.
#include <cstddef>
#include <iostream>
#include <string>
#include <lemon/backends/backend_utils.h>
using lemon::backends::BackendUtils;
namespace {
int g_failures = 0;
void check(bool cond, const std::string& msg) {
if (cond) {
std::cout << "[ok] " << msg << std::endl;
} else {
std::cerr << "[FAIL] " << msg << std::endl;
++g_failures;
}
}
} // namespace
int main() {
std::string name;
std::size_t bytes = 0;
// Real pip output: uppercase MB unit, parens after the filename token.
{
const bool matched = BackendUtils::parse_pip_download_line(
"Downloading rocm_sdk_core-7.14.0-py3-none-manylinux_2_28_x86_64.whl (414.0 MB)",
name, bytes);
check(matched, "matches a real pip Downloading line");
check(name == "rocm_sdk_core-7.14.0-py3-none-manylinux_2_28_x86_64.whl",
"extracts the wheel basename");
check(bytes == static_cast<std::size_t>(414.0 * 1048576.0),
"parses uppercase MB size (regression: token cut before parens)");
}
// A URL-form filename: basename is taken after the last slash.
{
const bool matched = BackendUtils::parse_pip_download_line(
" Downloading https://repo.amd.com/rocm/whl/rocm_sdk_libraries-7.14.0.whl (1.2 GB)",
name, bytes);
check(matched, "matches a leading-whitespace / URL download line");
check(name == "rocm_sdk_libraries-7.14.0.whl", "strips URL path to basename");
check(bytes == static_cast<std::size_t>(1.2 * 1073741824.0), "parses GB size");
}
// kB unit.
{
BackendUtils::parse_pip_download_line("Downloading tiny-1.0.whl (12.5 kB)", name, bytes);
check(bytes == static_cast<std::size_t>(12.5 * 1024.0), "parses kB size");
}
// Download line with no size in parens: valid line, zero bytes (no crash).
{
const bool matched =
BackendUtils::parse_pip_download_line("Downloading nosize-1.0.whl", name, bytes);
check(matched, "matches a download line without a size");
check(bytes == 0, "reports zero bytes when the size is absent");
check(name == "nosize-1.0.whl", "still extracts the filename without a size");
}
// Non-download lines are rejected.
{
check(!BackendUtils::parse_pip_download_line("Installing collected packages: rocm", name, bytes),
"rejects a non-download line");
check(!BackendUtils::parse_pip_download_line("", name, bytes), "rejects an empty line");
}
// Malformed size does not throw and yields zero bytes.
{
const bool matched =
BackendUtils::parse_pip_download_line("Downloading weird-1.0.whl (garbage)", name, bytes);
check(matched, "matches even with a malformed size");
check(bytes == 0, "malformed size yields zero without throwing");
}
if (g_failures > 0) {
std::cerr << "Total failures: " << g_failures << std::endl;
return 1;
}
std::cout << "All pip download parser unit tests passed!" << std::endl;
return 0;
}