guix-epistemia

Personal Guix channel
Log | Files | Refs

commit 7efaf2cf4283929a3f9a3e7da21fd4decbc8e994
parent 1d018fa9ac67152e71e65daba2fc556a1de92695
Author: Vineet Kumar <git@vineetk.net>
Date:   Sat, 14 Nov 2026 16:43:35 +0100

packages/machine-learning: start working on porting strata-rdna3

Diffstat:
Mepistemia/packages/machine-learning.scm | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 141 insertions(+), 0 deletions(-)

diff --git a/epistemia/packages/machine-learning.scm b/epistemia/packages/machine-learning.scm @@ -1,5 +1,6 @@ (define-module (epistemia packages machine-learning) #:use-module (guix packages) + #:use-module (guix build-system cmake) #:use-module (guix build-system go) #:use-module (guix download) #:use-module (guix utils) @@ -150,3 +151,143 @@ rccl))) (properties `((amd-gpu-targets . ,%default-amd-gpu-targets))))) +(define-public strata-rdna3 + (let* ((commit "f557b544") + ;; strata is pinned to an older llama.cpp's ggml; + ;; using package-source llama-cpp-rocm instead has "incorrect number of function argument" errors + (llama-cpp-commit "3cf03257f219afbe7334045ff7c6a06ac68c627d") + (llama-cpp-source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/ggml-org/llama.cpp") + (commit llama-cpp-commit))) + (file-name (git-file-name "llama-cpp-strata" llama-cpp-commit)) + (sha256 + (base32 "10hr8pkszphsylrg3j055pb0s4v2qpaip6kp0x12005qmxfsh4a9"))))) + (package + (name "strata-rdna3") + (version (string-append "0.0.0-" commit)) ;; arbitrary, the project, or at least fork, doensn't do versioning + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/nicejunjie/strata-rdna3") + (commit commit) + (recursive? #t))) + (file-name (git-file-name name version)) + (sha256 + (base32 "15vr8prmmjx5ci7mw1p25z0pghp1x3nqgazfbd690a84668kfii1")) + ;; patches required for fixing compiler errors and incoherent inference and failed tests + (patches (list (plain-file "strata-rdna3-shared_expert.patch" "\ +diff --git a/src/kernels/cuda/iq_kernels.cu b/src/kernels/cuda/iq_kernels.cu +index c8f60b61..ec17bb20 100644 +--- a/src/kernels/cuda/iq_kernels.cu ++++ b/src/kernels/cuda/iq_kernels.cu +@@ -1776,8 +1776,10 @@ struct IqGridWords { + // with MSVC as host does not take it. Same layout either way. + #if defined(__HIPCC__) + #define STRATA_SHARED_ALIGN16_U32(name, ...) __shared__ uint32_t name[__VA_ARGS__] __attribute__((aligned(16))) ++#define STRATA_SHARED_ALIGN16_INT4(name, ...) __shared__ int4 name[__VA_ARGS__] __attribute__((aligned(16))) + #else + #define STRATA_SHARED_ALIGN16_U32(name, ...) __shared__ alignas(16) uint32_t name[__VA_ARGS__] ++#define STRATA_SHARED_ALIGN16_INT4(name, ...) __shared__ alignas(16) int4 name[__VA_ARGS__] + #endif + template<int TY, int NC, bool STAGE_GRID = kStageIqGrid<TY>, bool EXACT_N = false> + __global__ void __launch_bounds__(128) mmvq_multi_kernel(const uint8_t* __restrict__ w, size_t row_bytes, +@@ -2474,7 +2476,7 @@ __global__ void __launch_bounds__(256, MINB) expdec_gu_kernel(const unsigned lon + float* __restrict__ gate, float* __restrict__ up, int rb) { + const int ng = *n_groups; + if (blockIdx.y >= ng) return; +- __shared__ alignas(16) int4 s_u[ED_NC * 2 * ED_XB]; ++ STRATA_SHARED_ALIGN16_INT4(s_u, ED_NC * 2 * ED_XB); + __shared__ float s_ds[ED_NC * ED_XB]; + STRATA_SHARED_ALIGN16_U32(s_grid_buf, EdGrid<TG>::words); + const int tid = threadIdx.x; +@@ -2661,7 +2663,7 @@ __global__ void __launch_bounds__(256, STRATA_EXPDEC_MINB) expdec_down_kernel(co + if (blockIdx.y >= ng) return; + constexpr int LANES = TD == 20 ? 8 : 16; + constexpr int RPP = (256 / LANES) * R; // rows per pass +- __shared__ alignas(16) int4 s_u[ED_NC * 2 * ED_HB]; ++ STRATA_SHARED_ALIGN16_INT4(s_u, ED_NC * 2 * ED_HB); + __shared__ float s_ds[ED_NC * ED_HB]; + const int tid = threadIdx.x; + const int sw = tid / LANES, t = tid % LANES;") + (plain-file "strata-rdna3-alignas.patch" "\ +diff --git a/src/kernels/cuda/iq_kernels.cu b/src/kernels/cuda/iq_kernels.cu +index c8f60b61..ec17bb20 100644 +--- a/src/kernels/cuda/iq_kernels.cu ++++ b/src/kernels/cuda/iq_kernels.cu +@@ -1776,8 +1776,10 @@ struct IqGridWords { + // with MSVC as host does not take it. Same layout either way. + #if defined(__HIPCC__) + #define STRATA_SHARED_ALIGN16_U32(name, ...) __shared__ uint32_t name[__VA_ARGS__] __attribute__((aligned(16))) ++#define STRATA_SHARED_ALIGN16_INT4(name, ...) __shared__ int4 name[__VA_ARGS__] __attribute__((aligned(16))) + #else + #define STRATA_SHARED_ALIGN16_U32(name, ...) __shared__ alignas(16) uint32_t name[__VA_ARGS__] ++#define STRATA_SHARED_ALIGN16_INT4(name, ...) __shared__ alignas(16) int4 name[__VA_ARGS__] + #endif + template<int TY, int NC, bool STAGE_GRID = kStageIqGrid<TY>, bool EXACT_N = false> + __global__ void __launch_bounds__(128) mmvq_multi_kernel(const uint8_t* __restrict__ w, size_t row_bytes, +@@ -2474,7 +2476,7 @@ __global__ void __launch_bounds__(256, MINB) expdec_gu_kernel(const unsigned lon + float* __restrict__ gate, float* __restrict__ up, int rb) { + const int ng = *n_groups; + if (blockIdx.y >= ng) return; +- __shared__ alignas(16) int4 s_u[ED_NC * 2 * ED_XB]; ++ STRATA_SHARED_ALIGN16_INT4(s_u, ED_NC * 2 * ED_XB); + __shared__ float s_ds[ED_NC * ED_XB]; + STRATA_SHARED_ALIGN16_U32(s_grid_buf, EdGrid<TG>::words); + const int tid = threadIdx.x; +@@ -2661,7 +2663,7 @@ __global__ void __launch_bounds__(256, STRATA_EXPDEC_MINB) expdec_down_kernel(co + if (blockIdx.y >= ng) return; + constexpr int LANES = TD == 20 ? 8 : 16; + constexpr int RPP = (256 / LANES) * R; // rows per pass +- __shared__ alignas(16) int4 s_u[ED_NC * 2 * ED_HB]; ++ STRATA_SHARED_ALIGN16_INT4(s_u, ED_NC * 2 * ED_HB); + __shared__ float s_ds[ED_NC * ED_HB]; + const int tid = threadIdx.x; + const int sw = tid / LANES, t = tid % LANES;"))))) + (build-system cmake-build-system) + (arguments + (list #:tests? #f ;; failing tests require rocm-capable gpu, which I don't see a way to fix without changing guix-daemon chroot + #:configure-flags + #~(list "-DHIP_PLATFORM=amd" + "-DSTRATA_ENABLE_HIP=ON" + "-DSTRATA_PREFILL_MMQ=ON" + "-DSTRATA_MMQ_KQUANTS=ON" + "-DCMAKE_HIP_ARCHITECTURES=gfx1100" ;; this is a rdna3-focused fork + "-DSTRATA_BUILD_TESTS=ON" + (string-append "-DSTRATA_GGML_DIR=" #$llama-cpp-source) ;; there isn't a submodule + (string-append "-DCMAKE_HIP_COMPILER_ROCM_ROOT=" #$rocm-hip-runtime) + (string-append "-DCMAKE_HIP_FLAGS=--rocm-path=" #$rocm-hip-runtime + " --rocm-device-lib-path=" #$rocm-device-libs "/amdgcn/bitcode")) + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'fix-hip-shared-alignas + (lambda _ + ;; ROCm 7.1's clang rejects `__shared__ alignas(16)` here. + (substitute* "src/kernels/cuda/iq_kernels.cu" + (("__shared__ alignas\\(16\\) int4 s_u\\[ED_NC \\* 2 \\* ED_XB\\];") + "__shared__ int4 s_u[ED_NC * 2 * ED_XB] __attribute__((aligned(16)));") + (("__shared__ alignas\\(16\\) int4 s_u\\[ED_NC \\* 2 \\* ED_HB\\];") + "__shared__ int4 s_u[ED_NC * 2 * ED_HB] __attribute__((aligned(16)));")))) + (add-after 'install 'actually-install-bin + (lambda _))))) + (inputs + (list clang-22 ;; clang 23 needs rocm newer than 7.1.1 + lld-rocm + rocm-cmake + rocm-device-libs + rocm-hipcc + rocm-hip-runtime + rocr-runtime + hipblas + hipblas-common + hipblaslt + rocblas + rccl)) + (properties '((tunable? . #t))) + (home-page "https://github.com/nicejunjie/strata-rdna3") + (synopsis "") + (description "") + (license license:expat))))