mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
build(loop): keep HIP, Metal, and SYCL builds compatible and polish docs
This commit is contained in:
1 parent
0703867d11
commit
e3f62bfe9c
7 files changed
+89
-7
No files matched your search
@@ -9,7 +9,7 @@ When `--loop-adapter` is omitted, Strata runs the stock 48-layer forward path.
|
||||
- `--loop-adapter FILE`: path to the Looped adapter `.safetensors` checkpoint (reads optional sibling `.json` metadata for `core_start`, `core_end`, `coda_lora_layers`, `lora_alpha`, `t_max`, `mode`).
|
||||
- `--loop-passes N`: number of recurrent passes `T` over the core layers `[core_start, core_end)` (default `2` when `--loop-adapter` is set; supports `2..8`).
|
||||
- `--loop-cd-omega F`: optional ratio-preserving LoopCD-Hidden weight applied after the final recurrent pass (default `0.0`).
|
||||
- `--loop-cd-thinking`: opt-in `<think>...</think>` gating for LoopCD-Hidden (matches `vllm_looped_qwen38`'s `compute_thinking_token_mask` with `default_thinking=False, include_end_token=False`). When omitted, `--loop-cd-omega` applies unconditionally to every token (legacy behavior). When enabled, LoopCD-Hidden is applied starting on `<think>` through the token before `</think>`, and leaves `</think>` and all non-thinking tokens bit-identical to `omega = 0.0`.
|
||||
- `--loop-cd-thinking`: opt-in `<think>...</think>` gating for LoopCD-Hidden (`default_thinking=false, include_end_token=false` semantics). When omitted, `--loop-cd-omega` applies unconditionally to every token (legacy behavior). When enabled, LoopCD-Hidden is applied starting on `<think>` through the token before `</think>`, and leaves `</think>` and all non-thinking tokens bit-identical to `omega = 0.0`.
|
||||
- `--loop-cd-think-ids START END`: token IDs for `<think>` and `</think>` used by `--loop-cd-thinking` (default `248068 248069` for `Qwen3.8-Flash-Next`; `serve/server.py` also auto-resolves them from the loaded tokenizer when not explicitly set).
|
||||
|
||||
## Per-Request Serving Controls (`--serve` / `serve/server.py`)
|
||||
@@ -18,7 +18,7 @@ When serving mixed traffic with `--loop-adapter FILE --loop-passes N` (`N >= 2`)
|
||||
|
||||
- `"loop_passes"`: `1` (exact stock 48-layer single-pass bypass: zero extra core passes, zero workspace/mixer/LoRA/LoopCD hooks) or `N` (the engine's loaded `--loop-passes`). Invalid values return HTTP `400`.
|
||||
- Why `{1, N}`: pass gates and LoRAs pre-fold `rem_idx = N - 1 - p` at adapter load time so weights are never duplicated in VRAM; `1` bypasses the adapter completely and `N` runs the loaded recurrent depth.
|
||||
- **Lazy `T=1` CUDA graph bank:** the engine captures the `T=1` bypass decode/commit CUDA graphs lazily on the first `loop_passes=1` request (zero extra startup VRAM when unused; ~100 MiB for all 6 verify window widths when first used). Works on single-GPU, non-cyclic multi-GPU, and cyclic multi-GPU `--layer-split`.
|
||||
- **Lazy `T=1` CUDA graph bank:** the engine captures the `T=1` bypass decode/commit CUDA graphs lazily on the first `loop_passes=1` request (`0 MiB` extra startup VRAM when unused; `+66 MiB` measured on RTX 3090 across all 6 verify window widths when first used). Works on single-GPU, non-cyclic multi-GPU, and cyclic multi-GPU `--layer-split`.
|
||||
- `"loop_cd_omega"`: finite float overriding `--loop-cd-omega` for that request (`0.0` disables LoopCD-Hidden; ignored when `loop_passes=1`).
|
||||
- `"loop_cd_thinking"`: boolean overriding `--loop-cd-thinking` for that request. Because `Verifier` reads a per-token device omega vector staged from pinned host memory before each graph launch, switching `loop_cd_omega`, `loop_cd_thinking`, or entering/exiting `<think>` spans requires **zero extra CUDA graph captures**.
|
||||
- **Automatic direct-mode bypass (`--loop-direct-t1` / `"loop_direct_t1": true`):** optional server flag/config key on `serve/server.py`. When enabled on a server started with `--loop-passes N >= 2`, requests with thinking disabled (`chat_template_kwargs: {"enable_thinking": false}`, `reasoning_effort: "none"`, Responses `reasoning: {"effort": "none"}`, or Anthropic `thinking: {"type": "disabled"}`) automatically run at stock `loop_passes=1` unless the request explicitly sends `"loop_passes"`.
|
||||
@@ -114,4 +114,4 @@ On RAM-offloaded MoE, one large chunk per visit beats smaller chunks with more o
|
||||
## Credits
|
||||
|
||||
- Recurrent core architecture inspired by [`jasontitus/loopedqwen`](https://github.com/jasontitus/loopedqwen) (MIT).
|
||||
- Engine based on [`Niko1221/Strata`](https://github.com/Niko1221/Strata) (MIT).
|
||||
- Looped Qwen3.8-Flash-Next checkpoint and initial CUDA engine integration by [`alesha-pro`](https://github.com/alesha-pro/Strata) ([`alesha-pro/Looped-Qwen3.8-Flash-Next`](https://huggingface.co/alesha-pro/Looped-Qwen3.8-Flash-Next)).
|
||||
@@ -12,6 +12,7 @@
|
||||
#define cublasCreate hipblasCreate
|
||||
#define cublasDestroy hipblasDestroy
|
||||
#define cublasSetStream hipblasSetStream
|
||||
#define cublasSgemm hipblasSgemm
|
||||
#define cublasGemmEx hipblasGemmEx
|
||||
#define CUBLAS_OP_N HIPBLAS_OP_N
|
||||
#define CUBLAS_OP_T HIPBLAS_OP_T
|
||||
|
||||
@@ -205,7 +205,7 @@ set(STRATA_METAL_HOST_SOURCES
|
||||
${S}/core/native_head.cpp ${S}/core/native_dense.cpp ${S}/core/verify.cpp ${S}/core/mtp.cpp
|
||||
${S}/core/conversation_snapshot.cpp ${S}/core/conversation_state.cpp ${S}/core/conversation_memory.cpp
|
||||
${S}/core/peer_experts.cpp ${S}/core/arch_defaults.cpp ${S}/core/vmm.cpp ${S}/core/conversation_file.cpp
|
||||
${S}/kernels/ngram.cpp ${S}/ngram/ple_reader.cpp ${S}/platform/direct_file.cpp ${S}/platform/io_priority.cpp
|
||||
${S}/kernels/ngram.cpp ${S}/kernels/loop_adapter_stub.cpp ${S}/ngram/ple_reader.cpp ${S}/platform/direct_file.cpp ${S}/platform/io_priority.cpp
|
||||
${S}/prefill/prefill.cpp
|
||||
${S}/spec/suffix_drafter.cpp ${S}/spec/controller.cpp ${S}/spec/draft_policy.cpp ${S}/spec/draft_source.cpp
|
||||
${S}/kernels/cpu/pool.cpp ${S}/kernels/cpu/expert_layout.cpp ${S}/kernels/cpu/native_expert.cpp
|
||||
|
||||
@@ -321,7 +321,7 @@ namespace strata::kernels { void sample_tokens(const float * p0, int p1, int p2,
|
||||
namespace strata::kernels { void scale_inplace(float * p0, int64_t p1, float p2, void * p3) { strata::metal_engine::missing("strata::kernels::scale_inplace"); } }
|
||||
namespace strata::kernels { void scatter_rows_f32(const float * p0, float * p1, const int32_t * p2, int64_t p3, int64_t p4, void * p5) { strata::metal_engine::missing("strata::kernels::scatter_rows_f32"); } }
|
||||
namespace strata::kernels { void shared_expert(const uint8_t * p0, const uint8_t * p1, const uint16_t * p2, const SForm & p3, const uint8_t * p4, const float * p5, const float * p6, const SForm & p7, const uint8_t * p8, const float * p9, const float * p10, const SForm & p11, const uint8_t * p12, const float * p13, const float * p14, const uint16_t * p15, float * p16, float * p17, int64_t p18, int64_t p19, int p20, void * p21, const float * p22, const NativeSharedWeights * p23) { strata::metal_engine::missing("strata::kernels::shared_expert"); } }
|
||||
namespace strata::kernels { void shared_expert_multi(int p0, const float * p1, const uint16_t * p2, const NativeSharedWeights & p3, const uint16_t * p4, float * p5, float * p6, float * p7, float * p8, int64_t p9, int64_t p10, void * p11, const void * p12, int p13) { strata::metal_engine::missing("strata::kernels::shared_expert_multi"); } }
|
||||
namespace strata::kernels { void shared_expert_multi(int p0, const float * p1, const uint16_t * p2, const NativeSharedWeights & p3, const uint16_t * p4, float * p5, float * p6, float * p7, float * p8, int64_t p9, int64_t p10, void * p11, const void * p12, int p13, int p14, int64_t p15) { strata::metal_engine::missing("strata::kernels::shared_expert_multi"); } }
|
||||
namespace strata::kernels { void silu_inplace(float * p0, int64_t p1, void * p2) { strata::metal_engine::missing("strata::kernels::silu_inplace"); } }
|
||||
namespace strata::kernels { void spec_draft_sample(float * p0, int p1, const int32_t * p2, const int32_t * p3, int p4, const SamplerParams * p5, int32_t * p6, int p7, int p8, const int32_t * p9, void * p10, int32_t * p11, float * p12, int32_t * p13, int p14, float p15, void * p16) { strata::metal_engine::missing("strata::kernels::spec_draft_sample"); } }
|
||||
namespace strata::kernels { void topk_512_step(const float * p0, const QsaShapes & p1, int64_t p2, const int32_t * p3, int32_t * p4, void * p5) { strata::metal_engine::missing("strata::kernels::topk_512_step"); } }
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
// src/kernels/loop_adapter_stub.cpp - Unloaded no-op implementation of loop_adapter.hpp for backends that do not
|
||||
// compile src/kernels/cuda/loop_adapter.cu (Metal, SYCL, CPU-only builds).
|
||||
#include "strata/kernels/loop_adapter.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace strata::kernels {
|
||||
|
||||
const LoopLoraPair* LoopAdapter::lora(int, int64_t, LoopTarget) const { return nullptr; }
|
||||
|
||||
const LoopAdapter& loop_adapter() {
|
||||
static const LoopAdapter none{};
|
||||
return none;
|
||||
}
|
||||
|
||||
bool loop_adapter_load(const std::string&, int, float, int64_t, int64_t, int64_t, std::string&, std::string& err, bool,
|
||||
int32_t, int32_t) {
|
||||
err = "loop_adapter: --loop-adapter is only supported on CUDA/HIP builds";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool loop_adapter_replicate(std::string&) { return true; }
|
||||
|
||||
void loop_adapter_free() {}
|
||||
|
||||
int64_t loop_extra_gdn_slots(int64_t, int64_t, int64_t) { return 0; }
|
||||
|
||||
int64_t loop_extra_qsa_slots(int64_t, int64_t, int64_t) { return 0; }
|
||||
|
||||
std::vector<LoopStep> build_loop_schedule(int64_t, int64_t qsa_interval, int64_t layer_lo, int64_t layer_hi, bool) {
|
||||
const int64_t I = qsa_interval > 0 ? qsa_interval : 4;
|
||||
std::vector<LoopStep> out;
|
||||
out.reserve((size_t) (layer_hi > layer_lo ? layer_hi - layer_lo : 0));
|
||||
for (int64_t l = layer_lo; l < layer_hi; ++l) {
|
||||
LoopStep s;
|
||||
s.layer = l;
|
||||
s.pass = 0;
|
||||
s.core_step = -1;
|
||||
if (l % I == I - 1) s.qsa_slot = l / I;
|
||||
else s.gdn_slot = l - l / I;
|
||||
out.push_back(s);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool loop_split_cyclic(const std::vector<int64_t>&) { return false; }
|
||||
|
||||
std::vector<LoopVisit> build_loop_itinerary(int64_t, int64_t, const std::vector<int64_t>&) { return {}; }
|
||||
|
||||
void loop_workspace_entry(const float*, const float*, float*, int, int, void*) {
|
||||
throw std::runtime_error("loop_workspace_entry: --loop-adapter is only supported on CUDA/HIP builds");
|
||||
}
|
||||
|
||||
void loop_cross_pass_mixer(const float*, const float*, float*, int, int, int, void*) {
|
||||
throw std::runtime_error("loop_cross_pass_mixer: --loop-adapter is only supported on CUDA/HIP builds");
|
||||
}
|
||||
|
||||
void loop_lora_add(const float*, int, float*, int, int, int64_t, LoopTarget, int, void*) {
|
||||
throw std::runtime_error("loop_lora_add: --loop-adapter is only supported on CUDA/HIP builds");
|
||||
}
|
||||
|
||||
void loop_lora_add_f16(const uint16_t*, int, float*, int, int, int64_t, LoopTarget, int, void*) {
|
||||
throw std::runtime_error("loop_lora_add_f16: --loop-adapter is only supported on CUDA/HIP builds");
|
||||
}
|
||||
|
||||
void loop_gdn_ab_epilogue(const float*, const float*, const float*, const float*, float*, float*, int, int, void*) {
|
||||
throw std::runtime_error("loop_gdn_ab_epilogue: --loop-adapter is only supported on CUDA/HIP builds");
|
||||
}
|
||||
|
||||
void loop_cd_hidden(const float*, const float*, float*, float, int, void*) {
|
||||
throw std::runtime_error("loop_cd_hidden: --loop-adapter is only supported on CUDA/HIP builds");
|
||||
}
|
||||
|
||||
void loop_cd_hidden_per_tok(const float*, const float*, float*, const float*, int, void*) {
|
||||
throw std::runtime_error("loop_cd_hidden_per_tok: --loop-adapter is only supported on CUDA/HIP builds");
|
||||
}
|
||||
|
||||
} // namespace strata::kernels
|
||||
@@ -280,7 +280,7 @@ set(_kernel_files "")
|
||||
foreach(k IN LISTS _kernel_cu)
|
||||
list(APPEND _kernel_files src/kernels/cuda/${k}.cu)
|
||||
endforeach()
|
||||
strata_resolve(_kernels ${_kernel_files} src/kernels/ngram.cpp src/ngram/ple_reader.cpp src/platform/direct_file.cpp)
|
||||
strata_resolve(_kernels ${_kernel_files} src/kernels/ngram.cpp src/kernels/loop_adapter_stub.cpp src/ngram/ple_reader.cpp src/platform/direct_file.cpp)
|
||||
list(APPEND _kernels ${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/cuda/qsa_prompt_attn_xmx.dp.cpp) # port-only: the XMX prompt attention
|
||||
list(APPEND _kernels ${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/cuda/qsa_prompt_attn_esimd.dp.cpp) # port-only: the int8 DPAS (ESIMD) prompt attention
|
||||
list(APPEND _kernels ${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/cuda/weight_permute.dp.cpp)
|
||||
|
||||
@@ -314,7 +314,10 @@ bool fused_swiglu_q81_enabled() {
|
||||
|
||||
void shared_expert_multi(int n_tok, const float* x, const uint16_t* x_bf16, const NativeSharedWeights& nw,
|
||||
const uint16_t* gate_inp_bf16, float* gate, float* up, float* g, float* out, int64_t n_embd,
|
||||
int64_t n_ff, void* stream, const void* x_q8_1_ready, int lfuse) {
|
||||
int64_t n_ff, void* stream, const void* x_q8_1_ready, int lfuse, int loop_pass,
|
||||
int64_t loop_layer) {
|
||||
(void) loop_pass;
|
||||
(void) loop_layer;
|
||||
const bool gate_deferred = (lfuse & 1) != 0, pair = (lfuse & 2) != 0;
|
||||
if (n_tok < 1 || n_tok > 8 || !nw.q8_1 || !nw.gate_data || !nw.up_data || !nw.down_data || !stream)
|
||||
throw std::invalid_argument("shared_expert_multi: needs 1..8 tokens, native weights, scratch and a stream");
|
||||
|
||||
Reference in new issue
Block a user