mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
loop: the Metal Loop and the CUDA Loop side by side (#7776 only in Metal builds, no STRATA_WITH_LOOP there)
generate.cpp: #7776's hunks (option fields, option parsing, the "runs on the Metal engine only" refusal, the Metal loader call) are wrapped in #if defined(STRATA_GPU_METAL) <new> #else <old> #endif, so a CUDA / HIP / SYCL build keeps the text of f-0226-q4-loop (the refusal would otherwise reject the CUDA Loop, and both branches declare loop_adapter / loop_passes / loop_coda in the same struct). metal/CMakeLists.txt: the Metal build does not define STRATA_WITH_LOOP; it has its own looped window (src/engine/loop.inc).
This commit is contained in:
1 parent
26a4034b87
commit
57954faf3a
2 files changed
+16
No files matched your search
@@ -15,6 +15,10 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0" CACHE STRING "the oldest macOS the binari
|
||||
project(strata_metal LANGUAGES C CXX OBJCXX)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/strata_symbols.cmake) # -DSTRATA_KEEP_SYMBOLS=ON: host debug information, same machine code
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/strata_geometry.cmake) # -DSTRATA_GEOMETRY=<name> (default flash_next, no flag added)
|
||||
# the Metal engine has its own looped window (src/engine/loop.inc, #7776 and the dual-coda file): the CUDA / HIP loop code of the q4_lite shape
|
||||
# (STRATA_WITH_LOOP) is not compiled here
|
||||
set(STRATA_WITH_LOOP_BUILD OFF)
|
||||
remove_definitions(-DSTRATA_WITH_LOOP=1)
|
||||
|
||||
if(NOT APPLE)
|
||||
message(FATAL_ERROR "metal/ builds on macOS only")
|
||||
|
||||
@@ -207,8 +207,10 @@
|
||||
namespace strata::metal_engine {
|
||||
void set_model_shard(const char* shard1); // metal/src/engine/window.cpp
|
||||
void set_batch_slots(int n); // metal/src/engine/window.cpp: how many --batch slots the window keeps state for
|
||||
#if defined(STRATA_GPU_METAL) // loop-metal
|
||||
void loop_adapter_set(const char* path, int passes); // metal/src/engine/loop.inc: --loop-adapter
|
||||
void loop_coda_set(const char* sel); // metal/src/engine/loop.inc: --loop-coda universal|compact
|
||||
#endif
|
||||
// batch slot b <-> the main sequence: the running state (unless kv_only) and the first `upto` cells of K/V
|
||||
bool window_slot_copy_main(bool into_slot, int slot, int64_t upto, bool kv_only, std::string& err);
|
||||
std::string draft_vocab_default(); // metal/src/engine/window.cpp: the packaged default draft subset (data/draft_vocab.bin)
|
||||
@@ -1096,9 +1098,11 @@ struct Options {
|
||||
/// prompt again, the v0.1.2 behaviour). One is the GDN recurrence of the 36 layers, the QSA indexer tails and
|
||||
/// the PLE history (~118 MB of host RAM); the KV cache itself is positional and stays where it is.
|
||||
int prompt_cache = 6;
|
||||
#if defined(STRATA_GPU_METAL) // loop-metal
|
||||
std::string loop_coda = "universal"; ///< --loop-coda universal|compact (the dual-coda file)
|
||||
std::string loop_adapter; ///< --loop-adapter FILE: Looped Qwen3.8-Flash-Next recurrent-core adapter (.safetensors + sibling .json), Metal
|
||||
int loop_passes = 0; ///< --loop-passes T (0: the window's default, 2)
|
||||
#endif
|
||||
int64_t conversation_cache_mib = -1; // host RAM for independent conversations; -1: not given, --serve sizes it from the free RAM (#3493), 0: off
|
||||
int conversation_cache_slots = 4;
|
||||
int conversation_cache_swap_block_mib = strata::core::conversation_cache_swap_default_block_mib;
|
||||
@@ -1380,9 +1384,11 @@ void usage() {
|
||||
" --mtp-q4 all|proj|head opt-in: the draft layer's projections and/or draft head as 4-bit copies\n"
|
||||
" (head/all need the draft head's subset: --mtp-draft-vocab / rt/draft_vocab.bin)\n"
|
||||
" --mtp-draft-vocab FILE opt-in: the draft head's token subset (default <mtp>/draft_vocab.bin)\n"
|
||||
#if defined(STRATA_GPU_METAL) // loop-metal
|
||||
" --loop-adapter FILE opt-in, Metal: a Looped Qwen3.8-Flash-Next adapter (ckpt_final.safetensors + .json): the core layers\n"
|
||||
" 16..31 run --loop-passes times (default 2); no --batch, no conversation cache, prompts read in windows\n"
|
||||
" --loop-passes T the core's passes with --loop-adapter (2..8)\n"
|
||||
#endif
|
||||
" --draft mtp|dflash2 the draft source (default mtp); dflash2 needs --draft-model PACK (tools/dflash2_pack.py)\n"
|
||||
" and loads no MTP layer (--draft-fallback mtp keeps it as the fallback) (opt-in, Flash-Next, CUDA / HIP)\n"
|
||||
" --draft-fallback mtp|none with --draft dflash2 (default none): none = the MTP layer is not loaded at all, DFlash2 is the only drafter and a DFlash2 that cannot start is an error;\n"
|
||||
@@ -4221,9 +4227,11 @@ int main(int argc, char** argv) {
|
||||
else if (a == "--vision") o.vision = true;
|
||||
else if (a == "--session-save-reclaim") o.session_save_reclaim = true;
|
||||
else if (a == "--prompt-cache") o.prompt_cache = std::max(0, std::atoi(next("--prompt-cache")));
|
||||
#if defined(STRATA_GPU_METAL) // loop-metal
|
||||
else if (a == "--loop-adapter") o.loop_adapter = next("--loop-adapter");
|
||||
else if (a == "--loop-coda") o.loop_coda = next("--loop-coda");
|
||||
else if (a == "--loop-passes") o.loop_passes = std::atoi(next("--loop-passes"));
|
||||
#endif
|
||||
else if (a == "--conversation-cache-swap-block-mib") {
|
||||
const std::string value = next(a.c_str());
|
||||
if (value == "-h" || (value.size() >= 2 && value[0] == '-' && value[1] == '-')) {
|
||||
@@ -5514,12 +5522,15 @@ int main(int argc, char** argv) {
|
||||
// The experimental older-CPU build (STRATA_ISA_FLOOR=avx|none, compiled on that PC; #394 #595 #623) has ggml-cpu
|
||||
// for that floor, so a native pack's experts run there on ggml-cpu (every AVX2 kernel is behind cpu_avx2_ok).
|
||||
const char* isa_floor = strata::kernels::cpu::isa_floor_build();
|
||||
#if defined(STRATA_GPU_METAL) // loop-metal
|
||||
#if !defined(STRATA_GPU_METAL)
|
||||
if (!o.loop_adapter.empty()) { std::fprintf(stderr, "strata generate: --loop-adapter runs on the Metal engine only\n"); return 2; }
|
||||
#endif
|
||||
#endif
|
||||
#if defined(STRATA_GPU_METAL) // Apple Silicon: every expert is on the GPU; ggml-cpu (NEON) is the only CPU expert code
|
||||
strata::metal_engine::set_model_shard(o.native_preset.c_str()); // the decode window reads the model GGUF itself
|
||||
strata::metal_engine::set_batch_slots(o.batch);
|
||||
#if defined(STRATA_GPU_METAL) // loop-metal
|
||||
if (!o.loop_adapter.empty()) {
|
||||
if (o.batch > 0) { std::fprintf(stderr, "strata generate: --loop-adapter does not run --batch slots yet\n"); return 2; }
|
||||
// the looped core's extra K/V and GDN slots live only in the window: a parked conversation would come back without them
|
||||
@@ -5528,6 +5539,7 @@ int main(int argc, char** argv) {
|
||||
strata::metal_engine::loop_coda_set(o.loop_coda.c_str());
|
||||
strata::metal_engine::loop_adapter_set(o.loop_adapter.c_str(), o.loop_passes);
|
||||
}
|
||||
#endif
|
||||
o.mmap_experts = true; // ... experts included: no resident copy of them (the GGUF shards in place)
|
||||
if (false) {
|
||||
#else
|
||||
|
||||
Reference in new issue
Block a user