guix-epistemia

Personal Guix channel
Log | Files | Refs

commit 3e022392b5aa28674e7d99e9ba75e9d7957fffd1
parent 7efaf2cf4283929a3f9a3e7da21fd4decbc8e994
Author: Vineet Kumar <git@vineetk.net>
Date:   Sat, 14 Nov 2026 17:20:59 +0100

packages/machine-learning: fix installation of strata-rdna3

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

diff --git a/epistemia/packages/machine-learning.scm b/epistemia/packages/machine-learning.scm @@ -8,13 +8,18 @@ #:use-module (guix gexp) #:use-module ((guix licenses) #:prefix license:) #:use-module (gnu packages base) + #:use-module (gnu packages bash) #:use-module (gnu packages golang-check) #:use-module (gnu packages golang-web) #:use-module (gnu packages golang-xyz) #:use-module (gnu packages llvm) #:use-module (gnu packages machine-learning) #:use-module (gnu packages rocm) - #:use-module (gnu packages rocm-libs)) + #:use-module (gnu packages rocm-libs) + #:use-module (gnu packages python) + #:use-module (gnu packages python-crypto) + #:use-module (gnu packages python-web) + #:use-module (gnu packages python-xyz)) (define-public python-pytorch-rocm (package/inherit python-pytorch-avx @@ -180,39 +185,21 @@ (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;") +diff --git a/src/kernels/cuda/shared_expert.cu b/src/kernels/cuda/shared_expert.cu +index f8b58963..dee881af 100644 +--- a/src/kernels/cuda/shared_expert.cu ++++ b/src/kernels/cuda/shared_expert.cu +@@ -421,8 +421,8 @@ void shared_expert(const uint8_t* x_q8_0, const uint8_t* x_q8k, const uint16_t* + // gate and up projections, then silu(gate) * up in place in `gate` + // [claude] native->x_q8_1: the caller's q8_1 image of x (STRATA_MTP_QFUSE: the hyper-connection read wrote it, the same bytes + // native_quantize_q8_1 writes) - read as is; the quantize launch is skipped +- const void* x_q8 = native->x_q8_1 != nullptr ? native->x_q8_1 : native->q8_1; +- if ((native_gate || native_up) && native->x_q8_1 == nullptr) ++ const void* x_q8 = native == nullptr ? nullptr : (native->x_q8_1 != nullptr ? native->x_q8_1 : native->q8_1); ++ if ((native_gate || native_up) && native != nullptr && native->x_q8_1 == nullptr) + native_quantize_q8_1(x_f32, native->q8_1, (int) n_embd, 1, stream); + if (native_gate) + native_mmvq(native->gate_type, native->gate_data, x_q8, gate, (int) n_embd, (int) n_ff, 1, stream);") (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 @@ -263,16 +250,62 @@ index c8f60b61..ec17bb20 100644 " --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 _))))) + ;; strata doesn't do any installation, so it needs to be done manually + ;; below is llm'd a bit (dsv4.1-flash-1017 with pi) with clean-up; too tedious otherwise + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (build (getcwd)) + (source (string-append (dirname build) "/source")) + (share (string-append out "/usr/share/strata")) + (libexec (string-append out "/libexec/strata")) + (python (assoc-ref inputs "python")) + (bash (assoc-ref inputs "bash-minimal")) + (python-dir (car (scandir + (string-append python "/lib") + (lambda (name) + (string-prefix? "python3." name))))) + (site-packages + (lambda (input) + (string-append (assoc-ref inputs input) + "/lib/" python-dir "/site-packages"))) + (pythonpath + (string-join + (map site-packages + '("python-numpy" "python-jinja2" "python-regex" + "python-pyyaml" "python-tqdm" "python-requests" + "python-pillow" "python-psutil" "python-markupsafe" + "python-certifi" "python-truststore" + "python-charset-normalizer" "python-idna" + "python-urllib3")) + ":"))) + ;; copy engine + (install-file (string-append build "/strata") + (string-append out "/lib/strata/engine")) + ;; copy python tree + (for-each (lambda (dir) + (copy-recursively + (string-append source "/" dir) + (string-append share "/" dir))) + '("serve" "tools" "data" "include" "src" "third_party" + "strata_control" "strata_cli")) + ;; create python wrapper that sets PYTHONPATH + (mkdir-p libexec) + (symlink (string-append python "/bin/python3") + (string-append libexec "/python3")) + (wrap-program (string-append libexec "/python3") + #:sh (string-append bash "/bin/bash") + `("GUIX_PYTHONPATH" ":" prefix (,pythonpath)) + `("PYTHONPATH" ":" prefix (,share))) + ;; use wrapped python to run the api server + (mkdir-p (string-append out "/bin")) + (let ((server (string-append out "/bin/strata-server"))) + (call-with-output-file server + (lambda (port) + (format port + "#!~a/python3~%from serve.server import main~%raise SystemExit(main())~%" + libexec))) + (chmod server #o555)))))))) (inputs (list clang-22 ;; clang 23 needs rocm newer than 7.1.1 lld-rocm @@ -285,7 +318,23 @@ index c8f60b61..ec17bb20 100644 hipblas-common hipblaslt rocblas - rccl)) + rccl + bash-minimal + python + python-numpy + python-jinja2 + python-regex + python-pyyaml + python-tqdm + python-requests + python-pillow + python-psutil + python-markupsafe + python-certifi + python-truststore + python-charset-normalizer + python-idna + python-urllib3)) (properties '((tunable? . #t))) (home-page "https://github.com/nicejunjie/strata-rdna3") (synopsis "")