Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
Nix CI: split native extension from pure engine wheel
YanissAmz38bdd09c51ae
diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.ymlindex 9f890fb..762bd4d 100644--- a/.github/workflows/nix.yml+++ b/.github/workflows/nix.yml@@ -24,9 +24,11 @@ jobs:- name: Nix cacheuses: DeterminateSystems/magic-nix-cache-action@v15- # Full evaluation + pre-commit hooks + CPU test subset. Deliberately- # does NOT build packages.exllamav3 (8-10 min ROCm ext compile, ~9 GB- # SDK closure): engine builds stay local, see doc/nix.md.+ # Full evaluation + pre-commit hooks + CPU test subset. The engine+ # wheel builds pure-python here (EXLLAMA_NOCOMPILE, seconds); the+ # ROCm extension .so is reused from the cache and recompiles only+ # when native sources change (setup.py, exllamav3_ext/, arch_list):+ # PRs without native changes finish in minutes, see doc/nix.md.- name: nix flake checkrun: nix flake check --print-build-logsdiff --git a/doc/nix.md b/doc/nix.mdindex 5772cec..11c6914 100644--- a/doc/nix.md+++ b/doc/nix.md@@ -32,7 +32,8 @@ metadata builds (`uv lock --check`, PEP 517 `get_requires`) keep working.## Building```bash-nix build .#exllamav3 # engine wheel + gfx1151 extension, 8-10 min+nix build .#exllamav3 # engine wheel + gfx1151 extension+nix build .#exllama-ext # native extension alone (narrowed sources)nix build .#kyojin # serve wrappers (qwen/glm/mimo)nix build .#torch-rocm # ROCm torch wheelnix build .#rocm-sdk # expanded SDK tree (headers, hipcc, libhsa)@@ -40,9 +41,23 @@ nix build .#docker # OCI image tarball, about 5 GB compressednix run .#kyojin-serve-glm -- --help```-`nix flake check` runs the hook suite plus the CPU test subset-(`checks.kyojin-tests`, GPUs hidden, bounded runtime). `nix fmt` doubles as-the clean-tree gate: it exits non-zero when a hook fails or rewrites files.+The engine package is split for CI caching: `.#exllama-ext` compiles the+native extension from narrowed sources only (`setup.py`,+`exllamav3/exllamav3_ext/`, `util/arch_list.py`, plus packaging metadata),+while `.#exllamav3` builds the pure-python wheel (`EXLLAMA_NOCOMPILE`,+seconds) with the cached `.so` injected into site-packages — same module,+same top-level import path, so `exllamav3.ext` finds it via+`is_precompiled_extension_available()` exactly as before. `nix flake check`+(hook suite + CPU test subset, `checks.kyojin-tests`, GPUs hidden, bounded+runtime) therefore never compiles the extension unless native sources+changed: python/docs/tests PRs reuse the cached `.so` through+magic-nix-cache and finish in minutes, while native changes still rebuild+and test it. The serve wrappers, the venv, and the container all consume+the same package, so nothing drifts. First build compiles the extension+once (8-10 min); afterwards only native changes pay that again.++`nix fmt` doubles as the clean-tree gate: it exits non-zero when a hook+fails or rewrites files.## ROCm pinsdiff --git a/flake.nix b/flake.nixindex 5eefe2a..a215bc5 100644--- a/flake.nix+++ b/flake.nix@@ -66,6 +66,27 @@"-Xclang -internal-isystem -Xclang ${pkgs.stdenv.cc.libc.dev}/include"];+ # Narrowed source for the native extension compile: the only+ # repo files setup.py + torch's cpp_extension read (verified:+ # no #include escapes exllamav3_ext/, setup.py loads+ # build_config.py and util/arch_list.py by file path, the+ # version comes from an AST read of version.py, and README.md+ # feeds the wheel metadata). Python/docs/tests changes leave+ # this store path untouched, so the cached .so below survives+ # them (magic-nix-cache) instead of recompiling (~11 min).+ exllamaNativeSrc = lib.fileset.toSource {+ root = ./.;+ fileset = lib.fileset.unions [+ ./setup.py+ ./pyproject.toml+ ./README.md+ ./exllamav3/__init__.py+ ./exllamav3/version.py+ ./exllamav3/util/arch_list.py+ ./exllamav3/exllamav3_ext+ ];+ };+# 1. Load workspace (pyproject.toml + uv.lock at eval time)workspace = inputs.uv2nix.lib.workspace.loadWorkspace {workspaceRoot = ./.;@@ -192,6 +213,55 @@withCudaPatch = old: (ignoreCuda old) // (cudaSearchHook old);# hipSysIncludes lives at perSystem scope (shared with the# runtime JIT wrappers below); referenced as ${hipSysIncludes}.+ # Engine extension compile env, shared by the cached native+ # build (exllamav3-ext) and the pure wheel (exllamav3):+ # setup.py imports torch (cpp_extension) and compiles HIP+ # sources with the SDK toolchain. torch comes from+ # buildInputs (importable via PYTHONPATH in the pep517+ # build); providers must be importable too (torch's+ # _rocm_init preloads through them at import time).+ exllamaExtBuildInputs =+ old:+ (old.buildInputs or [ ])+ ++ [+ final.torch+ rocmSdk+ # torch's own top-level imports (needed to import torch+ # during setup.py's cpp_extension build).+ final.filelock+ final."typing-extensions"+ final.sympy+ final.networkx+ final.jinja2+ final.fsspec+ ];+ exllamaExtPreBuild = ''+ export HOME="$TMPDIR"+ echo "ENVDBG CPATH=$CPATH CPLUS=$CPLUS_INCLUDE_PATH CINC=$C_INCLUDE_PATH" >&2+ echo "ENVDBG NIX_CFLAGS=$NIX_CFLAGS_COMPILE" >&2+ # NOTE: export ROCM_HOME only (torch reads it for -I).+ # ROCM_PATH/HIP_PATH are deliberately UNSET: hipcc+ # self-locates its version + data files correctly without+ # them, but misdetects (HIP 3.5.0) when they point at a+ # tree whose share/hip/version it can't resolve.+ export ROCM_HOME="${rocmSdk}"+ unset ROCM_PATH HIP_PATH+ export HIP_DEVICE_LIB_PATH="${rocmSdk}/lib/llvm/amdgcn/bitcode"+ export PYTORCH_ROCM_ARCH="gfx1151"+ export EXL3_HIP_DEFINES="EXL3_HIP_STG_PAD"+ export PYTHONPATH="${rocmProviders}/lib/python3.12/site-packages:$PYTHONPATH"+ export LD_LIBRARY_PATH="${+ lib.makeLibraryPath [+ pkgs.gcc.cc.lib+ rocmSdk+ rocmLibs+ ]+ }:$LD_LIBRARY_PATH"+ # SDK clang runs outside the cc wrapper: system headers for+ # host and device passes alike (plus NIX_CFLAGS_COMPILE's+ # python/SDK includes).+ export HIPCC_COMPILE_FLAGS_APPEND="${hipSysIncludes} $NIX_CFLAGS_COMPILE -v"+ '';inlib.genAttrs nvidiaSibs (n:@@ -276,53 +346,44 @@'';});- # Engine extension build: setup.py imports torch (cpp_extension)- # and compiles HIP sources with the SDK toolchain. torch comes- # from buildInputs (importable via PYTHONPATH in the pep517- # build); providers must be importable too (torch's _rocm_init- # preloads through them at import time).- exllamav3 = prev.exllamav3.overrideAttrs (old: {- buildInputs = (old.buildInputs or [ ]) ++ [- final.torch+ # Native extension, compiled ONLY from the narrowed native+ # sources (exllamaNativeSrc above). Its store path (and the+ # magic-nix-cache entry) is untouched by python/docs/tests+ # changes, so CI reuses the .so instead of recompiling.+ "exllamav3-ext" = prev.exllamav3.overrideAttrs (old: {+ src = exllamaNativeSrc;+ buildInputs = exllamaExtBuildInputs old;+ nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [rocmSdk- # torch's own top-level imports (needed to import torch- # during setup.py's cpp_extension build).- final.filelock- final."typing-extensions"- final.sympy- final.networkx- final.jinja2- final.fsspec];+ preBuild = exllamaExtPreBuild;+ });+ # Engine wheel: pure-python build (EXLLAMA_NOCOMPILE, seconds+ # even on a full-src rebuild) plus the cached .so injected+ # into site-packages, so ext.py finds the precompiled+ # extension at the same top-level import path as before.+ exllamav3 = prev.exllamav3.overrideAttrs (old: {+ buildInputs = exllamaExtBuildInputs old;nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [rocmSdk];- preBuild = ''- export HOME="$TMPDIR"- echo "ENVDBG CPATH=$CPATH CPLUS=$CPLUS_INCLUDE_PATH CINC=$C_INCLUDE_PATH" >&2- echo "ENVDBG NIX_CFLAGS=$NIX_CFLAGS_COMPILE" >&2- # NOTE: export ROCM_HOME only (torch reads it for -I).- # ROCM_PATH/HIP_PATH are deliberately UNSET: hipcc- # self-locates its version + data files correctly without- # them, but misdetects (HIP 3.5.0) when they point at a- # tree whose share/hip/version it can't resolve.- export ROCM_HOME="${rocmSdk}"- unset ROCM_PATH HIP_PATH- export HIP_DEVICE_LIB_PATH="${rocmSdk}/lib/llvm/amdgcn/bitcode"- export PYTORCH_ROCM_ARCH="gfx1151"- export EXL3_HIP_DEFINES="EXL3_HIP_STG_PAD"- export PYTHONPATH="${rocmProviders}/lib/python3.12/site-packages:$PYTHONPATH"- export LD_LIBRARY_PATH="${- lib.makeLibraryPath [- pkgs.gcc.cc.lib- rocmSdk- rocmLibs- ]- }:$LD_LIBRARY_PATH"- # SDK clang runs outside the cc wrapper: system headers for- # host and device passes alike (plus NIX_CFLAGS_COMPILE's- # python/SDK includes).- export HIPCC_COMPILE_FLAGS_APPEND="${hipSysIncludes} $NIX_CFLAGS_COMPILE -v"+ preBuild = exllamaExtPreBuild + ''+ # Pure wheel only: the native compile is skipped here;+ # the .so comes from exllamav3-ext (postInstall below).+ export EXLLAMA_NOCOMPILE=1+ '';+ postInstall = (old.postInstall or "") + ''+ extSo=${final."exllamav3-ext"}/lib/python3.12/site-packages+ copied=0+ for f in "$extSo"/exllamav3_ext*.so; do+ [ -e "$f" ] || continue+ cp "$f" $out/lib/python3.12/site-packages/+ copied=1+ done+ if [ "$copied" -eq 0 ]; then+ echo "exllamav3: FATAL: no exllamav3_ext*.so in exllamav3-ext output ($extSo)" >&2+ exit 1+ fi'';});};@@ -848,6 +909,9 @@rocm-libs = rocmLibs;rocm-providers = rocmProviders;inherit (pythonSet) exllamav3;+ # Native extension alone (narrowed sources, cached across+ # python-only changes); the .so is injected into .#exllamav3.+ exllama-ext = pythonSet."exllamav3-ext";hip-sysroot = hipSysroot;kyojin = kyojinServe;docker = kyojinImage;