diff --git a/docs/platform_strategy.md b/docs/platform_strategy.md index ea5540a..87bb873 100644 --- a/docs/platform_strategy.md +++ b/docs/platform_strategy.md @@ -52,12 +52,12 @@ reaches LiteRT: | 0 | Not established. Builds before v0.19 report 0; their Linux and Windows runtimes for v0.16 to v0.18 load upstream's prebuilt `libLiteRt` (#111). | | missing | The runtime predates the marker; treat it as 0. | -The marker covers only the LiteRT-LM to LiteRT weight handoff. It is not GPU -qualification: the `gpu_registry.cc` fallback to the prebuilt accelerator still -resolves LiteRT symbols from the host, which is the -[#47](https://github.com/leehack/litert-lm-native/issues/47) crash class. On -Linux, a consumer that preloads a separate `libLiteRt` with `RTLD_GLOBAL` -recreates the #111 state while the marker still reads 1. +The marker covers the LiteRT-LM to LiteRT weight handoff. On earlier bundles with +a prebuilt accelerator, the `gpu_registry.cc` fallback can resolve LiteRT symbols +from the host, which is the +[#47](https://github.com/leehack/litert-lm-native/issues/47) crash class. On Linux, +preloading an external `libLiteRt` with `RTLD_GLOBAL` can recreate the #111 state +while the marker still reads 1. Every source build from LiteRT-LM v0.19 reports 1 on every platform. The export is additive and carries no other ABI change. It is a bridge export @@ -208,12 +208,19 @@ the weights and Windows crashed, which broke every bundle with external-weight sections, such as EmbeddingGemma-2. The build fails if a v0.19+ host on any platform still imports `libLiteRt`, and those hosts report `litert_lm_native_in_process_litert_abi_version()` 1, so consumers can refuse -external-weight bundles on older desktop runtimes. Bundles keep shipping the -upstream `libLiteRt` and `libLiteRtWebGpuAccelerator` files on Linux, Windows -and Android, but the host loads neither. Apple bundles after `v0.19.1-3` omit -the macOS `libLiteRt` and `libLiteRtWebGpuAccelerator` and the iOS loose -`libLiteRt` (`has_prebuilt_apple_litert_companions`), and so publish no -`LiteRt` or `LiteRtWebGpuAccelerator` XCFramework. +external-weight bundles on older desktop runtimes. Linux and Windows v0.19 +bundles included upstream `libLiteRt` and `libLiteRtWebGpuAccelerator` files. +Apple bundles omit those companions after `v0.19.1-3`. LiteRT-LM v0.20.0 +removed the prebuilts upstream. The package validator rejects either separate +library in a v0.20+ desktop bundle. The source-built accelerator uses the +packaged Dawn library. + +For desktop GPU qualification, record the archive SHA-256, SHA-256 of every +file in the loaded runtime directory, model SHA-256, selected GPU backend, and +driver version alongside the candidate and comparison run logs. The +[v0.19.1-2 L4 receipt](https://github.com/leehack/llamadart/pull/1830#issuecomment-6731113939) +binds the Linux Vulkan and Windows D3D12 results to that release's bundle and +loaded runtime digests. The rest of this section covers v0.16 to v0.18. diff --git a/tools/test_validate_runtime_dependencies.py b/tools/test_validate_runtime_dependencies.py new file mode 100644 index 0000000..24fd923 --- /dev/null +++ b/tools/test_validate_runtime_dependencies.py @@ -0,0 +1,42 @@ +from pathlib import Path +import sys +import tempfile +import unittest +from unittest.mock import patch + +import validate_runtime_dependencies as validate + + +class DesktopLiteRtBundleTest(unittest.TestCase): + def test_current_cli_rejects_separate_desktop_litert_and_accelerator(self) -> None: + cases = ( + "linux/x64/libLiteRt.so", + "linux/arm64/libLiteRtWebGpuAccelerator.so", + "macos/arm64/libLiteRtWebGpuAccelerator.dylib", + "windows/x64/libLiteRt.dll", + ) + for library in cases: + with self.subTest(library=library), tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "bin" / library + path.parent.mkdir(parents=True) + path.touch() + with patch.object(sys, "argv", [ + "validate_runtime_dependencies.py", "--root", directory, + "--upstream-tag", "v0.20.0", + ]), self.assertRaises(SystemExit) as failure: + validate.main() + self.assertIn(f"bin/{library}", str(failure.exception)) + + def test_accepts_legacy_companions_and_current_runtime_dependencies(self) -> None: + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + runtime = root / "bin/linux/x64" + runtime.mkdir(parents=True) + companion = runtime / "libLiteRt.so" + companion.touch() + validate.validate_desktop_litert_bundle(root, "v0.19.1") + companion.unlink() + for name in ("libLiteRtLm.so", "libwebgpu_dawn.so", + "libGemmaModelConstraintProvider.so"): + (runtime / name).touch() + validate.validate_desktop_litert_bundle(root, "v0.20.0") diff --git a/tools/validate_runtime_dependencies.py b/tools/validate_runtime_dependencies.py index 9724bad..253dc1b 100644 --- a/tools/validate_runtime_dependencies.py +++ b/tools/validate_runtime_dependencies.py @@ -44,6 +44,24 @@ def fail(message: str) -> None: raise SystemExit(message) +def validate_desktop_litert_bundle(root: Path, upstream_tag: str) -> None: + if not is_at_least(upstream_tag, (0, 20, 0)): + return + companions = re.compile( + r"(?:lib)?litert(?:webgpuaccelerator)?\.(?:so(?:\.\d+)*|dylib|dll)", + re.IGNORECASE, + ) + found = sorted( + path.relative_to(root).as_posix() + for platform in ("linux", "macos", "windows") + for path in (root / "bin" / platform).glob("*/*") + if companions.fullmatch(path.name) and (path.is_file() or path.is_symlink()) + ) + if found: + fail("v0.20+ desktop runtimes must not bundle separate LiteRT or WebGPU " + "accelerator libraries:\n" + "\n".join(f"- {path}" for path in found)) + + def iter_elf_libraries(root: Path) -> list[Path]: bin_dir = root / "bin" if not bin_dir.exists(): @@ -358,6 +376,7 @@ def main() -> int: args = parser.parse_args() root = args.root.resolve() + validate_desktop_litert_bundle(root, args.upstream_tag) if provider_free_ios(args.upstream_tag): validate_ios_directory(root / "bin" / "ios") validate_ios_archives(args.archive_root or root / "dist" / "spm")