mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1523] [CLOSED] [Engine] LoRA adapter support with per-request on/off switch #3507
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#3507
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?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1523
Author: @agrogov
Created: 10/8/2026
Status: ❌ Closed
Base:
main← Head:feat/lora-adapter-pr📝 Commits (10+)
1d4743akernels: LoRA adapter kernels for the mixer output projections2a6d701core: apply the LoRA adapter in decode, verify and the prompt path80625ebconversation: key cached and saved state by the LoRA switch1df9ce9generate: --lora / --lora-scaled and the per-request lora=0|1 keybae032dserve: "lora": true|false in the request bodyb9099daperf(lora): overlap the up kernel with the down kernel (PDL)3385e61Merge branch 'main' into feat/lora-adapter-prf271f74Merge branch 'main' into feat/lora-adapter-pr51d3ca8Merge tag 'v0.1.45' into feat/lora-adapter-pr9ebbf70generate.cpp: close load_lora_adapters (the brace was lost in an earlier merge)📊 Changes
15 files changed (+989 additions, -30 deletions)
View changed files
📝
CMakeLists.txt(+6 -0)📝
include/strata/core/conversation_cache.hpp(+8 -5)📝
include/strata/core/conversation_file.hpp(+2 -0)📝
include/strata/core/conversation_snapshot.hpp(+1 -0)➕
include/strata/kernels/lora.hpp(+77 -0)📝
serve/server.py(+16 -4)📝
serve/test_server.py(+6 -0)📝
src/core/conversation_file.cpp(+5 -3)📝
src/core/conversation_state.cpp(+3 -3)📝
src/core/layer.cpp(+10 -2)📝
src/core/verify.cpp(+3 -0)➕
src/kernels/cuda/lora.cu(+421 -0)➕
src/kernels/lora_parity.cpp(+237 -0)📝
src/prefill/prefill.cpp(+3 -0)📝
src/program/generate.cpp(+191 -13)📄 Description
Problem and result
Strata cannot apply a LoRA adapter, so a fine-tuned variant of the model needs a merged GGUF. This adds optional LoRA support in the CUDA engine (llama.cpp's adapter GGUF format) with a per-request on/off switch.
--lora FILE/--lora-scaled FILE:SCALE[,...]load a llama.cpp LoRA GGUF (general.type = adapter,adapter.type = lora; f32/f16/bf16). It is applied to the mixer output projections:ssm_outon GDN layers andattn_outputon QSA layers. For each adapted layer,y += s·B(A·x)withs = scale·alpha/rank; several files stack their ranks.lora=0|1, and the server takes"lora": true|falsein the request body (OpenAI and Anthropic APIs) or"sampling": {"lora": ...}in the config. The switch is a device flag the kernels read, so captured CUDA graphs serve both states with no re-capture. Turned off, the output is bit-identical to the engine without an adapter.cvec. Session files stay backward compatible (a new bit in the existing flag word; the fingerprint changes only when an adapter is loaded). While batch slots are decoding, a request for the other state is refused.Without
--loranothing changes: the feature is opt-in.Related discussion
none
Approach
Commits: kernels (+
lora_paritytest); core hooks in decode, verify and prompt path; conversation cache/session keying;generateloader, CLI flags and request key;serverequest field + unit test; PDL overlap of the decode/verify up kernel (rank > 64 and HIP use the plain launch). Rebased ontomainatf57c0adc(0.2.0-beta line); conflicts were inlayer.cpp,conversation_state.cpp,conversation_cache.hppandgenerate.cppand were resolved by keepingmain's changes and re-adding the LoRA lines (including the LoRA switch in the #879 slot checkpoint move).Validation
Passed (measured on the earlier revision, NOT on the rebased branch):
Tested on
mainv0.1.40.4 (6674a00) with this branch applied, and before that on v0.1.40.2 with the same results. One NVIDIA B200, CUDA 12.8, sm_100. Model: Qwen4Exp IQ2_XS. Adapter: rank 50 on all 48 layers, 80 MiB VRAM.lora_parity: all checks pass.lora=1,lora=0,lora=1; a second engine without an adapter answers the same prompts. Greedy, with and without MTP:lora=0gives the same tokens as no adapter.lora=1runs give the same tokens.lora=1differs fromlora=0where the adapter changes behaviour.lora=0lora=1Before commit 6,
lora=1ran at 202.2 tok/s with MTP and 110.1 without. Each setting reads different prompt texts, so prompt read moves by a few percent between settings even where the prompt path is unchanged.lora=0lora=1lora_parity, rank 50, 6144 → 2560; there are 48 adapted layers per forward pass). Decode replays its layers from CUDA graphs, so the in-graph figure is the one decode pays:serve/test_server.py: the newtest_lora_keypasses. The 3 errors that remain also occur on the untouched base: a socket timeout and Python 3.9staticmethod.Failed:
none observed (on the earlier revision). On the rebased branch the build has not been attempted yet.
Not run (on the rebased branch,
799c0c17, on top off57c0adc):lora_parity, the end-to-endlora=0|1checks and the speed table: not re-run after the rebase (the rebase was done on a Mac without CUDA). The numbers above are from the earlier revision.layer.cpp,verify.cpp,prefill.cppandgenerate.cppare shared files.serve/test_server.pytest_lora_key: not re-run after the rebase.Limits
No SYCL/HIP port, no web UI toggle, no VRAM accounting in the layer-split auto planner (80 MiB at rank 50). Docs (
docs/DETAILS.md) and benchmark scripts/results are kept out of this PR; they live on the fork'sfeat/lora-adapterbranch.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.