mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4165] [Engine] AVX CPU not working and a possible solution(includes custom patch) #1826
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#1826
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @FlowDownTheRiver on GitHub (Oct 25, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4165
Hi there. thanks for the project.
I am using intel I7 3930k processor with AVX instructions only,64 GB drr3 ram,paired with RTX 3090.
Just because I was having trouble with the pre-compiled strata engine and vision exe files and I was also getting errors with the official repo compling,I asked claude to give me a solution. and it gave me a working solution so that I am able to compile the strata.exe and strata_vision.exe files. However my Strata is pulling your latest repository with bat files and old GUI.(older way of using strata). So when I realized you have changed the repo to a new setup format,there is no way for me to compile the strata engine for the new user interface. I used my old setup and compiled the exe files with bat files and it is working on the old strata(cuda 12),however this new GUI is forcing to use cuda13 in this folder : C:\Users\my_user_name\AppData\Local\Strata\components\engine\0.1.50-windows-x86_64-cuda-cuda13. I tried to compile the exe on old strata and replace the exe files,it didn't work, I downloaded your cuda12 pack and manually put them in the app data folder it didn't work either because they are compiled with avx2 and also the new gui deleted the files and replaced them with cuda 13 again. So in short I don't have avx2 cpu to use the new GUI.
in my old setup to make it work I am using this to compile and update with bat files and a supplementary monkey patch python file to patch the cmake file which can compile the exe without any errors for the avx cpus :
python patch file as patch_strata.py :
#!/usr/bin/env python3
"""Re-apply local build fixes to a fresh Strata checkout. Safe to run any number of times.
Usage: python patch_strata.py [--restore] [path\to\Strata] (default: the folder this script sits in, else cwd)
(no flag) apply every patch below that is still needed
--restore undo them with "git checkout -- " so the next "git pull" cannot be blocked by local edits
Patch 1 - CMakeLists.txt, MSVC + CUDA 12.x link error (LNK2005 / LNK1169, "cudart_static.lib ... already defined in
cudart.lib"): upstream only links the shared CUDA runtime when STRATA_EXPERIMENTAL_SM60 is set. This makes
it apply to every MSVC build except the STRATA_PORTABLE release build.
Patch 2 - src/core/vmm.cpp, compile error C3861 "cudaGetDriverEntryPointByVersion: identifier not found" with
CUDA 12.4 (that function arrived in CUDA 12.5). Uses the same #if CUDART_VERSION guard that
src/core/expert_cache.cpp already has.
The AVX (no-AVX2) support itself is upstream (STRATA_ISA_FLOOR=avx), so it needs no patch.
"""
import re, subprocess, sys
from pathlib import Path
MARK = "STRATA-LOCAL-PATCH"
--------------------------------------------------------------------------------------------- patch 1: CMake
_CM_OLD = re.compile(r"if(MSVC AND STRATA_EXPERIMENTAL_SM60 AND NOT DEFINED CMAKE_CUDA_RUNTIME_LIBRARY)")
_CM_NEW = "if(MSVC AND NOT STRATA_PORTABLE AND NOT DEFINED CMAKE_CUDA_RUNTIME_LIBRARY) # " + MARK
_ENABLE = re.compile(r"^(?P[ \t])enable_language(CUDA)[ \t](?P\r?\n)", re.M)
def patch_cmake(txt):
"""returns (new_text or None, message)"""
if MARK in txt:
return None, "already patched"
if _CM_OLD.search(txt):
return _CM_OLD.sub(_CM_NEW, txt, count=1), "patched"
if re.search(r"if(MSVC[^\n]*CMAKE_CUDA_RUNTIME_LIBRARY", txt) and "Shared" in txt:
return None, "upstream already links the shared runtime for this build - nothing to do"
m = _ENABLE.search(txt)
if not m:
return None, "FAILED: neither the known block nor enable_language(CUDA) found - edit by hand"
i, nl = m.group("ind"), m.group("nl")
block = (f"{i}if(MSVC AND NOT STRATA_PORTABLE AND NOT DEFINED CMAKE_CUDA_RUNTIME_LIBRARY) # {MARK}{nl}"
f"{i} set(CMAKE_CUDA_RUNTIME_LIBRARY Shared){nl}{i}endif(){nl}")
return txt[:m.start()] + block + txt[m.start():], "patched (fallback insert)"
---------------------------------------------------------------------------------------------- patch 2: vmm
_VMM_OLD = re.compile(
r"(?P[ \t])if
cudaGetDriverEntryPointByVersion\(name, &p, 12000, cudaEnableDefault, &q!= cudaSuccess ||"r"\sq != cudaDriverEntryPointSuccess || p == nullptr)\s*return false;")
def patch_vmm(txt):
if MARK in txt:
return None, "already patched"
if "cudaGetDriverEntryPointByVersion" not in txt:
return None, "no cudaGetDriverEntryPointByVersion call any more - nothing to do"
if "CUDART_VERSION" in txt:
return None, "upstream already guards it with CUDART_VERSION - nothing to do"
m = _VMM_OLD.search(txt)
if not m:
return None, ("FAILED: cudaGetDriverEntryPointByVersion is used but the code changed shape - guard it by hand "
"like src/core/expert_cache.cpp does (#if CUDART_VERSION >= 12050 ... #else cudaGetDriverEntryPoint)")
nl = "\r\n" if "\r\n" in txt else "\n"
i = m.group("ind")
new = nl.join([
f"#if CUDART_VERSION >= 12050 // {MARK}: cudaGetDriverEntryPointByVersion needs CUDA 12.5+",
f"{i}const cudaError_t e = cudaGetDriverEntryPointByVersion(name, &p, 12000, cudaEnableDefault, &q);",
"#else",
f"{i}const cudaError_t e = cudaGetDriverEntryPoint(name, &p, cudaEnableDefault, &q);",
"#endif",
f"{i}if (e != cudaSuccess || q != cudaDriverEntryPointSuccess || p == nullptr) {{",
f"{i} (void) cudaGetLastError();",
f"{i} return false;",
f"{i}}}",
])
return txt[:m.start()] + new + txt[m.end():], "patched"
PATCHES = [("CMakeLists.txt", patch_cmake), ("src/core/vmm.cpp", patch_vmm)]
------------------------------------------------------------------------------------------------------ driver
def apply_all(root: Path) -> None:
for rel, fn in PATCHES:
f = root / rel
if not f.exists():
print(f"{rel}: not present - skipped")
continue
txt = f.read_bytes().decode("utf-8") # keeps BOM and CRLF exactly as they are
new, msg = fn(txt)
if new is not None:
f.write_bytes(new.encode("utf-8"))
print(f"{rel}: {msg}")
def restore_all(root: Path) -> None:
if not (root / ".git").exists():
print("not a git clone - nothing to restore")
return
for rel, _ in PATCHES:
r = subprocess.run(["git", "-C", str(root), "checkout", "--", rel], capture_output=True, text=True)
print(f"{rel}: {'restored to the repo version' if r.returncode == 0 else 'left alone (' + r.stderr.strip()[:80] + ')'}")
if name == "main":
args = [a for a in sys.argv[1:] if not a.startswith("--")]
here = Path(file).resolve().parent
root = Path(args[0]) if args else (here if (here / "CMakeLists.txt").exists() else Path.cwd())
if not (root / "CMakeLists.txt").exists():
sys.exit(f"no CMakeLists.txt in {root}")
(restore_all if "--restore" in sys.argv else apply_all)(root)
CMakeLists.txt
my custom update bat file as UPDATE_custom.bat(uses monkey patching with the python code provided) :
@echo off
rem Update Strata without starting the model (#475): the newest code (git pull, when this folder is a git clone), then
rem what START-HERE.bat does before a start - the engine (a new one when this version needs it), the Python packages,
rem each installed model's settings and draft subset. The model files are not touched. Start the model later with
rem START-HERE.bat. Options are passed on to setup.py.
setlocal
title Strata - update
cd /d "%~dp0"
rem All of it in one block: cmd reads a .bat file while it runs it, and the git pull can change this very file.
(
if exist ".git" (
where git >nul 2>nul || (
echo This folder is a git clone, but git is not on PATH: install Git for Windows ^(winget install Git.Git^)
echo or run "git pull" here yourself, then run UPDATE.bat again.
pause
exit /b 1
)
rem drop the local build patches first - otherwise git pull refuses when upstream changed a patched file
if exist "%~dp0patch_strata.py" (
where python >nul 2>nul
if errorlevel 1 (
py -3 "%~dp0patch_strata.py" --restore "%~dp0." >nul 2>nul
) else (
python "%~dp0patch_strata.py" --restore "%~dp0." >nul 2>nul
)
)
git checkout -- CMakeLists.txt >nul 2>nul
git checkout -- src/core/vmm.cpp >nul 2>nul
echo Getting the newest Strata ^(git pull^) ...
git pull --ff-only || (
echo.
echo git pull did not succeed ^(the reason is above^).
git rev-parse --abbrev-ref --symbolic-full-name @{u} >nul 2>nul || (
echo This branch has no upstream set - nothing was updated.
pause
exit /b 1
)
echo "Not possible to fast-forward" means upstream rewrote its history ^(a forced update^).
echo This copy can be reset to the newest upstream. Commits made only in this copy, and edits to tracked
echo files, would be lost ^(your patch and bat files are not tracked, so they stay^).
for /f %%h in ('git rev-parse --short HEAD') do echo Current commit is %%h - "git reset --hard %%h" brings it back.
choice /c YN /m " Reset this copy to the newest upstream now"
if errorlevel 2 (
echo Nothing was updated.
pause
exit /b 1
)
git reset --hard @{u} || (
echo The reset failed - nothing was updated.
pause
exit /b 1
)
)
) else (
echo This copy of Strata was not made with git, so it cannot fetch new files itself. Download the newest one:
echo https://github.com/Niko1221/Strata/archive/refs/heads/main.zip
echo unzip it anywhere and run START-HERE.bat ^(or UPDATE.bat^) in it: it finds the model files in Strata-data
echo and sets itself up the same way - nothing big is downloaded again.
echo Checking this copy's engine and settings meanwhile ...
)
if exist "%~dp0patch_strata.py" (
echo Applying local build patches ^(patch_strata.py^) ...
where python >nul 2>nul
if errorlevel 1 (
py -3 "%~dp0patch_strata.py" "%~dp0." || echo python not found - continuing without the patch
) else (
python "%~dp0patch_strata.py" "%~dp0."
)
)
call "%~dp0START-HERE.bat" --update %*
if not errorlevel 1 pause
exit /b
)
Anyway,with these I am able to use the old strata with bat files,but I want to use the new GUI of strata which needs to work with avx cpus. Can you please use these files or examine them to make the new GUI work with AVX cpu's with cuda 12 or cuda 13, whichever is suitable?
@coolguy744-creator commented on GitHub (Oct 26, 2026):
What a strange composition of parts you have.
What is this mobo that can run a 3090 and is stuck to ddr3?
@FlowDownTheRiver commented on GitHub (Oct 26, 2026):
Yeah got stuck with this system like forever. Asus p9x79 deluxe mainboard with 8 drr3 slots. It was very high end back in the day,but not having avx2 is killing me in every corner with projects like this. I had 32 gb ram but after using strata I went on a mission to find 64 gb ddr3 on second hand market and I was extremely lucky to find compatible parts. You can find ddr4-ddr5 easy but ddr3 are rare especially with 64 gb capacity. So I bought ram for strata now I can't run it with the new GUI :(
@coolguy744-creator commented on GitHub (Oct 27, 2026):
Interesting. Just wondering. Kinda want it lol.
On Mon, Oct 26, 2026, 8:43 AM FlowDownTheRiver @.***>
wrote:
@devstratum commented on GitHub (Oct 27, 2026):
Yes, I would also like support on Xeon E5-26XX V2 Series CPUs, which only have AVX
@fraseyboo commented on GitHub (Oct 27, 2026):
I just encountered this issue trying to run Strata 0.2.6 on my rig (Intel Xeon CPU E5-2697 v2, 128 GB DDR3, Nvidia P40 24 GB), it's an old setup but cost me less than £400 in total to build and has been running Ollama fine.
It's also kinda niche but the old 2013 Mac Pro (the trashcan one) uses similar architecture topping out with the E5-2667-V2, having support for AVX would let them be very cheap entries into the local LLM ecosystem.
Edit:
Building from source allowed me to use Strata 0.2.7 (
5e8a4cca7d690ac60ca37eb09e7d0e010099ad6d) with the Web UI over http, the new UI still eludes me. Looking at the model log my CPU was missing AVX2 with FMA and F16C.this CPU (Intel(R) Xeon(R) CPU E5-2697 v2 @ 2.70GHz) does not support AVX2 with FMA and F16C, which this engine's CPU expert kernels needI was able to build succesfully with the following CMake arguments:
And also made sure
GGML_NATIVE, GGML_AVX2, GGML_FMA, GGML_F16C, GGML_BMI2andGGML_AVX512were all off in the CMakeCache.txt.Additionally I needed to modify the CUDA 12.8 headers due to a declaration mismatch. The local toolkit's crt/math_functions.h needed
noexcept(true)on the six declarations ofrsqrt/rsqrtf, sinpi/sinpifandcospi/cospif. There's a useful Nvidia thread on the issue here.@devstratum commented on GitHub (Oct 28, 2026):
What kind of performance did you get?
It's difficult for me to compile it myself.
@fraseyboo commented on GitHub (Oct 28, 2026):
I haven't run the official benchmark yet given the workarounds, but I am getting around 18 tokens/second on Qwen3.8-flash-next-ud-q6_k_xl which is the 110 GB model, comparably it's around 40% the speed of my main rig (Nvidia RTX A6000, an Intel i9-10980XE, 128 GB DDR5). The GPU is not fully-utilised under load and seems to run much cooler than when I was using Ollama which suggests there's some bottlenecks in utilisation.
With MoE models most of the limitations in processing speed come from the model not being present in the VRAM and then needing retrieval from the system memory. A good chunk of the experts fit into the 24 GB of VRAM in the P40 with an average VRAM hit rate of 85% for the Qwen3.8-flash-next-ud-q6_k_xl model.
I believe the actual bottleneck in my setup is coming from the PCIe Gen 3 x16 connection to the P40, it's limited to around 12 GB/s which is substantially slower than the aggregate 50 GB/s I can get off the system memory. With the A6000 because it's PCIe Gen 4 x16 the transfer speed is doubled, and the extra VRAM helps reduce transfers.
So I guess my takeaway is that the PCIe connection is the limiting factor with builds like these, if you can't fit the model into VRAM (like with an MoE) then the speed of the rest of the system doesn't really matter.
@FlowDownTheRiver commented on GitHub (Oct 30, 2026):
Strata with my own AVX engine (no AVX2 CPU)
The official Strata app downloads an AVX2 / CUDA 13 engine. This setup compiles the engine on this PC
(AVX, CUDA 12.x) and installs it into the app as engine version
9.0.N, so the new desktop app and theTerminal run it instead of the official one.
How it works in one line: the engine is packaged with the repo's own
package_engine.py, signed with a localtest key, installed with
strata update --feed, and that test key is trusted permanently(
STRATA_UPDATE_TRUSTED_KEYS) so the app does not throw the engine away at the next start.Files (all live in
E:\Strata, the git clone of the official repo)UPDATE_custom.batbuild\andbuild-vision\.patch_strata.pyCMakeLists.txtafter everygit pull(and checkssrc/core/vmm.cpp).UPDATE_custom.batcalls it: first with--restore, then again after the pull. Keep your own copy.CMakeLists.txtpatch_strata.py. Do not edit it by hand:git checkout -- CMakeLists.txtrestores the original before each pull.INSTALL_MY_ENGINE.batpackaging\package_engine.py,packaging\make_local_feed.pygit pull). Used by step 2.custom-engine\stage\,pkg\,feed\,test-trust.json,version-counter.txt,update.log, andfeed-test-keys\(the private signing key: keep it private).Also needed: the Strata desktop app (installed once), the Strata Terminal (step 2 offers to install it),
Git, Python on PATH, Visual Studio 2022 with the C++ tools, and the CUDA 12.x toolkit (
CUDA_PATHset).First-time order
UPDATE_custom.bat,patch_strata.pyandINSTALL_MY_ENGINE.batinE:\Strata.UPDATE_custom.batand wait for the compile. Check thatbuild\strata.exeandbuild-vision\bin\strata-vision.exeexist. A linecould not compile the updated enginemeans it failed,even though the script still ends with "Strata is updated".
INSTALL_MY_ENGINE.bat. AnswerYwhen it offers to install the Terminal. It ends withDoneand the active engine9.0.N.9.0.N.Every later Strata update
Close the app, run
UPDATE_custom.bat, runINSTALL_MY_ENGINE.bat, start the app.Each run installs the next version (
9.0.N+1), so it always counts as newer than the official engines.No sign-out is needed again.
Rules
official AVX2 engine and deletes yours. Rerun
INSTALL_MY_ENGINE.batinstead.%LOCALAPPDATA%\Strata\components\engineby hand: every file is hash-checked.strata components rollbackreturns to the previous engine.INSTALL_MY_ENGINE.bat:ARCH(sm_86),VISION_ARCHS(86),MIN_DRIVER,VARIANT(avx, nevercuda12),CUDA_BIN.If something fails
CMAKE_CXX_COMPILER ... is not a full pathUPDATE_custom.batclears the stale cache itself; run it again.refusing to package the cuda12 engineavx.needs MSVCP140.dlland similarcustom-engine\update.log.echo %STRATA_UPDATE_TRUSTED_KEYS%must print the path ofcustom-engine\test-trust.json. If it does, sign out and in again; if not, rerunINSTALL_MY_ENGINE.bat.INSTALL_MY_ENGINE.bat.Strata_new_gui_with_avx_patch.zip
Note : e:\strata refers to where you have git cloned the repo. It works on my system with avx with the new GUI. If something gets stuck you can ask claude to troubleshoot. Hope it works for you as well guys.
Note 2 : You may need to use build-strata.bat and build-vision.bat files manually and if necessary by deleting the "build-vision" and/or "build" folders when/if needed.
@devstratum commented on GitHub (Oct 31, 2026):
Comrade, it's cool, we have to try!
@FlowDownTheRiver commented on GitHub (Nov 6, 2026):
@devstratum I have updated the patch.
@devstratum commented on GitHub (Nov 6, 2026):
@FlowDownTheRiver very good, thanks, maybe you should create a repo for these patches?