toy 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +1124 -0
- data/LICENSE +21 -0
- data/Makefile +2022 -0
- data/README.md +154 -0
- data/bin/toy +10 -0
- data/lib/toy/compute.rb +135 -0
- data/lib/toy/compute_cuda.rb +104 -0
- data/lib/toy/compute_metal.rb +97 -0
- data/lib/toy/core/cli/describe.rb +188 -0
- data/lib/toy/core/cli/eval.rb +385 -0
- data/lib/toy/core/cli/exit_codes.rb +15 -0
- data/lib/toy/core/cli/fetch.rb +238 -0
- data/lib/toy/core/cli/infer.rb +268 -0
- data/lib/toy/core/cli/install.rb +228 -0
- data/lib/toy/core/cli/list.rb +86 -0
- data/lib/toy/core/cli/manifest.rb +49 -0
- data/lib/toy/core/cli/new.rb +594 -0
- data/lib/toy/core/cli/serve.rb +237 -0
- data/lib/toy/core/cli/train.rb +471 -0
- data/lib/toy/core/cli.rb +165 -0
- data/lib/toy/core/config.rb +64 -0
- data/lib/toy/core/gguf_meta.rb +161 -0
- data/lib/toy/core/model_scan.rb +221 -0
- data/lib/toy/core/run_log.rb +94 -0
- data/lib/toy/core/toy_root.rb +95 -0
- data/lib/toy/dev/toy_card.rb +299 -0
- data/lib/toy/dev/toy_describe_flow.rb +412 -0
- data/lib/toy/dev/toy_logprobs.rb +86 -0
- data/lib/toy/dev/toy_tap.rb +183 -0
- data/lib/toy/dev/toy_token_drift.rb +121 -0
- data/lib/toy/ffi/tinynn.rb +1491 -0
- data/lib/toy/ffi/tinynn_cuda.rb +1124 -0
- data/lib/toy/ffi/tinynn_metal.rb +359 -0
- data/lib/toy/ffi_manifest.rb +84 -0
- data/lib/toy/io/bpe.rb +325 -0
- data/lib/toy/io/gguf_kv.rb +35 -0
- data/lib/toy/io/gguf_load.rb +331 -0
- data/lib/toy/io/loaders/toy_gpt2_loader.rb +70 -0
- data/lib/toy/io/loaders/toy_smollm2_loader.rb +754 -0
- data/lib/toy/io/model_index.rb +206 -0
- data/lib/toy/io/run_bundle.rb +280 -0
- data/lib/toy/io/tokenizer.rb +613 -0
- data/lib/toy/io/toy_corpus_loader.rb +52 -0
- data/lib/toy/io/toy_events.rb +56 -0
- data/lib/toy/io/toy_image_loader.rb +48 -0
- data/lib/toy/llm/adamw.rb +169 -0
- data/lib/toy/llm/archs/llama_arch.rb +233 -0
- data/lib/toy/llm/archs/llama_arch_cuda.rb +237 -0
- data/lib/toy/llm/archs/llama_arch_metal.rb +237 -0
- data/lib/toy/llm/blocks/transformer_block.rb +876 -0
- data/lib/toy/llm/blocks/transformer_block_cuda.rb +880 -0
- data/lib/toy/llm/blocks/transformer_block_metal.rb +880 -0
- data/lib/toy/llm/classify_batch.rb +88 -0
- data/lib/toy/llm/engine/gpt2_fwd_engine.rb +360 -0
- data/lib/toy/llm/engine/gpt2_fwd_engine_cuda.rb +362 -0
- data/lib/toy/llm/engine/gpt2_fwd_engine_metal.rb +362 -0
- data/lib/toy/llm/engine/gpt2_kv_engine.rb +346 -0
- data/lib/toy/llm/engine/gpt2_kv_engine_cuda.rb +348 -0
- data/lib/toy/llm/engine/gpt2_kv_engine_metal.rb +348 -0
- data/lib/toy/llm/engine/gpt2_seq_engine.rb +289 -0
- data/lib/toy/llm/engine/gpt2_seq_engine_cuda.rb +293 -0
- data/lib/toy/llm/engine/gpt2_seq_engine_metal.rb +293 -0
- data/lib/toy/llm/engine/llama_kv_engine.rb +1593 -0
- data/lib/toy/llm/engine/llama_kv_engine_cuda.rb +1526 -0
- data/lib/toy/llm/engine/llama_kv_engine_metal.rb +1526 -0
- data/lib/toy/llm/engine/llama_seq_engine.rb +1233 -0
- data/lib/toy/llm/engine/llama_seq_engine_cuda.rb +1238 -0
- data/lib/toy/llm/engine/llama_seq_engine_metal.rb +1238 -0
- data/lib/toy/llm/engine/vit_tiny_engine.rb +467 -0
- data/lib/toy/llm/labels.rb +142 -0
- data/lib/toy/llm/primitives/gqa.rb +62 -0
- data/lib/toy/llm/primitives/gqa_cuda.rb +66 -0
- data/lib/toy/llm/primitives/gqa_metal.rb +66 -0
- data/lib/toy/llm/primitives/rms_norm.rb +39 -0
- data/lib/toy/llm/primitives/rms_norm_cuda.rb +43 -0
- data/lib/toy/llm/primitives/rms_norm_metal.rb +43 -0
- data/lib/toy/llm/primitives/rope.rb +68 -0
- data/lib/toy/llm/primitives/rope_cuda.rb +72 -0
- data/lib/toy/llm/primitives/rope_metal.rb +72 -0
- data/lib/toy/llm/primitives/swiglu.rb +41 -0
- data/lib/toy/llm/primitives/swiglu_cuda.rb +45 -0
- data/lib/toy/llm/primitives/swiglu_metal.rb +45 -0
- data/lib/toy/llm/recipe_options.rb +71 -0
- data/lib/toy/llm/recipes/from_scratch.rb +105 -0
- data/lib/toy/llm/recipes/from_scratch_cuda.rb +109 -0
- data/lib/toy/llm/recipes/from_scratch_metal.rb +109 -0
- data/lib/toy/llm/recipes/lora.rb +110 -0
- data/lib/toy/llm/recipes/lora_cuda.rb +114 -0
- data/lib/toy/llm/recipes/lora_metal.rb +114 -0
- data/lib/toy/llm/recipes/vit_tiny.rb +75 -0
- data/lib/toy/llm/recipes/warm_start.rb +235 -0
- data/lib/toy/llm/recipes/warm_start_cuda.rb +239 -0
- data/lib/toy/llm/recipes/warm_start_metal.rb +239 -0
- data/lib/toy/llm/training_batch.rb +133 -0
- data/lib/toy/models/arch.rb +253 -0
- data/lib/toy/models/gpt2.rb +311 -0
- data/lib/toy/models/toy_gpt2.rb +177 -0
- data/lib/toy/models/toy_smollm2.rb +393 -0
- data/lib/toy/models/toy_vit.rb +83 -0
- data/lib/toy/models/transformer.rb +1494 -0
- data/lib/toy/models/transformer_lm.rb +298 -0
- data/lib/toy/models/transformer_lm_cuda.rb +159 -0
- data/lib/toy/models/transformer_lm_metal.rb +142 -0
- data/lib/toy/mri.rb +300 -0
- data/lib/toy/run/eval.rb +76 -0
- data/lib/toy/run/eval_cuda.rb +66 -0
- data/lib/toy/run/eval_lmc.rb +334 -0
- data/lib/toy/run/eval_metal.rb +67 -0
- data/lib/toy/run/infer.rb +130 -0
- data/lib/toy/run/infer_cuda.rb +118 -0
- data/lib/toy/run/infer_metal.rb +119 -0
- data/lib/toy/run/infer_trace.rb +37 -0
- data/lib/toy/run/serve.rb +144 -0
- data/lib/toy/run/train.rb +404 -0
- data/lib/toy/run/train_cuda.rb +397 -0
- data/lib/toy/run/train_gpt2.rb +103 -0
- data/lib/toy/run/train_gpt2_cuda.rb +85 -0
- data/lib/toy/run/train_gpt2_metal.rb +85 -0
- data/lib/toy/run/train_lora.rb +207 -0
- data/lib/toy/run/train_lora_cuda.rb +219 -0
- data/lib/toy/run/train_metal.rb +227 -0
- data/lib/toy/run/train_vit.rb +251 -0
- data/lib/toy/serve/openai/embeddings_handler.rb +92 -0
- data/lib/toy/serve/openai/handlers.rb +143 -0
- data/lib/toy/serve/openai/server.rb +159 -0
- data/lib/toy/train/sampler.rb +314 -0
- data/lib/toy/train/toy_chat_template.rb +179 -0
- data/lib/toy/train/toy_drift_grad.rb +176 -0
- data/lib/toy/train/toy_gguf_fuse.rb +428 -0
- data/lib/toy/train/toy_gguf_writer.rb +100 -0
- data/lib/toy/train/toy_lr_schedule.rb +39 -0
- data/lib/toy/train/toy_sample.rb +125 -0
- data/lib/toy/train/toy_trainer.rb +86 -0
- data/lib/toy/train/training.rb +160 -0
- data/lib/toy/version.rb +11 -0
- data/lib/toy.rb +902 -0
- data/prep/progress +118 -0
- data/prep/quietly +64 -0
- data/sig/toy.rbs +397 -0
- data/sig/toy_compute.rbs +450 -0
- data/spinel-ext.json +122 -0
- data/tinynn/Makefile +71 -0
- data/tinynn/tinynn_backend_cuda.c +99 -0
- data/tinynn/tinynn_backend_metal.m +75 -0
- data/tinynn/tinynn_events.c +122 -0
- data/tinynn/tinynn_events.h +83 -0
- data/tinynn/tinynn_ggml.c +2460 -0
- data/tinynn/tinynn_ggml.h +545 -0
- data/tinynn/tinynn_gguf.c +783 -0
- data/tinynn/tinynn_gguf.h +167 -0
- data/tinynn/tinynn_trace.c +180 -0
- data/tinynn/tinynn_trace.h +85 -0
- data/vendor/ggml/AUTHORS +335 -0
- data/vendor/ggml/CMakeLists.txt +505 -0
- data/vendor/ggml/CONTRIBUTING.md +3 -0
- data/vendor/ggml/LICENSE +21 -0
- data/vendor/ggml/README.md +50 -0
- data/vendor/ggml/ci/run.sh +395 -0
- data/vendor/ggml/cmake/FindNCCL.cmake +36 -0
- data/vendor/ggml/cmake/GitVars.cmake +22 -0
- data/vendor/ggml/cmake/common.cmake +50 -0
- data/vendor/ggml/cmake/ggml-config.cmake.in +191 -0
- data/vendor/ggml/docs/gguf.md +828 -0
- data/vendor/ggml/examples/CMakeLists.txt +34 -0
- data/vendor/ggml/examples/common-ggml.cpp +244 -0
- data/vendor/ggml/examples/common-ggml.h +18 -0
- data/vendor/ggml/examples/common.cpp +675 -0
- data/vendor/ggml/examples/common.h +322 -0
- data/vendor/ggml/examples/gpt-2/CMakeLists.txt +32 -0
- data/vendor/ggml/examples/gpt-2/README.md +225 -0
- data/vendor/ggml/examples/gpt-2/convert-cerebras-to-ggml.py +183 -0
- data/vendor/ggml/examples/gpt-2/convert-ckpt-to-ggml.py +159 -0
- data/vendor/ggml/examples/gpt-2/convert-h5-to-ggml.py +195 -0
- data/vendor/ggml/examples/gpt-2/download-ggml-model.sh +69 -0
- data/vendor/ggml/examples/gpt-2/download-model.sh +48 -0
- data/vendor/ggml/examples/gpt-2/main-alloc.cpp +880 -0
- data/vendor/ggml/examples/gpt-2/main-backend.cpp +946 -0
- data/vendor/ggml/examples/gpt-2/main-batched.cpp +1210 -0
- data/vendor/ggml/examples/gpt-2/main-ctx.cpp +840 -0
- data/vendor/ggml/examples/gpt-2/main-sched.cpp +1079 -0
- data/vendor/ggml/examples/gpt-2/quantize.cpp +184 -0
- data/vendor/ggml/examples/gpt-j/CMakeLists.txt +13 -0
- data/vendor/ggml/examples/gpt-j/README.md +239 -0
- data/vendor/ggml/examples/gpt-j/convert-h5-to-ggml.py +173 -0
- data/vendor/ggml/examples/gpt-j/download-ggml-model.sh +69 -0
- data/vendor/ggml/examples/gpt-j/download-model.sh +11 -0
- data/vendor/ggml/examples/gpt-j/main.cpp +755 -0
- data/vendor/ggml/examples/gpt-j/quantize.cpp +182 -0
- data/vendor/ggml/examples/magika/CMakeLists.txt +17 -0
- data/vendor/ggml/examples/magika/README.md +23 -0
- data/vendor/ggml/examples/magika/convert.py +32 -0
- data/vendor/ggml/examples/magika/main.cpp +374 -0
- data/vendor/ggml/examples/mnist/CMakeLists.txt +58 -0
- data/vendor/ggml/examples/mnist/README.md +206 -0
- data/vendor/ggml/examples/mnist/mnist-common.cpp +496 -0
- data/vendor/ggml/examples/mnist/mnist-common.h +166 -0
- data/vendor/ggml/examples/mnist/mnist-eval.cpp +67 -0
- data/vendor/ggml/examples/mnist/mnist-train-cnn.py +91 -0
- data/vendor/ggml/examples/mnist/mnist-train-fc.py +131 -0
- data/vendor/ggml/examples/mnist/mnist-train.cpp +39 -0
- data/vendor/ggml/examples/mnist/server.py +36 -0
- data/vendor/ggml/examples/mnist/web/index.html +178 -0
- data/vendor/ggml/examples/perf-metal/CMakeLists.txt +7 -0
- data/vendor/ggml/examples/perf-metal/perf-metal.cpp +152 -0
- data/vendor/ggml/examples/prompts/dolly-v2.txt +100 -0
- data/vendor/ggml/examples/prompts/gpt-2-chinese.txt +1 -0
- data/vendor/ggml/examples/prompts/gpt-2.txt +100 -0
- data/vendor/ggml/examples/prompts/gpt-j.txt +100 -0
- data/vendor/ggml/examples/prompts/gpt-neox-japanese.txt +1 -0
- data/vendor/ggml/examples/prompts/gpt-neox.txt +100 -0
- data/vendor/ggml/examples/prompts/polyglot-ko.txt +3 -0
- data/vendor/ggml/examples/prompts/replit.txt +100 -0
- data/vendor/ggml/examples/prompts/starcoder.txt +100 -0
- data/vendor/ggml/examples/prompts/test-cases.txt +110 -0
- data/vendor/ggml/examples/prompts/tokenize_huggingface.py +65 -0
- data/vendor/ggml/examples/prompts/whisper.txt +100 -0
- data/vendor/ggml/examples/python/README.md +115 -0
- data/vendor/ggml/examples/python/api.h +14 -0
- data/vendor/ggml/examples/python/example_add_quant.py +25 -0
- data/vendor/ggml/examples/python/example_test_all_quants.py +68 -0
- data/vendor/ggml/examples/python/ggml/__init__.py +58 -0
- data/vendor/ggml/examples/python/ggml/__init__.pyi +2406 -0
- data/vendor/ggml/examples/python/ggml/cffi.py +11 -0
- data/vendor/ggml/examples/python/ggml/ffi/__init__.pyi +7 -0
- data/vendor/ggml/examples/python/ggml/utils.py +182 -0
- data/vendor/ggml/examples/python/regenerate.py +42 -0
- data/vendor/ggml/examples/python/stubs.py +128 -0
- data/vendor/ggml/examples/python/test_tensor.py +258 -0
- data/vendor/ggml/examples/sam/CMakeLists.txt +13 -0
- data/vendor/ggml/examples/sam/README.md +95 -0
- data/vendor/ggml/examples/sam/convert-pth-to-ggml.py +147 -0
- data/vendor/ggml/examples/sam/example.jpg +0 -0
- data/vendor/ggml/examples/sam/sam.cpp +2370 -0
- data/vendor/ggml/examples/simple/CMakeLists.txt +21 -0
- data/vendor/ggml/examples/simple/README.md +61 -0
- data/vendor/ggml/examples/simple/simple-backend.cpp +153 -0
- data/vendor/ggml/examples/simple/simple-ctx.cpp +127 -0
- data/vendor/ggml/examples/stb_image.h +7987 -0
- data/vendor/ggml/examples/stb_image_write.h +1724 -0
- data/vendor/ggml/examples/test-cmake/CMakeLists.txt +10 -0
- data/vendor/ggml/examples/test-cmake/README.md +3 -0
- data/vendor/ggml/examples/test-cmake/test-cmake.cpp +6 -0
- data/vendor/ggml/examples/yolo/CMakeLists.txt +6 -0
- data/vendor/ggml/examples/yolo/README.md +59 -0
- data/vendor/ggml/examples/yolo/convert-yolov3-tiny.py +53 -0
- data/vendor/ggml/examples/yolo/data/coco.names +80 -0
- data/vendor/ggml/examples/yolo/data/labels/100_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_7.png +0 -0
- data/vendor/ggml/examples/yolo/yolo-image.cpp +210 -0
- data/vendor/ggml/examples/yolo/yolo-image.h +39 -0
- data/vendor/ggml/examples/yolo/yolov3-tiny.cpp +661 -0
- data/vendor/ggml/ggml.pc.in +10 -0
- data/vendor/ggml/include/ggml-alloc.h +85 -0
- data/vendor/ggml/include/ggml-backend.h +431 -0
- data/vendor/ggml/include/ggml-blas.h +25 -0
- data/vendor/ggml/include/ggml-cann.h +123 -0
- data/vendor/ggml/include/ggml-cpp.h +39 -0
- data/vendor/ggml/include/ggml-cpu.h +151 -0
- data/vendor/ggml/include/ggml-cuda.h +50 -0
- data/vendor/ggml/include/ggml-hexagon.h +19 -0
- data/vendor/ggml/include/ggml-metal.h +61 -0
- data/vendor/ggml/include/ggml-opencl.h +26 -0
- data/vendor/ggml/include/ggml-openvino.h +37 -0
- data/vendor/ggml/include/ggml-opt.h +256 -0
- data/vendor/ggml/include/ggml-rpc.h +35 -0
- data/vendor/ggml/include/ggml-sycl.h +49 -0
- data/vendor/ggml/include/ggml-virtgpu.h +14 -0
- data/vendor/ggml/include/ggml-vulkan.h +29 -0
- data/vendor/ggml/include/ggml-webgpu.h +19 -0
- data/vendor/ggml/include/ggml-zdnn.h +17 -0
- data/vendor/ggml/include/ggml-zendnn.h +22 -0
- data/vendor/ggml/include/ggml.h +2845 -0
- data/vendor/ggml/include/gguf.h +204 -0
- data/vendor/ggml/requirements.txt +12 -0
- data/vendor/ggml/scripts/gen-authors.sh +9 -0
- data/vendor/ggml/scripts/release.sh +296 -0
- data/vendor/ggml/scripts/sync-llama-am.sh +167 -0
- data/vendor/ggml/scripts/sync-llama.last +1 -0
- data/vendor/ggml/scripts/sync-llama.sh +21 -0
- data/vendor/ggml/scripts/sync-whisper-am.sh +138 -0
- data/vendor/ggml/scripts/sync-whisper.last +1 -0
- data/vendor/ggml/scripts/sync-whisper.sh +17 -0
- data/vendor/ggml/src/CMakeLists.txt +493 -0
- data/vendor/ggml/src/ggml-alloc.c +1248 -0
- data/vendor/ggml/src/ggml-backend-dl.cpp +48 -0
- data/vendor/ggml/src/ggml-backend-dl.h +45 -0
- data/vendor/ggml/src/ggml-backend-impl.h +275 -0
- data/vendor/ggml/src/ggml-backend-meta.cpp +2144 -0
- data/vendor/ggml/src/ggml-backend-reg.cpp +586 -0
- data/vendor/ggml/src/ggml-backend.cpp +2371 -0
- data/vendor/ggml/src/ggml-blas/CMakeLists.txt +101 -0
- data/vendor/ggml/src/ggml-blas/ggml-blas.cpp +522 -0
- data/vendor/ggml/src/ggml-cann/CMakeLists.txt +89 -0
- data/vendor/ggml/src/ggml-cann/acl_tensor.cpp +195 -0
- data/vendor/ggml/src/ggml-cann/acl_tensor.h +349 -0
- data/vendor/ggml/src/ggml-cann/aclnn_ops.cpp +4436 -0
- data/vendor/ggml/src/ggml-cann/aclnn_ops.h +1190 -0
- data/vendor/ggml/src/ggml-cann/common.h +651 -0
- data/vendor/ggml/src/ggml-cann/ggml-cann.cpp +3062 -0
- data/vendor/ggml/src/ggml-common.h +1900 -0
- data/vendor/ggml/src/ggml-cpu/CMakeLists.txt +731 -0
- data/vendor/ggml/src/ggml-cpu/amx/amx.cpp +249 -0
- data/vendor/ggml/src/ggml-cpu/amx/amx.h +8 -0
- data/vendor/ggml/src/ggml-cpu/amx/common.h +115 -0
- data/vendor/ggml/src/ggml-cpu/amx/mmq.cpp +2512 -0
- data/vendor/ggml/src/ggml-cpu/amx/mmq.h +10 -0
- data/vendor/ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp +98 -0
- data/vendor/ggml/src/ggml-cpu/arch/arm/quants.c +4245 -0
- data/vendor/ggml/src/ggml-cpu/arch/arm/repack.cpp +5156 -0
- data/vendor/ggml/src/ggml-cpu/arch/loongarch/quants.c +2158 -0
- data/vendor/ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp +82 -0
- data/vendor/ggml/src/ggml-cpu/arch/powerpc/quants.c +2304 -0
- data/vendor/ggml/src/ggml-cpu/arch/riscv/cpu-feats.cpp +38 -0
- data/vendor/ggml/src/ggml-cpu/arch/riscv/quants.c +4553 -0
- data/vendor/ggml/src/ggml-cpu/arch/riscv/repack.cpp +1703 -0
- data/vendor/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp +50 -0
- data/vendor/ggml/src/ggml-cpu/arch/s390/quants.c +1465 -0
- data/vendor/ggml/src/ggml-cpu/arch/wasm/quants.c +1220 -0
- data/vendor/ggml/src/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
- data/vendor/ggml/src/ggml-cpu/arch/x86/quants.c +3970 -0
- data/vendor/ggml/src/ggml-cpu/arch/x86/repack.cpp +6407 -0
- data/vendor/ggml/src/ggml-cpu/arch-fallback.h +348 -0
- data/vendor/ggml/src/ggml-cpu/binary-ops.cpp +154 -0
- data/vendor/ggml/src/ggml-cpu/binary-ops.h +16 -0
- data/vendor/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
- data/vendor/ggml/src/ggml-cpu/cmake/FindSMTIME.cmake +32 -0
- data/vendor/ggml/src/ggml-cpu/common.h +95 -0
- data/vendor/ggml/src/ggml-cpu/ggml-cpu-impl.h +539 -0
- data/vendor/ggml/src/ggml-cpu/ggml-cpu.c +3835 -0
- data/vendor/ggml/src/ggml-cpu/ggml-cpu.cpp +703 -0
- data/vendor/ggml/src/ggml-cpu/hbm.cpp +55 -0
- data/vendor/ggml/src/ggml-cpu/hbm.h +8 -0
- data/vendor/ggml/src/ggml-cpu/kleidiai/kernels.cpp +939 -0
- data/vendor/ggml/src/ggml-cpu/kleidiai/kernels.h +90 -0
- data/vendor/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +1513 -0
- data/vendor/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
- data/vendor/ggml/src/ggml-cpu/llamafile/sgemm.cpp +4051 -0
- data/vendor/ggml/src/ggml-cpu/llamafile/sgemm.h +25 -0
- data/vendor/ggml/src/ggml-cpu/ops.cpp +11373 -0
- data/vendor/ggml/src/ggml-cpu/ops.h +119 -0
- data/vendor/ggml/src/ggml-cpu/quants.c +1288 -0
- data/vendor/ggml/src/ggml-cpu/quants.h +103 -0
- data/vendor/ggml/src/ggml-cpu/repack.cpp +4836 -0
- data/vendor/ggml/src/ggml-cpu/repack.h +245 -0
- data/vendor/ggml/src/ggml-cpu/simd-gemm.h +226 -0
- data/vendor/ggml/src/ggml-cpu/simd-mappings.h +1319 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime.cpp +1740 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime.h +21 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime1_kernels.cpp +1027 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime2_kernels.cpp +5768 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime_env.cpp +320 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime_env.h +55 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime_kernels.h +189 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/repack.cpp +1795 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/repack.h +14 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/rvv_kernels.cpp +3178 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/rvv_kernels.h +95 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/spine_barrier.h +34 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/spine_mem_pool.cpp +760 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/spine_mem_pool.h +32 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/spine_tcm.h +409 -0
- data/vendor/ggml/src/ggml-cpu/traits.cpp +36 -0
- data/vendor/ggml/src/ggml-cpu/traits.h +38 -0
- data/vendor/ggml/src/ggml-cpu/unary-ops.cpp +337 -0
- data/vendor/ggml/src/ggml-cpu/unary-ops.h +35 -0
- data/vendor/ggml/src/ggml-cpu/vec.cpp +629 -0
- data/vendor/ggml/src/ggml-cpu/vec.h +1588 -0
- data/vendor/ggml/src/ggml-cuda/CMakeLists.txt +268 -0
- data/vendor/ggml/src/ggml-cuda/acc.cu +61 -0
- data/vendor/ggml/src/ggml-cuda/acc.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/add-id.cu +58 -0
- data/vendor/ggml/src/ggml-cuda/add-id.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/allreduce.cu +971 -0
- data/vendor/ggml/src/ggml-cuda/allreduce.cuh +29 -0
- data/vendor/ggml/src/ggml-cuda/arange.cu +34 -0
- data/vendor/ggml/src/ggml-cuda/arange.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/argmax.cu +91 -0
- data/vendor/ggml/src/ggml-cuda/argmax.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/argsort.cu +266 -0
- data/vendor/ggml/src/ggml-cuda/argsort.cuh +19 -0
- data/vendor/ggml/src/ggml-cuda/binbcast.cu +534 -0
- data/vendor/ggml/src/ggml-cuda/binbcast.cuh +12 -0
- data/vendor/ggml/src/ggml-cuda/clamp.cu +45 -0
- data/vendor/ggml/src/ggml-cuda/clamp.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/common.cuh +1489 -0
- data/vendor/ggml/src/ggml-cuda/concat.cu +204 -0
- data/vendor/ggml/src/ggml-cuda/concat.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/conv-transpose-1d.cu +86 -0
- data/vendor/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/conv2d-dw.cu +161 -0
- data/vendor/ggml/src/ggml-cuda/conv2d-dw.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/conv2d-transpose.cu +115 -0
- data/vendor/ggml/src/ggml-cuda/conv2d-transpose.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/conv2d.cu +166 -0
- data/vendor/ggml/src/ggml-cuda/conv2d.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/convert.cu +892 -0
- data/vendor/ggml/src/ggml-cuda/convert.cuh +66 -0
- data/vendor/ggml/src/ggml-cuda/count-equal.cu +64 -0
- data/vendor/ggml/src/ggml-cuda/count-equal.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/cp-async.cuh +57 -0
- data/vendor/ggml/src/ggml-cuda/cpy-utils.cuh +217 -0
- data/vendor/ggml/src/ggml-cuda/cpy.cu +558 -0
- data/vendor/ggml/src/ggml-cuda/cpy.cuh +7 -0
- data/vendor/ggml/src/ggml-cuda/cross-entropy-loss.cu +177 -0
- data/vendor/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
- data/vendor/ggml/src/ggml-cuda/cumsum.cu +307 -0
- data/vendor/ggml/src/ggml-cuda/cumsum.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/dequantize.cuh +99 -0
- data/vendor/ggml/src/ggml-cuda/diag.cu +77 -0
- data/vendor/ggml/src/ggml-cuda/diag.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/diagmask.cu +40 -0
- data/vendor/ggml/src/ggml-cuda/diagmask.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/fattn-common.cuh +1212 -0
- data/vendor/ggml/src/ggml-cuda/fattn-mma-f16.cuh +2020 -0
- data/vendor/ggml/src/ggml-cuda/fattn-tile.cu +61 -0
- data/vendor/ggml/src/ggml-cuda/fattn-tile.cuh +1347 -0
- data/vendor/ggml/src/ggml-cuda/fattn-vec.cuh +600 -0
- data/vendor/ggml/src/ggml-cuda/fattn-wmma-f16.cu +696 -0
- data/vendor/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +51 -0
- data/vendor/ggml/src/ggml-cuda/fattn.cu +562 -0
- data/vendor/ggml/src/ggml-cuda/fattn.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/fill.cu +37 -0
- data/vendor/ggml/src/ggml-cuda/fill.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/gated_delta_net.cu +311 -0
- data/vendor/ggml/src/ggml-cuda/gated_delta_net.cuh +4 -0
- data/vendor/ggml/src/ggml-cuda/getrows.cu +300 -0
- data/vendor/ggml/src/ggml-cuda/getrows.cuh +15 -0
- data/vendor/ggml/src/ggml-cuda/ggml-cuda.cu +5684 -0
- data/vendor/ggml/src/ggml-cuda/gla.cu +93 -0
- data/vendor/ggml/src/ggml-cuda/gla.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/im2col.cu +267 -0
- data/vendor/ggml/src/ggml-cuda/im2col.cuh +6 -0
- data/vendor/ggml/src/ggml-cuda/mean.cu +75 -0
- data/vendor/ggml/src/ggml-cuda/mean.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/mma.cuh +1456 -0
- data/vendor/ggml/src/ggml-cuda/mmf.cu +191 -0
- data/vendor/ggml/src/ggml-cuda/mmf.cuh +908 -0
- data/vendor/ggml/src/ggml-cuda/mmid.cu +164 -0
- data/vendor/ggml/src/ggml-cuda/mmid.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/mmq.cu +372 -0
- data/vendor/ggml/src/ggml-cuda/mmq.cuh +4176 -0
- data/vendor/ggml/src/ggml-cuda/mmvf.cu +862 -0
- data/vendor/ggml/src/ggml-cuda/mmvf.cuh +14 -0
- data/vendor/ggml/src/ggml-cuda/mmvq.cu +1161 -0
- data/vendor/ggml/src/ggml-cuda/mmvq.cuh +16 -0
- data/vendor/ggml/src/ggml-cuda/norm.cu +672 -0
- data/vendor/ggml/src/ggml-cuda/norm.cuh +18 -0
- data/vendor/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
- data/vendor/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/opt-step-sgd.cu +49 -0
- data/vendor/ggml/src/ggml-cuda/opt-step-sgd.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/out-prod.cu +84 -0
- data/vendor/ggml/src/ggml-cuda/out-prod.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/pad.cu +106 -0
- data/vendor/ggml/src/ggml-cuda/pad.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/pad_reflect_1d.cu +91 -0
- data/vendor/ggml/src/ggml-cuda/pad_reflect_1d.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/pool2d.cu +94 -0
- data/vendor/ggml/src/ggml-cuda/pool2d.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/quantize.cu +443 -0
- data/vendor/ggml/src/ggml-cuda/quantize.cuh +41 -0
- data/vendor/ggml/src/ggml-cuda/reduce_rows.cuh +39 -0
- data/vendor/ggml/src/ggml-cuda/roll.cu +67 -0
- data/vendor/ggml/src/ggml-cuda/roll.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/rope.cu +665 -0
- data/vendor/ggml/src/ggml-cuda/rope.cuh +9 -0
- data/vendor/ggml/src/ggml-cuda/scale.cu +34 -0
- data/vendor/ggml/src/ggml-cuda/scale.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/set-rows.cu +330 -0
- data/vendor/ggml/src/ggml-cuda/set-rows.cuh +7 -0
- data/vendor/ggml/src/ggml-cuda/set.cu +39 -0
- data/vendor/ggml/src/ggml-cuda/set.cuh +7 -0
- data/vendor/ggml/src/ggml-cuda/snake.cu +72 -0
- data/vendor/ggml/src/ggml-cuda/snake.cuh +8 -0
- data/vendor/ggml/src/ggml-cuda/softcap.cu +34 -0
- data/vendor/ggml/src/ggml-cuda/softcap.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/softmax.cu +472 -0
- data/vendor/ggml/src/ggml-cuda/softmax.cuh +7 -0
- data/vendor/ggml/src/ggml-cuda/solve_tri.cu +275 -0
- data/vendor/ggml/src/ggml-cuda/solve_tri.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/ssm-conv.cu +197 -0
- data/vendor/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/ssm-scan.cu +342 -0
- data/vendor/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/sum.cu +41 -0
- data/vendor/ggml/src/ggml-cuda/sum.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/sumrows.cu +43 -0
- data/vendor/ggml/src/ggml-cuda/sumrows.cuh +4 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +6 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_32.cu +6 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +6 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_32.cu +6 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +6 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq112-dv112.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq128-dv128.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq192-dv128.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq256-dv256.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq320-dv256.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq40-dv40.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq512-dv512.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq576-dv512.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq64-dv64.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq72-dv72.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq80-dv80.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq96-dv96.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/generate_cu_files.py +110 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_1.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_10.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_11.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_12.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_13.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_14.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_15.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_16.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_2.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_3.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_4.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_5.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_6.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_7.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_8.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_9.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-mxfp4.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-nvfp4.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q1_0.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/top-k.cu +95 -0
- data/vendor/ggml/src/ggml-cuda/top-k.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/topk-moe.cu +415 -0
- data/vendor/ggml/src/ggml-cuda/topk-moe.cuh +27 -0
- data/vendor/ggml/src/ggml-cuda/tri.cu +136 -0
- data/vendor/ggml/src/ggml-cuda/tri.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/tsembd.cu +47 -0
- data/vendor/ggml/src/ggml-cuda/tsembd.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/unary.cu +640 -0
- data/vendor/ggml/src/ggml-cuda/unary.cuh +114 -0
- data/vendor/ggml/src/ggml-cuda/upscale.cu +293 -0
- data/vendor/ggml/src/ggml-cuda/upscale.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/vecdotq.cuh +1317 -0
- data/vendor/ggml/src/ggml-cuda/vendors/cuda.h +28 -0
- data/vendor/ggml/src/ggml-cuda/vendors/hip.h +304 -0
- data/vendor/ggml/src/ggml-cuda/vendors/musa.h +150 -0
- data/vendor/ggml/src/ggml-cuda/wkv.cu +199 -0
- data/vendor/ggml/src/ggml-cuda/wkv.cuh +7 -0
- data/vendor/ggml/src/ggml-hexagon/CMakeLists.txt +118 -0
- data/vendor/ggml/src/ggml-hexagon/ggml-hexagon.cpp +3680 -0
- data/vendor/ggml/src/ggml-hexagon/htp/CMakeLists.txt +78 -0
- data/vendor/ggml/src/ggml-hexagon/htp/act-ops.c +782 -0
- data/vendor/ggml/src/ggml-hexagon/htp/argsort-ops.c +293 -0
- data/vendor/ggml/src/ggml-hexagon/htp/binary-ops.c +872 -0
- data/vendor/ggml/src/ggml-hexagon/htp/cmake-toolchain.cmake +157 -0
- data/vendor/ggml/src/ggml-hexagon/htp/cpy-ops.c +275 -0
- data/vendor/ggml/src/ggml-hexagon/htp/cumsum-ops.c +270 -0
- data/vendor/ggml/src/ggml-hexagon/htp/diag-ops.c +216 -0
- data/vendor/ggml/src/ggml-hexagon/htp/fill-ops.c +123 -0
- data/vendor/ggml/src/ggml-hexagon/htp/flash-attn-ops.c +727 -0
- data/vendor/ggml/src/ggml-hexagon/htp/gated-delta-net-ops.c +955 -0
- data/vendor/ggml/src/ggml-hexagon/htp/get-rows-ops.c +124 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hex-dma.c +63 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hex-dma.h +372 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hex-dump.h +86 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hex-fastdiv.h +37 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hex-utils.h +137 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-flash-attn-ops.c +1841 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-matmul-ops.c +1785 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-ops.h +71 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-profile.h +34 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-queue.c +158 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-queue.h +134 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-utils.h +200 -0
- data/vendor/ggml/src/ggml-hexagon/htp/htp-ctx.h +111 -0
- data/vendor/ggml/src/ggml-hexagon/htp/htp-ops.h +181 -0
- data/vendor/ggml/src/ggml-hexagon/htp/htp_iface.idl +22 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-arith.h +443 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-base.h +308 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-copy.h +262 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-div.h +291 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-dump.h +129 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-exp.h +216 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-floor.h +100 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-inverse.h +210 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-reduce.h +296 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-repl.h +74 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-scale.h +133 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-sigmoid.h +142 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-sqrt.h +126 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-types.h +36 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-utils.h +19 -0
- data/vendor/ggml/src/ggml-hexagon/htp/main.c +880 -0
- data/vendor/ggml/src/ggml-hexagon/htp/matmul-ops.c +3173 -0
- data/vendor/ggml/src/ggml-hexagon/htp/repeat-ops.c +148 -0
- data/vendor/ggml/src/ggml-hexagon/htp/rope-ops.c +494 -0
- data/vendor/ggml/src/ggml-hexagon/htp/set-rows-ops.c +184 -0
- data/vendor/ggml/src/ggml-hexagon/htp/softmax-ops.c +407 -0
- data/vendor/ggml/src/ggml-hexagon/htp/solve-tri-ops.c +267 -0
- data/vendor/ggml/src/ggml-hexagon/htp/ssm-conv.c +340 -0
- data/vendor/ggml/src/ggml-hexagon/htp/sum-rows-ops.c +128 -0
- data/vendor/ggml/src/ggml-hexagon/htp/unary-ops.c +657 -0
- data/vendor/ggml/src/ggml-hexagon/htp/vtcm-utils.h +16 -0
- data/vendor/ggml/src/ggml-hexagon/htp/worker-pool.c +293 -0
- data/vendor/ggml/src/ggml-hexagon/htp/worker-pool.h +57 -0
- data/vendor/ggml/src/ggml-hexagon/htp-drv.cpp +418 -0
- data/vendor/ggml/src/ggml-hexagon/htp-drv.h +121 -0
- data/vendor/ggml/src/ggml-hexagon/libdl.h +79 -0
- data/vendor/ggml/src/ggml-hexagon/libggml-htp.inf +40 -0
- data/vendor/ggml/src/ggml-hexagon/op-desc.h +153 -0
- data/vendor/ggml/src/ggml-hip/CMakeLists.txt +157 -0
- data/vendor/ggml/src/ggml-impl.h +783 -0
- data/vendor/ggml/src/ggml-metal/CMakeLists.txt +124 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-common.cpp +457 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-common.h +52 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-context.h +41 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-context.m +739 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-device.cpp +2053 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-device.h +296 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-device.m +1829 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-impl.h +1175 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-ops.cpp +4606 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-ops.h +97 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal.cpp +950 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal.metal +10679 -0
- data/vendor/ggml/src/ggml-musa/CMakeLists.txt +124 -0
- data/vendor/ggml/src/ggml-musa/mudnn.cu +112 -0
- data/vendor/ggml/src/ggml-musa/mudnn.cuh +12 -0
- data/vendor/ggml/src/ggml-opencl/CMakeLists.txt +189 -0
- data/vendor/ggml/src/ggml-opencl/ggml-opencl.cpp +16374 -0
- data/vendor/ggml/src/ggml-opencl/kernels/add.cl +190 -0
- data/vendor/ggml/src/ggml-opencl/kernels/add_id.cl +42 -0
- data/vendor/ggml/src/ggml-opencl/kernels/argsort.cl +86 -0
- data/vendor/ggml/src/ggml-opencl/kernels/clamp.cl +20 -0
- data/vendor/ggml/src/ggml-opencl/kernels/concat.cl +51 -0
- data/vendor/ggml/src/ggml-opencl/kernels/conv2d.cl +185 -0
- data/vendor/ggml/src/ggml-opencl/kernels/conv2d_f16_f32.cl +176 -0
- data/vendor/ggml/src/ggml-opencl/kernels/cpy.cl +229 -0
- data/vendor/ggml/src/ggml-opencl/kernels/cumsum.cl +139 -0
- data/vendor/ggml/src/ggml-opencl/kernels/cvt.cl +1471 -0
- data/vendor/ggml/src/ggml-opencl/kernels/diag.cl +27 -0
- data/vendor/ggml/src/ggml-opencl/kernels/diag_mask_inf.cl +58 -0
- data/vendor/ggml/src/ggml-opencl/kernels/div.cl +138 -0
- data/vendor/ggml/src/ggml-opencl/kernels/embed_kernel.py +26 -0
- data/vendor/ggml/src/ggml-opencl/kernels/exp.cl +125 -0
- data/vendor/ggml/src/ggml-opencl/kernels/expm1.cl +113 -0
- data/vendor/ggml/src/ggml-opencl/kernels/fill.cl +17 -0
- data/vendor/ggml/src/ggml-opencl/kernels/flash_attn_f16.cl +370 -0
- data/vendor/ggml/src/ggml-opencl/kernels/flash_attn_f32.cl +371 -0
- data/vendor/ggml/src/ggml-opencl/kernels/flash_attn_f32_f16.cl +373 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gelu.cl +89 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_mxfp4_f32.cl +162 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_mxfp4_f32_ns.cl +302 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_q4_0_f32_ns.cl +252 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_q4_1_f32_ns.cl +254 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_q5_0_f32_ns.cl +256 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_q5_1_f32_ns.cl +258 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_iq4_nl_f32.cl +150 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q4_0_f32.cl +139 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q4_1_f32.cl +132 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q4_k_f32.cl +172 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q5_k_f32.cl +176 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q6_k_f32.cl +140 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q8_0_f32.cl +129 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_xmem_f16_f32_os8.cl +233 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_mxfp4_f32.cl +156 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_mxfp4_f32_ns.cl +161 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_q4_0_f32_ns.cl +116 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_q4_1_f32_ns.cl +119 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_q5_0_f32_ns.cl +119 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_q5_1_f32_ns.cl +121 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_iq4_nl_f32.cl +302 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q4_0_f32.cl +274 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q4_0_f32_spec.cl +268 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q4_1_f32.cl +283 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q4_k_f32.cl +318 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q5_k_f32.cl +326 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q6_k_f32.cl +293 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q8_0_f32.cl +195 -0
- data/vendor/ggml/src/ggml-opencl/kernels/get_rows.cl +187 -0
- data/vendor/ggml/src/ggml-opencl/kernels/glu.cl +378 -0
- data/vendor/ggml/src/ggml-opencl/kernels/group_norm.cl +121 -0
- data/vendor/ggml/src/ggml-opencl/kernels/im2col_f16.cl +57 -0
- data/vendor/ggml/src/ggml-opencl/kernels/im2col_f32.cl +57 -0
- data/vendor/ggml/src/ggml-opencl/kernels/l2_norm.cl +71 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mean.cl +140 -0
- data/vendor/ggml/src/ggml-opencl/kernels/moe_reorder_b.cl +30 -0
- data/vendor/ggml/src/ggml-opencl/kernels/moe_sort_by_expert.cl +82 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul.cl +152 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mat_f16_f32.cl +130 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_f16_f32_kq_kqv.cl +273 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_f16_f32_l4_lm.cl +146 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_f32_f32_l4_lm.cl +147 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_iq4_nl_f32_l4_lm.cl +171 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q4_0_f32_l4_lm.cl +163 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q4_1_f32_l4_lm.cl +165 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q4_k_f32_l4_lm.cl +179 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q5_k_f32_l4_lm.cl +192 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q6_k_f32_l4_lm.cl +158 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q8_0_f32_l4_lm.cl +154 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_f16_f16.cl +118 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32.cl +118 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_1row.cl +94 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_l4.cl +84 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_f32_f32.cl +118 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_id_mxfp4_f32.cl +189 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_id_mxfp4_f32_flat.cl +176 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_id_q4_0_f32_8x_flat.cl +283 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_id_q8_0_f32.cl +140 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_id_q8_0_f32_flat.cl +222 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_iq4_nl_f32.cl +164 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_iq4_nl_f32_flat.cl +202 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_mxfp4_f32.cl +144 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_mxfp4_f32_flat.cl +167 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32.cl +192 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_1d_16x_flat.cl +307 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_1d_8x_flat.cl +265 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_8x_flat.cl +272 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_v.cl +254 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_1_f32.cl +219 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_1_f32_flat.cl +229 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_k_f32.cl +180 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_k_f32_flat.cl +196 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q5_k_f32.cl +187 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q5_k_f32_flat.cl +203 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q6_k_f32.cl +194 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q6_k_f32_flat.cl +194 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q8_0_f32.cl +125 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q8_0_f32_flat.cl +202 -0
- data/vendor/ggml/src/ggml-opencl/kernels/neg.cl +125 -0
- data/vendor/ggml/src/ggml-opencl/kernels/norm.cl +161 -0
- data/vendor/ggml/src/ggml-opencl/kernels/pad.cl +39 -0
- data/vendor/ggml/src/ggml-opencl/kernels/relu.cl +16 -0
- data/vendor/ggml/src/ggml-opencl/kernels/repeat.cl +38 -0
- data/vendor/ggml/src/ggml-opencl/kernels/rms_norm.cl +190 -0
- data/vendor/ggml/src/ggml-opencl/kernels/rope.cl +747 -0
- data/vendor/ggml/src/ggml-opencl/kernels/scale.cl +27 -0
- data/vendor/ggml/src/ggml-opencl/kernels/set_rows.cl +208 -0
- data/vendor/ggml/src/ggml-opencl/kernels/sigmoid.cl +29 -0
- data/vendor/ggml/src/ggml-opencl/kernels/silu.cl +30 -0
- data/vendor/ggml/src/ggml-opencl/kernels/softmax_4_f16.cl +108 -0
- data/vendor/ggml/src/ggml-opencl/kernels/softmax_4_f32.cl +108 -0
- data/vendor/ggml/src/ggml-opencl/kernels/softmax_f16.cl +107 -0
- data/vendor/ggml/src/ggml-opencl/kernels/softmax_f32.cl +107 -0
- data/vendor/ggml/src/ggml-opencl/kernels/softplus.cl +116 -0
- data/vendor/ggml/src/ggml-opencl/kernels/solve_tri.cl +51 -0
- data/vendor/ggml/src/ggml-opencl/kernels/sqr.cl +53 -0
- data/vendor/ggml/src/ggml-opencl/kernels/sqrt.cl +53 -0
- data/vendor/ggml/src/ggml-opencl/kernels/ssm_conv.cl +77 -0
- data/vendor/ggml/src/ggml-opencl/kernels/sub.cl +138 -0
- data/vendor/ggml/src/ggml-opencl/kernels/sum_rows.cl +140 -0
- data/vendor/ggml/src/ggml-opencl/kernels/tanh.cl +109 -0
- data/vendor/ggml/src/ggml-opencl/kernels/transpose.cl +143 -0
- data/vendor/ggml/src/ggml-opencl/kernels/tri.cl +32 -0
- data/vendor/ggml/src/ggml-opencl/kernels/tsembd.cl +48 -0
- data/vendor/ggml/src/ggml-opencl/kernels/upscale.cl +120 -0
- data/vendor/ggml/src/ggml-openvino/CMakeLists.txt +22 -0
- data/vendor/ggml/src/ggml-openvino/ggml-decoder.cpp +985 -0
- data/vendor/ggml/src/ggml-openvino/ggml-decoder.h +294 -0
- data/vendor/ggml/src/ggml-openvino/ggml-openvino-extra.cpp +380 -0
- data/vendor/ggml/src/ggml-openvino/ggml-openvino-extra.h +182 -0
- data/vendor/ggml/src/ggml-openvino/ggml-openvino.cpp +1132 -0
- data/vendor/ggml/src/ggml-openvino/ggml-quants.cpp +956 -0
- data/vendor/ggml/src/ggml-openvino/ggml-quants.h +153 -0
- data/vendor/ggml/src/ggml-openvino/openvino/decoder.h +74 -0
- data/vendor/ggml/src/ggml-openvino/openvino/frontend.cpp +27 -0
- data/vendor/ggml/src/ggml-openvino/openvino/frontend.h +23 -0
- data/vendor/ggml/src/ggml-openvino/openvino/input_model.cpp +17 -0
- data/vendor/ggml/src/ggml-openvino/openvino/input_model.h +29 -0
- data/vendor/ggml/src/ggml-openvino/openvino/node_context.h +112 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/cont.cpp +48 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/cpy.cpp +21 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/flash_attn_ext.cpp +90 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/get_rows.cpp +69 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/glu_geglu.cpp +61 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/glu_swiglu.cpp +62 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/mulmat.cpp +90 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/permute.cpp +102 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/reshape.cpp +83 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/rms_norm.cpp +46 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/rope.cpp +149 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/scale.cpp +41 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/set_rows.cpp +76 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/softmax.cpp +89 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/transpose.cpp +23 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/unary_gelu.cpp +25 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/unary_silu.cpp +27 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/view.cpp +53 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op_table.cpp +47 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op_table.h +40 -0
- data/vendor/ggml/src/ggml-openvino/openvino/pass/fuse_to_sdpa.cpp +60 -0
- data/vendor/ggml/src/ggml-openvino/openvino/pass/fuse_to_sdpa.h +17 -0
- data/vendor/ggml/src/ggml-openvino/openvino/pass/mark_decompression_convert_constant_folding.h +29 -0
- data/vendor/ggml/src/ggml-openvino/openvino/pass/squeeze_matmul.cpp +58 -0
- data/vendor/ggml/src/ggml-openvino/openvino/pass/squeeze_matmul.h +17 -0
- data/vendor/ggml/src/ggml-openvino/openvino/rt_info/weightless_caching_attributes.hpp +41 -0
- data/vendor/ggml/src/ggml-openvino/openvino/translate_session.cpp +317 -0
- data/vendor/ggml/src/ggml-openvino/openvino/translate_session.h +28 -0
- data/vendor/ggml/src/ggml-openvino/openvino/utils.cpp +257 -0
- data/vendor/ggml/src/ggml-openvino/openvino/utils.h +86 -0
- data/vendor/ggml/src/ggml-openvino/utils.cpp +880 -0
- data/vendor/ggml/src/ggml-openvino/utils.h +143 -0
- data/vendor/ggml/src/ggml-opt.cpp +1094 -0
- data/vendor/ggml/src/ggml-quants.c +5491 -0
- data/vendor/ggml/src/ggml-quants.h +112 -0
- data/vendor/ggml/src/ggml-rpc/CMakeLists.txt +33 -0
- data/vendor/ggml/src/ggml-rpc/ggml-rpc.cpp +1974 -0
- data/vendor/ggml/src/ggml-rpc/transport.cpp +683 -0
- data/vendor/ggml/src/ggml-rpc/transport.h +34 -0
- data/vendor/ggml/src/ggml-sycl/CMakeLists.txt +207 -0
- data/vendor/ggml/src/ggml-sycl/add-id.cpp +81 -0
- data/vendor/ggml/src/ggml-sycl/add-id.hpp +8 -0
- data/vendor/ggml/src/ggml-sycl/backend.hpp +48 -0
- data/vendor/ggml/src/ggml-sycl/binbcast.cpp +346 -0
- data/vendor/ggml/src/ggml-sycl/binbcast.hpp +39 -0
- data/vendor/ggml/src/ggml-sycl/common.cpp +155 -0
- data/vendor/ggml/src/ggml-sycl/common.hpp +1002 -0
- data/vendor/ggml/src/ggml-sycl/concat.cpp +202 -0
- data/vendor/ggml/src/ggml-sycl/concat.hpp +20 -0
- data/vendor/ggml/src/ggml-sycl/conv.cpp +101 -0
- data/vendor/ggml/src/ggml-sycl/conv.hpp +20 -0
- data/vendor/ggml/src/ggml-sycl/convert.cpp +825 -0
- data/vendor/ggml/src/ggml-sycl/convert.hpp +64 -0
- data/vendor/ggml/src/ggml-sycl/count-equal.cpp +79 -0
- data/vendor/ggml/src/ggml-sycl/count-equal.hpp +9 -0
- data/vendor/ggml/src/ggml-sycl/cpy.cpp +602 -0
- data/vendor/ggml/src/ggml-sycl/cpy.hpp +223 -0
- data/vendor/ggml/src/ggml-sycl/cumsum.cpp +148 -0
- data/vendor/ggml/src/ggml-sycl/cumsum.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/dequantize.hpp +975 -0
- data/vendor/ggml/src/ggml-sycl/diag.cpp +67 -0
- data/vendor/ggml/src/ggml-sycl/diag.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/dmmv.cpp +1579 -0
- data/vendor/ggml/src/ggml-sycl/dmmv.hpp +27 -0
- data/vendor/ggml/src/ggml-sycl/dpct/helper.hpp +3774 -0
- data/vendor/ggml/src/ggml-sycl/element_wise.cpp +1124 -0
- data/vendor/ggml/src/ggml-sycl/element_wise.hpp +94 -0
- data/vendor/ggml/src/ggml-sycl/fattn-buffers.cpp +56 -0
- data/vendor/ggml/src/ggml-sycl/fattn-buffers.hpp +63 -0
- data/vendor/ggml/src/ggml-sycl/fattn-common.hpp +1181 -0
- data/vendor/ggml/src/ggml-sycl/fattn-tile.cpp +59 -0
- data/vendor/ggml/src/ggml-sycl/fattn-tile.hpp +1246 -0
- data/vendor/ggml/src/ggml-sycl/fattn-vec.hpp +674 -0
- data/vendor/ggml/src/ggml-sycl/fattn.cpp +227 -0
- data/vendor/ggml/src/ggml-sycl/fattn.hpp +22 -0
- data/vendor/ggml/src/ggml-sycl/fill.cpp +55 -0
- data/vendor/ggml/src/ggml-sycl/fill.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/gated_delta_net.cpp +307 -0
- data/vendor/ggml/src/ggml-sycl/gated_delta_net.hpp +9 -0
- data/vendor/ggml/src/ggml-sycl/gemm.hpp +93 -0
- data/vendor/ggml/src/ggml-sycl/getrows.cpp +219 -0
- data/vendor/ggml/src/ggml-sycl/getrows.hpp +20 -0
- data/vendor/ggml/src/ggml-sycl/ggml-sycl.cpp +5520 -0
- data/vendor/ggml/src/ggml-sycl/gla.cpp +106 -0
- data/vendor/ggml/src/ggml-sycl/gla.hpp +8 -0
- data/vendor/ggml/src/ggml-sycl/im2col.cpp +400 -0
- data/vendor/ggml/src/ggml-sycl/im2col.hpp +23 -0
- data/vendor/ggml/src/ggml-sycl/mmq.cpp +3030 -0
- data/vendor/ggml/src/ggml-sycl/mmq.hpp +33 -0
- data/vendor/ggml/src/ggml-sycl/mmvq.cpp +1380 -0
- data/vendor/ggml/src/ggml-sycl/mmvq.hpp +43 -0
- data/vendor/ggml/src/ggml-sycl/norm.cpp +656 -0
- data/vendor/ggml/src/ggml-sycl/norm.hpp +28 -0
- data/vendor/ggml/src/ggml-sycl/outprod.cpp +47 -0
- data/vendor/ggml/src/ggml-sycl/outprod.hpp +10 -0
- data/vendor/ggml/src/ggml-sycl/pad.cpp +97 -0
- data/vendor/ggml/src/ggml-sycl/pad.hpp +24 -0
- data/vendor/ggml/src/ggml-sycl/pad_reflect_1d.cpp +100 -0
- data/vendor/ggml/src/ggml-sycl/pad_reflect_1d.hpp +10 -0
- data/vendor/ggml/src/ggml-sycl/presets.hpp +79 -0
- data/vendor/ggml/src/ggml-sycl/quantize.hpp +133 -0
- data/vendor/ggml/src/ggml-sycl/quants.hpp +156 -0
- data/vendor/ggml/src/ggml-sycl/repeat_back.cpp +76 -0
- data/vendor/ggml/src/ggml-sycl/repeat_back.hpp +8 -0
- data/vendor/ggml/src/ggml-sycl/roll.cpp +122 -0
- data/vendor/ggml/src/ggml-sycl/roll.hpp +20 -0
- data/vendor/ggml/src/ggml-sycl/rope.cpp +641 -0
- data/vendor/ggml/src/ggml-sycl/rope.hpp +26 -0
- data/vendor/ggml/src/ggml-sycl/set.cpp +73 -0
- data/vendor/ggml/src/ggml-sycl/set.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/set_rows.cpp +240 -0
- data/vendor/ggml/src/ggml-sycl/set_rows.hpp +8 -0
- data/vendor/ggml/src/ggml-sycl/softmax.cpp +426 -0
- data/vendor/ggml/src/ggml-sycl/softmax.hpp +24 -0
- data/vendor/ggml/src/ggml-sycl/solve_tri.cpp +172 -0
- data/vendor/ggml/src/ggml-sycl/solve_tri.hpp +8 -0
- data/vendor/ggml/src/ggml-sycl/ssm_conv.cpp +132 -0
- data/vendor/ggml/src/ggml-sycl/ssm_conv.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/ssm_scan.cpp +156 -0
- data/vendor/ggml/src/ggml-sycl/ssm_scan.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/sycl_hw.cpp +67 -0
- data/vendor/ggml/src/ggml-sycl/sycl_hw.hpp +38 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq112-dv112.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq128-dv128.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq256-dv256.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq40-dv40.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq512-dv512.cpp +6 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq576-dv512.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq64-dv64.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq72-dv72.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq80-dv80.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq96-dv96.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/tsembd.cpp +73 -0
- data/vendor/ggml/src/ggml-sycl/tsembd.hpp +20 -0
- data/vendor/ggml/src/ggml-sycl/type.hpp +112 -0
- data/vendor/ggml/src/ggml-sycl/upscale.cpp +410 -0
- data/vendor/ggml/src/ggml-sycl/upscale.hpp +9 -0
- data/vendor/ggml/src/ggml-sycl/vecdotq.hpp +1508 -0
- data/vendor/ggml/src/ggml-sycl/wkv.cpp +293 -0
- data/vendor/ggml/src/ggml-sycl/wkv.hpp +10 -0
- data/vendor/ggml/src/ggml-threading.cpp +12 -0
- data/vendor/ggml/src/ggml-threading.h +14 -0
- data/vendor/ggml/src/ggml-virtgpu/CMakeLists.txt +70 -0
- data/vendor/ggml/src/ggml-virtgpu/apir_cs_ggml-rpc-front.cpp +87 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/CMakeLists.txt +21 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/apir_cs_ggml-rpc-back.cpp +115 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-convert.h +13 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched-backend.cpp +102 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched-buffer-type.cpp +105 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched-buffer.cpp +179 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched-device.cpp +148 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched.cpp +51 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched.gen.h +73 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched.h +27 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-virgl-apir.h +32 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend.cpp +144 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/api_remoting.h +95 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/apir_backend.gen.h +94 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/apir_backend.h +50 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/apir_cs.h +378 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/apir_cs_ggml.h +232 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/apir_cs_rpc.h +58 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-backend-buffer-type.cpp +81 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-backend-buffer.cpp +123 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-backend-device.cpp +160 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-backend-reg.cpp +213 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-backend.cpp +71 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-remoting.h +71 -0
- data/vendor/ggml/src/ggml-virtgpu/ggmlremoting_functions.yaml +166 -0
- data/vendor/ggml/src/ggml-virtgpu/include/apir_hw.h +9 -0
- data/vendor/ggml/src/ggml-virtgpu/regenerate_remoting.py +333 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-apir.h +15 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward-backend.cpp +58 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward-buffer-type.cpp +110 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward-buffer.cpp +173 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward-device.cpp +192 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward-impl.h +36 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward.gen.h +53 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-shm.cpp +99 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-shm.h +23 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-utils.cpp +179 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-utils.h +86 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu.cpp +545 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu.h +115 -0
- data/vendor/ggml/src/ggml-vulkan/CMakeLists.txt +220 -0
- data/vendor/ggml/src/ggml-vulkan/cmake/host-toolchain.cmake.in +15 -0
- data/vendor/ggml/src/ggml-vulkan/ggml-vulkan.cpp +17208 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +31 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/abs.comp +21 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/acc.comp +37 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/add.comp +69 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/add1.comp +28 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/add_id.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/arange.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/argmax.comp +60 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/argsort.comp +86 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/argsort_large.comp +114 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/ceil.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/concat.comp +41 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/contig_copy.comp +49 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_dw.comp +105 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_mm.comp +347 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/conv_transpose_1d.comp +98 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/copy.comp +23 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/copy_from_quant.comp +51 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp +320 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/copy_transpose.comp +67 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/cos.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/count_equal.comp +31 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/count_experts.comp +51 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/cumsum.comp +83 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/cumsum_multipass1.comp +60 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/cumsum_multipass2.comp +66 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_f32.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs.glsl +653 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs_cm2.glsl +768 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_head.glsl +13 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_m.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_s.comp +35 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_s.comp +44 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xs.comp +43 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xxs.comp +49 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_s.comp +40 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_xxs.comp +51 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_nl.comp +32 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_xs.comp +34 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_mxfp4.comp +32 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_nvfp4.comp +32 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q1_0.comp +29 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q2_k.comp +34 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q3_k.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_0.comp +30 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_1.comp +32 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_k.comp +68 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_0.comp +34 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_1.comp +35 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_k.comp +70 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q6_k.comp +33 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q8_0.comp +31 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp +28 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/diag_mask_inf.comp +34 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/div.comp +27 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/elu.comp +27 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/exp.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/feature-tests/bfloat16.comp +7 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/feature-tests/coopmat.comp +7 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/feature-tests/coopmat2.comp +7 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/feature-tests/integer_dot.comp +7 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/fill.comp +19 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +756 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_base.glsl +255 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +626 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +427 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_dequant.glsl +123 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_mask_opt.comp +162 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_mmq_funcs.glsl +203 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_split_k_reduce.comp +121 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/floor.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/gated_delta_net.comp +190 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/geglu.comp +13 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/geglu_erf.comp +27 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/geglu_quick.comp +11 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/gelu.comp +25 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/gelu_erf.comp +39 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/gelu_quick.comp +23 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/generic_binary_head.glsl +65 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/generic_head.glsl +11 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/generic_unary_head.glsl +83 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/get_rows.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/get_rows_quant.comp +51 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/glu_head.glsl +28 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/glu_main.glsl +39 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/group_norm.comp +66 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/hardsigmoid.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/hardswish.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/im2col.comp +93 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/im2col_3d.comp +124 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +44 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/leaky_relu.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/log.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul.comp +27 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_split_k_reduce.comp +48 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec.comp +169 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_base.glsl +230 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iface.glsl +35 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_m.comp +132 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_s.comp +95 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_s.comp +90 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xs.comp +105 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xxs.comp +87 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_s.comp +90 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_xxs.comp +88 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_nc.comp +124 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_p021.comp +156 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q2_k.comp +128 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q3_k.comp +132 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q4_k.comp +134 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q5_k.comp +165 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q6_k.comp +130 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq.comp +143 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq_funcs.glsl +503 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +464 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +624 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_funcs.glsl +600 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_id_funcs.glsl +74 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp +311 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.glsl +454 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_shmem_types.glsl +93 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/multi_add.comp +194 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/neg.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/norm.comp +44 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/opt_step_adamw.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/opt_step_sgd.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/pad.comp +64 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/pool2d.comp +74 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/quantize_q8_1.comp +127 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/reglu.comp +9 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/relu.comp +21 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/repeat.comp +26 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/repeat_back.comp +37 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm.comp +150 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm_back.comp +55 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm_partials.comp +65 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/roll.comp +46 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_funcs.glsl +207 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_head.glsl +19 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_multi.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_neox.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_norm.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_params.glsl +31 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_vision.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/round.comp +29 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/scale.comp +24 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sgn.comp +21 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sigmoid.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/silu.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/silu_back.comp +26 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sin.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max.comp +195 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_back.comp +54 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large1.comp +62 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large2.comp +79 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large3.comp +65 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large_common.glsl +53 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/softplus.comp +23 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/solve_tri.comp +81 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sqrt.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/square.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/ssm_conv.comp +50 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/ssm_scan.comp +124 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/step.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sub.comp +29 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sum_rows.comp +47 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sum_rows.glsl +25 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/swiglu.comp +9 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/swiglu_oai.comp +14 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/tanh.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/timestep_embedding.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/topk_argsort.comp +118 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/topk_moe.comp +213 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/topk_nary_search.comp +246 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/trunc.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/types.glsl +1846 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/upscale.comp +178 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/utils.glsl +25 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +1183 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/wkv6.comp +87 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/wkv7.comp +91 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/xielu.comp +35 -0
- data/vendor/ggml/src/ggml-webgpu/CMakeLists.txt +80 -0
- data/vendor/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp +3231 -0
- data/vendor/ggml/src/ggml-webgpu/ggml-webgpu.cpp +4461 -0
- data/vendor/ggml/src/ggml-webgpu/pre_wgsl.hpp +778 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/add_id.wgsl +64 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/argmax.wgsl +72 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/argsort.wgsl +106 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/argsort_merge.wgsl +134 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/binary.wgsl +139 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/common_decls.tmpl +905 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/concat.wgsl +75 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/conv2d.wgsl +165 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/cpy.wgsl +81 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/cumsum.wgsl +66 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/embed_wgsl.py +89 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn.wgsl +706 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_tile.wgsl +351 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_blk.wgsl +101 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_reduce.wgsl +84 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_split.wgsl +720 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/gated_delta_net.wgsl +132 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/get_rows.wgsl +773 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/glu.wgsl +155 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/im2col.wgsl +101 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/memset.wgsl +40 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat.wgsl +747 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_decls.tmpl +1210 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id.wgsl +195 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id_gather.wgsl +55 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id_vec.wgsl +154 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_reg_tile.wgsl +149 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_subgroup_matrix.wgsl +200 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec.wgsl +133 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec_acc.tmpl +1433 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/pad.wgsl +86 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/repeat.wgsl +67 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/rms_norm_mul.wgsl +152 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/rope.wgsl +224 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/row_norm.wgsl +153 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/scale.wgsl +63 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/set.wgsl +109 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/set_rows.wgsl +109 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/soft_max.wgsl +245 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/solve_tri.wgsl +121 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/ssm_conv.wgsl +65 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/ssm_scan.wgsl +193 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/sum_rows.wgsl +55 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/unary.wgsl +210 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/upscale.wgsl +240 -0
- data/vendor/ggml/src/ggml-zdnn/CMakeLists.txt +36 -0
- data/vendor/ggml/src/ggml-zdnn/common.hpp +59 -0
- data/vendor/ggml/src/ggml-zdnn/ggml-zdnn.cpp +637 -0
- data/vendor/ggml/src/ggml-zdnn/mmf.cpp +80 -0
- data/vendor/ggml/src/ggml-zdnn/mmf.hpp +12 -0
- data/vendor/ggml/src/ggml-zdnn/utils.cpp +79 -0
- data/vendor/ggml/src/ggml-zdnn/utils.hpp +19 -0
- data/vendor/ggml/src/ggml-zendnn/CMakeLists.txt +91 -0
- data/vendor/ggml/src/ggml-zendnn/ggml-zendnn.cpp +669 -0
- data/vendor/ggml/src/ggml.c +7777 -0
- data/vendor/ggml/src/ggml.cpp +26 -0
- data/vendor/ggml/src/gguf.cpp +1556 -0
- data/vendor/ggml/tests/CMakeLists.txt +356 -0
- data/vendor/ggml/tests/test-arange.cpp +100 -0
- data/vendor/ggml/tests/test-backend-ops.cpp +9786 -0
- data/vendor/ggml/tests/test-cont.c +170 -0
- data/vendor/ggml/tests/test-conv-transpose-1d.cpp +691 -0
- data/vendor/ggml/tests/test-conv-transpose.c +248 -0
- data/vendor/ggml/tests/test-conv1d-dw-c1.cpp +243 -0
- data/vendor/ggml/tests/test-conv1d-dw-c2.cpp +243 -0
- data/vendor/ggml/tests/test-conv1d.cpp +289 -0
- data/vendor/ggml/tests/test-conv2d-dw.cpp +153 -0
- data/vendor/ggml/tests/test-conv2d.cpp +391 -0
- data/vendor/ggml/tests/test-customop.c +300 -0
- data/vendor/ggml/tests/test-dup.c +111 -0
- data/vendor/ggml/tests/test-interpolate.cpp +166 -0
- data/vendor/ggml/tests/test-opt.cpp +1003 -0
- data/vendor/ggml/tests/test-pad-reflect-1d.cpp +213 -0
- data/vendor/ggml/tests/test-pool.c +274 -0
- data/vendor/ggml/tests/test-quantize-fns.cpp +196 -0
- data/vendor/ggml/tests/test-quantize-perf.cpp +356 -0
- data/vendor/ggml/tests/test-rel-pos.c +87 -0
- data/vendor/ggml/tests/test-roll.cpp +128 -0
- data/vendor/ggml/tests/test-timestep_embedding.cpp +180 -0
- data/vendor-patches/0001-cuda-buffer_from_ptr.patch +253 -0
- data/vendor-patches/0002-cuda-buffer_from_ptr-reuse-iface.patch +117 -0
- data/vendor-patches/0003-cuda-buffer_from_ptr-copy-mode.patch +128 -0
- data/vendor-patches/0004-cuda-cpy-strided.patch +61 -0
- data/vendor-patches/0005-concat-backward.patch +36 -0
- data/vendor-patches/0006-getrows-back-large-vocab.patch +69 -0
- data/vendor-patches/0007-gpt2-backward-kernels.patch +438 -0
- data/vendor-patches/0008-mul-mat-backward-mixed-precision.patch +50 -0
- data/vendor-patches/0009-sched-unsupported-node-diagnostic.patch +26 -0
- metadata +2161 -0
|
@@ -0,0 +1,2370 @@
|
|
|
1
|
+
#define _USE_MATH_DEFINES // for M_PI
|
|
2
|
+
#define _CRT_SECURE_NO_DEPRECATE // Disables ridiculous "unsafe" warnigns on Windows
|
|
3
|
+
|
|
4
|
+
#include "ggml.h"
|
|
5
|
+
#include "ggml-cpu.h"
|
|
6
|
+
#include "ggml-alloc.h"
|
|
7
|
+
#include "ggml-backend.h"
|
|
8
|
+
#define STB_IMAGE_IMPLEMENTATION
|
|
9
|
+
#include "stb_image.h"
|
|
10
|
+
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|
11
|
+
#include "stb_image_write.h"
|
|
12
|
+
|
|
13
|
+
#include <cassert>
|
|
14
|
+
#include <cmath>
|
|
15
|
+
#include <cstddef>
|
|
16
|
+
#include <cstdio>
|
|
17
|
+
#include <cstring>
|
|
18
|
+
#include <fstream>
|
|
19
|
+
#include <map>
|
|
20
|
+
#include <string>
|
|
21
|
+
#include <vector>
|
|
22
|
+
#include <thread>
|
|
23
|
+
#include <cinttypes>
|
|
24
|
+
|
|
25
|
+
#if defined(_MSC_VER)
|
|
26
|
+
#pragma warning(disable: 4244 4267) // possible loss of data
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
// default hparams (ViT-B SAM)
|
|
30
|
+
struct sam_hparams {
|
|
31
|
+
int32_t n_enc_state = 768;
|
|
32
|
+
int32_t n_enc_layer = 12;
|
|
33
|
+
int32_t n_enc_head = 12;
|
|
34
|
+
int32_t n_enc_out_chans = 256;
|
|
35
|
+
int32_t n_pt_embd = 4;
|
|
36
|
+
int32_t n_dec_heads = 8;
|
|
37
|
+
int32_t ftype = 1;
|
|
38
|
+
float mask_threshold = 0.f;
|
|
39
|
+
float iou_threshold = 0.88f;
|
|
40
|
+
float stability_score_threshold = 0.95f;
|
|
41
|
+
float stability_score_offset = 1.0f;
|
|
42
|
+
float eps = 1e-6f;
|
|
43
|
+
float eps_decoder_transformer = 1e-5f;
|
|
44
|
+
|
|
45
|
+
int32_t n_enc_head_dim() const { return n_enc_state / n_enc_head; }
|
|
46
|
+
int32_t n_img_size() const { return 1024; }
|
|
47
|
+
int32_t n_window_size() const { return 14; }
|
|
48
|
+
int32_t n_patch_size() const { return 16; }
|
|
49
|
+
int32_t n_img_embd() const { return n_img_size() / n_patch_size(); }
|
|
50
|
+
|
|
51
|
+
std::vector<int32_t> global_attn_indices() const {
|
|
52
|
+
switch (n_enc_state) {
|
|
53
|
+
case 768: return { 2, 5, 8, 11 };
|
|
54
|
+
case 1024: return { 5, 11, 17, 23 };
|
|
55
|
+
case 1280: return { 7, 15, 23, 31 };
|
|
56
|
+
default:
|
|
57
|
+
{
|
|
58
|
+
fprintf(stderr, "%s: unsupported n_enc_state = %d\n", __func__, n_enc_state);
|
|
59
|
+
} break;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
bool is_global_attn(int32_t layer) const {
|
|
66
|
+
const auto indices = global_attn_indices();
|
|
67
|
+
|
|
68
|
+
for (const auto & idx : indices) {
|
|
69
|
+
if (layer == idx) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
struct sam_layer_enc {
|
|
79
|
+
struct ggml_tensor * norm1_w;
|
|
80
|
+
struct ggml_tensor * norm1_b;
|
|
81
|
+
|
|
82
|
+
struct ggml_tensor * rel_pos_w;
|
|
83
|
+
struct ggml_tensor * rel_pos_h;
|
|
84
|
+
|
|
85
|
+
struct ggml_tensor * qkv_w;
|
|
86
|
+
struct ggml_tensor * qkv_b;
|
|
87
|
+
|
|
88
|
+
struct ggml_tensor * proj_w;
|
|
89
|
+
struct ggml_tensor * proj_b;
|
|
90
|
+
|
|
91
|
+
struct ggml_tensor * norm2_w;
|
|
92
|
+
struct ggml_tensor * norm2_b;
|
|
93
|
+
|
|
94
|
+
struct ggml_tensor * mlp_lin1_w;
|
|
95
|
+
struct ggml_tensor * mlp_lin1_b;
|
|
96
|
+
|
|
97
|
+
struct ggml_tensor * mlp_lin2_w;
|
|
98
|
+
struct ggml_tensor * mlp_lin2_b;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
struct sam_encoder_image {
|
|
102
|
+
struct ggml_tensor * pe;
|
|
103
|
+
|
|
104
|
+
struct ggml_tensor * proj_w;
|
|
105
|
+
struct ggml_tensor * proj_b;
|
|
106
|
+
|
|
107
|
+
struct ggml_tensor * neck_conv_0;
|
|
108
|
+
struct ggml_tensor * neck_norm_0_w;
|
|
109
|
+
struct ggml_tensor * neck_norm_0_b;
|
|
110
|
+
struct ggml_tensor * neck_conv_1;
|
|
111
|
+
struct ggml_tensor * neck_norm_1_w;
|
|
112
|
+
struct ggml_tensor * neck_norm_1_b;
|
|
113
|
+
|
|
114
|
+
std::vector<sam_layer_enc> layers;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
struct sam_encoder_prompt {
|
|
118
|
+
struct ggml_tensor * pe;
|
|
119
|
+
|
|
120
|
+
struct ggml_tensor * not_a_pt_embd_w;
|
|
121
|
+
std::vector<struct ggml_tensor *> pt_embd;
|
|
122
|
+
|
|
123
|
+
struct ggml_tensor * no_mask_embd_w;
|
|
124
|
+
//std::vector<struct ggml_tensor *> mask_down_w;
|
|
125
|
+
//std::vector<struct ggml_tensor *> mask_down_b;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
struct sam_layer_dec_transformer_attn {
|
|
129
|
+
// q_proj
|
|
130
|
+
struct ggml_tensor * q_w;
|
|
131
|
+
struct ggml_tensor * q_b;
|
|
132
|
+
|
|
133
|
+
// k_proj
|
|
134
|
+
struct ggml_tensor * k_w;
|
|
135
|
+
struct ggml_tensor * k_b;
|
|
136
|
+
|
|
137
|
+
// v_proj
|
|
138
|
+
struct ggml_tensor * v_w;
|
|
139
|
+
struct ggml_tensor * v_b;
|
|
140
|
+
|
|
141
|
+
// out_proj
|
|
142
|
+
struct ggml_tensor * out_w;
|
|
143
|
+
struct ggml_tensor * out_b;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
struct sam_layer_dec_transformer {
|
|
147
|
+
sam_layer_dec_transformer_attn self_attn;
|
|
148
|
+
|
|
149
|
+
// norm1
|
|
150
|
+
struct ggml_tensor * norm1_w;
|
|
151
|
+
struct ggml_tensor * norm1_b;
|
|
152
|
+
|
|
153
|
+
sam_layer_dec_transformer_attn cross_attn_token_to_img;
|
|
154
|
+
|
|
155
|
+
// norm2
|
|
156
|
+
struct ggml_tensor * norm2_w;
|
|
157
|
+
struct ggml_tensor * norm2_b;
|
|
158
|
+
|
|
159
|
+
// mlp.lin1
|
|
160
|
+
struct ggml_tensor * mlp_lin1_w;
|
|
161
|
+
struct ggml_tensor * mlp_lin1_b;
|
|
162
|
+
|
|
163
|
+
// mlp.lin2
|
|
164
|
+
struct ggml_tensor * mlp_lin2_w;
|
|
165
|
+
struct ggml_tensor * mlp_lin2_b;
|
|
166
|
+
|
|
167
|
+
// norm3
|
|
168
|
+
struct ggml_tensor * norm3_w;
|
|
169
|
+
struct ggml_tensor * norm3_b;
|
|
170
|
+
|
|
171
|
+
// norm4
|
|
172
|
+
struct ggml_tensor * norm4_w;
|
|
173
|
+
struct ggml_tensor * norm4_b;
|
|
174
|
+
|
|
175
|
+
sam_layer_dec_transformer_attn cross_attn_img_to_token;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
struct sam_layer_dec_output_hypernet_mlps {
|
|
179
|
+
// mlps_*.layers.0
|
|
180
|
+
struct ggml_tensor * w_0;
|
|
181
|
+
struct ggml_tensor * b_0;
|
|
182
|
+
|
|
183
|
+
// mlps_*.layers.1
|
|
184
|
+
struct ggml_tensor * w_1;
|
|
185
|
+
struct ggml_tensor * b_1;
|
|
186
|
+
|
|
187
|
+
// mlps_*.layers.2
|
|
188
|
+
struct ggml_tensor * w_2;
|
|
189
|
+
struct ggml_tensor * b_2;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
struct sam_decoder_mask {
|
|
193
|
+
std::vector<sam_layer_dec_transformer> transformer_layers;
|
|
194
|
+
|
|
195
|
+
// trasnformer.final_attn_token_to_image
|
|
196
|
+
sam_layer_dec_transformer_attn transformer_final_attn_token_to_img;
|
|
197
|
+
|
|
198
|
+
// transformer.norm_final
|
|
199
|
+
struct ggml_tensor * transformer_norm_final_w;
|
|
200
|
+
struct ggml_tensor * transformer_norm_final_b;
|
|
201
|
+
|
|
202
|
+
// output_upscaling.0
|
|
203
|
+
struct ggml_tensor * output_upscaling_0_w;
|
|
204
|
+
struct ggml_tensor * output_upscaling_0_b;
|
|
205
|
+
|
|
206
|
+
// output_upscaling.1
|
|
207
|
+
struct ggml_tensor * output_upscaling_1_w;
|
|
208
|
+
struct ggml_tensor * output_upscaling_1_b;
|
|
209
|
+
|
|
210
|
+
// output_upscaling.3
|
|
211
|
+
struct ggml_tensor * output_upscaling_3_w;
|
|
212
|
+
struct ggml_tensor * output_upscaling_3_b;
|
|
213
|
+
|
|
214
|
+
// output_hypernetworks_mlps
|
|
215
|
+
std::vector<sam_layer_dec_output_hypernet_mlps> output_hypernet_mlps;
|
|
216
|
+
|
|
217
|
+
// iou_prediction_head.0
|
|
218
|
+
struct ggml_tensor * iou_prediction_head_0_w;
|
|
219
|
+
struct ggml_tensor * iou_prediction_head_0_b;
|
|
220
|
+
|
|
221
|
+
// iou_prediction_head.1
|
|
222
|
+
struct ggml_tensor * iou_prediction_head_1_w;
|
|
223
|
+
struct ggml_tensor * iou_prediction_head_1_b;
|
|
224
|
+
|
|
225
|
+
// iou_prediction_head.2
|
|
226
|
+
struct ggml_tensor * iou_prediction_head_2_w;
|
|
227
|
+
struct ggml_tensor * iou_prediction_head_2_b;
|
|
228
|
+
|
|
229
|
+
// iou_token.weight
|
|
230
|
+
struct ggml_tensor * iou_token_w;
|
|
231
|
+
|
|
232
|
+
// mask_tokens.weight
|
|
233
|
+
struct ggml_tensor * mask_tokens_w;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
struct sam_state {
|
|
238
|
+
struct ggml_tensor * embd_img;
|
|
239
|
+
|
|
240
|
+
struct ggml_tensor * low_res_masks;
|
|
241
|
+
struct ggml_tensor * iou_predictions;
|
|
242
|
+
|
|
243
|
+
//struct ggml_tensor * tmp_save = {};
|
|
244
|
+
|
|
245
|
+
struct ggml_context * ctx;
|
|
246
|
+
|
|
247
|
+
// buffer for `ggml_graph_plan.work_data`
|
|
248
|
+
std::vector<uint8_t> work_buffer;
|
|
249
|
+
// buffers to evaluate the model
|
|
250
|
+
std::vector<uint8_t> buf_compute_img_enc;
|
|
251
|
+
|
|
252
|
+
std::vector<uint8_t> buf_compute_fast;
|
|
253
|
+
|
|
254
|
+
ggml_gallocr_t allocr = {};
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// void save_tensor(sam_state& state, struct ggml_tensor * t, struct ggml_cgraph * gf) {
|
|
258
|
+
// if (!state.tmp_save) {
|
|
259
|
+
// state.tmp_save = ggml_new_tensor(state.ctx, t->type, t->n_dims, t->ne);
|
|
260
|
+
// }
|
|
261
|
+
// struct ggml_tensor * tmp0 = ggml_cpy(state.ctx, t, state.tmp_save);
|
|
262
|
+
// ggml_build_forward_expand(gf, tmp0);
|
|
263
|
+
// }
|
|
264
|
+
|
|
265
|
+
struct sam_model {
|
|
266
|
+
sam_hparams hparams;
|
|
267
|
+
|
|
268
|
+
sam_encoder_image enc_img;
|
|
269
|
+
sam_encoder_prompt enc_prompt;
|
|
270
|
+
sam_decoder_mask dec;
|
|
271
|
+
|
|
272
|
+
//
|
|
273
|
+
struct ggml_context * ctx;
|
|
274
|
+
std::map<std::string, struct ggml_tensor *> tensors;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
struct sam_point {
|
|
278
|
+
float x;
|
|
279
|
+
float y;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
struct sam_box {
|
|
283
|
+
float x1;
|
|
284
|
+
float y1;
|
|
285
|
+
float x2;
|
|
286
|
+
float y2;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// RGB uint8 image
|
|
290
|
+
struct sam_image_u8 {
|
|
291
|
+
int nx;
|
|
292
|
+
int ny;
|
|
293
|
+
|
|
294
|
+
std::vector<uint8_t> data;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
// RGB float32 image
|
|
298
|
+
// Memory layout: RGBRGBRGB...
|
|
299
|
+
struct sam_image_f32 {
|
|
300
|
+
int nx;
|
|
301
|
+
int ny;
|
|
302
|
+
|
|
303
|
+
std::vector<float> data;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
enum sam_prompt_type {
|
|
307
|
+
SAM_PROMPT_TYPE_POINT = 0,
|
|
308
|
+
SAM_PROMPT_TYPE_BOX = 1,
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
struct sam_prompt {
|
|
312
|
+
sam_prompt_type prompt_type = SAM_PROMPT_TYPE_POINT;
|
|
313
|
+
sam_point pt = { 414.375f, 162.796875f, };
|
|
314
|
+
sam_box box = { 368.0f, 144.0f, 441.0f, 173.0f };
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
struct sam_params {
|
|
318
|
+
int32_t seed = -1; // RNG seed
|
|
319
|
+
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
|
|
320
|
+
|
|
321
|
+
std::string model = "models/sam-vit-b/ggml-model-f16.bin"; // model path
|
|
322
|
+
std::string fname_inp = "img.jpg";
|
|
323
|
+
std::string fname_out = "img.out";
|
|
324
|
+
float mask_threshold = 0.f;
|
|
325
|
+
float iou_threshold = 0.88f;
|
|
326
|
+
float stability_score_threshold = 0.95f;
|
|
327
|
+
float stability_score_offset = 1.0f;
|
|
328
|
+
float eps = 1e-6f;
|
|
329
|
+
float eps_decoder_transformer = 1e-5f;
|
|
330
|
+
|
|
331
|
+
sam_prompt prompt;
|
|
332
|
+
bool multimask_output = true;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
void print_t_f32(const char* title, struct ggml_tensor * t, int n = 10) {
|
|
336
|
+
printf("%s\n", title);
|
|
337
|
+
float * data = (float *)t->data;
|
|
338
|
+
printf("dims: % " PRId64 " % " PRId64 " % " PRId64 " % " PRId64 " f32\n", t->ne[0], t->ne[1], t->ne[2], t->ne[3]);
|
|
339
|
+
printf("First & Last %d elements:\n", n);
|
|
340
|
+
for (int i = 0; i < std::min((int) (t->ne[0]*t->ne[1]), n); i++) {
|
|
341
|
+
printf("%.5f ", data[i]);
|
|
342
|
+
if (i != 0 && i % t->ne[0] == 0) {
|
|
343
|
+
printf("\n");
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
printf("\n");
|
|
347
|
+
for (int i = 0; i < std::min((int) (t->ne[0]*t->ne[1]), n); i++) {
|
|
348
|
+
printf("%.5f ", data[ggml_nelements(t) - n + i]);
|
|
349
|
+
if ((ggml_nelements(t) - n + i) % t->ne[0] == 0) {
|
|
350
|
+
printf("\n");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
printf("\n");
|
|
354
|
+
double sum = 0.0;
|
|
355
|
+
for (int i = 0; i < ggml_nelements(t); i++) {
|
|
356
|
+
sum += data[i];
|
|
357
|
+
}
|
|
358
|
+
printf("sum: %f\n\n", sum);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
static void ggml_disconnect_node_from_graph(ggml_tensor * t) {
|
|
362
|
+
t->op = GGML_OP_NONE;
|
|
363
|
+
for (int i = 0; i < GGML_MAX_SRC; i++) {
|
|
364
|
+
t->src[i] = NULL;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
static void ggml_graph_compute_helper(std::vector<uint8_t> & buf, ggml_cgraph * graph, int n_threads) {
|
|
369
|
+
struct ggml_cplan plan = ggml_graph_plan(graph, n_threads, nullptr);
|
|
370
|
+
|
|
371
|
+
if (plan.work_size > 0) {
|
|
372
|
+
buf.resize(plan.work_size);
|
|
373
|
+
plan.work_data = buf.data();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
ggml_graph_compute(graph, &plan);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
static void ggml_sam_sin(struct ggml_tensor * dst , const struct ggml_tensor * src, int ith, int nth, void * userdata) {
|
|
380
|
+
GGML_ASSERT(userdata == NULL);
|
|
381
|
+
GGML_ASSERT(ggml_are_same_shape(dst, src));
|
|
382
|
+
GGML_ASSERT(ggml_is_contiguous(dst));
|
|
383
|
+
GGML_ASSERT(ggml_is_contiguous(src));
|
|
384
|
+
|
|
385
|
+
const float * src_data = ggml_get_data_f32(src);
|
|
386
|
+
float * dst_data = ggml_get_data_f32(dst);
|
|
387
|
+
|
|
388
|
+
const int ne = (int)ggml_nelements(dst);
|
|
389
|
+
const int dr = (ne + nth - 1) / nth;
|
|
390
|
+
const int ie0 = dr * ith;
|
|
391
|
+
const int ie1 = std::min(ie0 + dr, ne);
|
|
392
|
+
|
|
393
|
+
for (int i = ie0; i < ie1; ++i) {
|
|
394
|
+
dst_data[i] = sinf(src_data[i]);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
static void ggml_sam_cos(struct ggml_tensor * dst , const struct ggml_tensor * src, int ith, int nth, void * userdata) {
|
|
399
|
+
GGML_ASSERT(userdata == NULL);
|
|
400
|
+
GGML_ASSERT(ggml_are_same_shape(dst, src));
|
|
401
|
+
GGML_ASSERT(ggml_is_contiguous(dst));
|
|
402
|
+
GGML_ASSERT(ggml_is_contiguous(src));
|
|
403
|
+
|
|
404
|
+
const float * src_data = ggml_get_data_f32(src);
|
|
405
|
+
float * dst_data = ggml_get_data_f32(dst);
|
|
406
|
+
|
|
407
|
+
const int ne = (int)ggml_nelements(dst);
|
|
408
|
+
const int dr = (ne + nth - 1) / nth;
|
|
409
|
+
const int ie0 = dr * ith;
|
|
410
|
+
const int ie1 = std::min(ie0 + dr, ne);
|
|
411
|
+
|
|
412
|
+
for (int i = ie0; i < ie1; ++i) {
|
|
413
|
+
dst_data[i] = cosf(src_data[i]);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
bool sam_image_load_from_file(const std::string & fname, sam_image_u8 & img) {
|
|
418
|
+
int nx, ny, nc;
|
|
419
|
+
auto data = stbi_load(fname.c_str(), &nx, &ny, &nc, 3);
|
|
420
|
+
if (!data) {
|
|
421
|
+
fprintf(stderr, "%s: failed to load '%s'\n", __func__, fname.c_str());
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
img.nx = nx;
|
|
426
|
+
img.ny = ny;
|
|
427
|
+
img.data.resize(nx * ny * 3);
|
|
428
|
+
memcpy(img.data.data(), data, nx * ny * 3);
|
|
429
|
+
|
|
430
|
+
stbi_image_free(data);
|
|
431
|
+
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/efeab7296ab579d4a261e554eca80faf6b33924a/segment_anything/modeling/sam.py#L164
|
|
436
|
+
// resize largest dimension to 1024
|
|
437
|
+
// normalize: x = (x - mean) / std
|
|
438
|
+
// mean = [123.675, 116.28, 103.53]
|
|
439
|
+
// std = [58.395, 57.12, 57.375]
|
|
440
|
+
// TODO: why are these hardcoded !?
|
|
441
|
+
// pad to 1024x1024
|
|
442
|
+
// TODO: for some reason, this is not numerically identical to pytorch's interpolation
|
|
443
|
+
bool sam_image_preprocess(const sam_image_u8 & img, sam_image_f32 & res) {
|
|
444
|
+
const int nx = img.nx;
|
|
445
|
+
const int ny = img.ny;
|
|
446
|
+
|
|
447
|
+
const int nx2 = 1024;
|
|
448
|
+
const int ny2 = 1024;
|
|
449
|
+
|
|
450
|
+
res.nx = nx2;
|
|
451
|
+
res.ny = ny2;
|
|
452
|
+
res.data.resize(3*nx2*ny2);
|
|
453
|
+
|
|
454
|
+
const float scale = std::max(nx, ny) / 1024.0f;
|
|
455
|
+
|
|
456
|
+
fprintf(stderr, "%s: scale = %f\n", __func__, scale);
|
|
457
|
+
|
|
458
|
+
const int nx3 = int(nx/scale + 0.5f);
|
|
459
|
+
const int ny3 = int(ny/scale + 0.5f);
|
|
460
|
+
|
|
461
|
+
const float m3[3] = { 123.675f, 116.280f, 103.530f };
|
|
462
|
+
const float s3[3] = { 58.395f, 57.120f, 57.375f };
|
|
463
|
+
|
|
464
|
+
for (int y = 0; y < ny3; y++) {
|
|
465
|
+
for (int x = 0; x < nx3; x++) {
|
|
466
|
+
for (int c = 0; c < 3; c++) {
|
|
467
|
+
// linear interpolation
|
|
468
|
+
const float sx = (x + 0.5f)*scale - 0.5f;
|
|
469
|
+
const float sy = (y + 0.5f)*scale - 0.5f;
|
|
470
|
+
|
|
471
|
+
const int x0 = std::max(0, (int) std::floor(sx));
|
|
472
|
+
const int y0 = std::max(0, (int) std::floor(sy));
|
|
473
|
+
|
|
474
|
+
const int x1 = std::min(x0 + 1, nx - 1);
|
|
475
|
+
const int y1 = std::min(y0 + 1, ny - 1);
|
|
476
|
+
|
|
477
|
+
const float dx = sx - x0;
|
|
478
|
+
const float dy = sy - y0;
|
|
479
|
+
|
|
480
|
+
const int j00 = 3*(y0*nx + x0) + c;
|
|
481
|
+
const int j01 = 3*(y0*nx + x1) + c;
|
|
482
|
+
const int j10 = 3*(y1*nx + x0) + c;
|
|
483
|
+
const int j11 = 3*(y1*nx + x1) + c;
|
|
484
|
+
|
|
485
|
+
const float v00 = img.data[j00];
|
|
486
|
+
const float v01 = img.data[j01];
|
|
487
|
+
const float v10 = img.data[j10];
|
|
488
|
+
const float v11 = img.data[j11];
|
|
489
|
+
|
|
490
|
+
const float v0 = v00*(1.0f - dx) + v01*dx;
|
|
491
|
+
const float v1 = v10*(1.0f - dx) + v11*dx;
|
|
492
|
+
|
|
493
|
+
const float v = v0*(1.0f - dy) + v1*dy;
|
|
494
|
+
|
|
495
|
+
const uint8_t v2 = std::min(std::max(std::round(v), 0.0f), 255.0f);
|
|
496
|
+
|
|
497
|
+
const int i = 3*(y*nx3 + x) + c;
|
|
498
|
+
|
|
499
|
+
res.data[i] = (float(v2) - m3[c]) / s3[c];
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// load the model's weights from a file
|
|
508
|
+
bool sam_model_load(const sam_params & params, sam_model & model) {
|
|
509
|
+
fprintf(stderr, "%s: loading model from '%s' - please wait ...\n", __func__, params.model.c_str());
|
|
510
|
+
|
|
511
|
+
auto fin = std::ifstream(params.model, std::ios::binary);
|
|
512
|
+
if (!fin) {
|
|
513
|
+
fprintf(stderr, "%s: failed to open '%s'\n", __func__, params.model.c_str());
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// verify magic
|
|
518
|
+
{
|
|
519
|
+
uint32_t magic;
|
|
520
|
+
fin.read((char *) &magic, sizeof(magic));
|
|
521
|
+
if (magic != 0x67676d6c) {
|
|
522
|
+
fprintf(stderr, "%s: invalid model file '%s' (bad magic)\n", __func__, params.model.c_str());
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// load hparams
|
|
528
|
+
{
|
|
529
|
+
// Override defaults with user choices
|
|
530
|
+
model.hparams.mask_threshold = params.mask_threshold;
|
|
531
|
+
model.hparams.iou_threshold = params.iou_threshold;
|
|
532
|
+
model.hparams.stability_score_threshold = params.stability_score_threshold;
|
|
533
|
+
model.hparams.stability_score_offset = params.stability_score_offset;
|
|
534
|
+
model.hparams.eps = params.eps;
|
|
535
|
+
model.hparams.eps_decoder_transformer = params.eps_decoder_transformer;
|
|
536
|
+
|
|
537
|
+
auto & hparams = model.hparams;
|
|
538
|
+
|
|
539
|
+
fin.read((char *) &hparams.n_enc_state, sizeof(hparams.n_enc_state));
|
|
540
|
+
fin.read((char *) &hparams.n_enc_layer, sizeof(hparams.n_enc_layer));
|
|
541
|
+
fin.read((char *) &hparams.n_enc_head, sizeof(hparams.n_enc_head));
|
|
542
|
+
fin.read((char *) &hparams.n_enc_out_chans, sizeof(hparams.n_enc_out_chans));
|
|
543
|
+
fin.read((char *) &hparams.n_pt_embd, sizeof(hparams.n_pt_embd));
|
|
544
|
+
fin.read((char *) &hparams.ftype, sizeof(hparams.ftype));
|
|
545
|
+
|
|
546
|
+
const int32_t qntvr = hparams.ftype / GGML_QNT_VERSION_FACTOR;
|
|
547
|
+
|
|
548
|
+
printf("%s: n_enc_state = %d\n", __func__, hparams.n_enc_state);
|
|
549
|
+
printf("%s: n_enc_layer = %d\n", __func__, hparams.n_enc_layer);
|
|
550
|
+
printf("%s: n_enc_head = %d\n", __func__, hparams.n_enc_head);
|
|
551
|
+
printf("%s: n_enc_out_chans = %d\n", __func__, hparams.n_enc_out_chans);
|
|
552
|
+
printf("%s: n_pt_embd = %d\n", __func__, hparams.n_pt_embd);
|
|
553
|
+
printf("%s: ftype = %d\n", __func__, hparams.ftype);
|
|
554
|
+
printf("%s: qntvr = %d\n", __func__, qntvr);
|
|
555
|
+
|
|
556
|
+
hparams.ftype %= GGML_QNT_VERSION_FACTOR;
|
|
557
|
+
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// for the big tensors, we have the option to store the data in 16-bit floats or quantized
|
|
561
|
+
// in order to save memory and also to speed up the computation
|
|
562
|
+
ggml_type wtype = ggml_ftype_to_ggml_type((ggml_ftype) (model.hparams.ftype));
|
|
563
|
+
if (wtype == GGML_TYPE_COUNT) {
|
|
564
|
+
fprintf(stderr, "%s: invalid model file '%s' (bad ftype value %d)\n",
|
|
565
|
+
__func__, params.model.c_str(), model.hparams.ftype);
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
auto & ctx = model.ctx;
|
|
570
|
+
|
|
571
|
+
const size_t ctx_size = [&]() {
|
|
572
|
+
size_t ctx_size = 0;
|
|
573
|
+
|
|
574
|
+
const auto & hparams = model.hparams;
|
|
575
|
+
|
|
576
|
+
const int32_t n_enc_state = hparams.n_enc_state;
|
|
577
|
+
const int32_t n_enc_layer = hparams.n_enc_layer;
|
|
578
|
+
const int32_t n_enc_head_dim = hparams.n_enc_head_dim();
|
|
579
|
+
const int32_t n_enc_out_chans = hparams.n_enc_out_chans;
|
|
580
|
+
const int32_t n_pt_embd = hparams.n_pt_embd;
|
|
581
|
+
|
|
582
|
+
const int32_t n_enc_layer_local = hparams.global_attn_indices().size();
|
|
583
|
+
const int32_t n_enc_layer_global = n_enc_layer - n_enc_layer_local;
|
|
584
|
+
|
|
585
|
+
const int32_t n_img_embd = hparams.n_img_embd();
|
|
586
|
+
const int32_t n_window_size = hparams.n_window_size();
|
|
587
|
+
const int32_t n_patch_size = hparams.n_patch_size();
|
|
588
|
+
|
|
589
|
+
// image encoder
|
|
590
|
+
{
|
|
591
|
+
ctx_size += n_enc_state*n_img_embd*n_img_embd*ggml_type_size(GGML_TYPE_F32);
|
|
592
|
+
|
|
593
|
+
ctx_size += n_enc_state*3*n_patch_size*n_patch_size*ggml_type_size(GGML_TYPE_F16);
|
|
594
|
+
ctx_size += n_enc_state*ggml_type_size(GGML_TYPE_F32);
|
|
595
|
+
|
|
596
|
+
ctx_size += n_enc_state*n_enc_out_chans*1*1*ggml_type_size(GGML_TYPE_F16);
|
|
597
|
+
ctx_size += n_enc_out_chans*n_enc_out_chans*3*3*ggml_type_size(GGML_TYPE_F16);
|
|
598
|
+
|
|
599
|
+
ctx_size += n_enc_out_chans*ggml_type_size(GGML_TYPE_F32);
|
|
600
|
+
ctx_size += n_enc_out_chans*ggml_type_size(GGML_TYPE_F32);
|
|
601
|
+
|
|
602
|
+
ctx_size += n_enc_out_chans*ggml_type_size(GGML_TYPE_F32);
|
|
603
|
+
ctx_size += n_enc_out_chans*ggml_type_size(GGML_TYPE_F32);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// image encoder layers
|
|
607
|
+
{
|
|
608
|
+
ctx_size += n_enc_layer*n_enc_state*ggml_type_size(GGML_TYPE_F32);
|
|
609
|
+
ctx_size += n_enc_layer*n_enc_state*ggml_type_size(GGML_TYPE_F32);
|
|
610
|
+
|
|
611
|
+
ctx_size += n_enc_layer_global*n_enc_head_dim*(2*n_img_embd - 1)*ggml_type_size(GGML_TYPE_F16);
|
|
612
|
+
ctx_size += n_enc_layer_global*n_enc_head_dim*(2*n_img_embd - 1)*ggml_type_size(GGML_TYPE_F16);
|
|
613
|
+
|
|
614
|
+
ctx_size += n_enc_layer_local*n_enc_head_dim*(2*n_window_size - 1)*ggml_type_size(GGML_TYPE_F16);
|
|
615
|
+
ctx_size += n_enc_layer_local*n_enc_head_dim*(2*n_window_size - 1)*ggml_type_size(GGML_TYPE_F16);
|
|
616
|
+
|
|
617
|
+
ctx_size += n_enc_layer*3*n_enc_state*n_enc_state*ggml_type_size(GGML_TYPE_F16);
|
|
618
|
+
ctx_size += n_enc_layer*3*n_enc_state* ggml_type_size(GGML_TYPE_F32);
|
|
619
|
+
|
|
620
|
+
ctx_size += n_enc_layer*n_enc_state*n_enc_state*ggml_type_size(GGML_TYPE_F16);
|
|
621
|
+
ctx_size += n_enc_layer*n_enc_state* ggml_type_size(GGML_TYPE_F32);
|
|
622
|
+
|
|
623
|
+
ctx_size += n_enc_layer*n_enc_state*ggml_type_size(GGML_TYPE_F32);
|
|
624
|
+
ctx_size += n_enc_layer*n_enc_state*ggml_type_size(GGML_TYPE_F32);
|
|
625
|
+
|
|
626
|
+
ctx_size += n_enc_layer*4*n_enc_state*n_enc_state*ggml_type_size(GGML_TYPE_F16);
|
|
627
|
+
ctx_size += n_enc_layer*4*n_enc_state* ggml_type_size(GGML_TYPE_F32);
|
|
628
|
+
|
|
629
|
+
ctx_size += n_enc_layer*4*n_enc_state*n_enc_state*ggml_type_size(GGML_TYPE_F16);
|
|
630
|
+
ctx_size += n_enc_layer*4*n_enc_state* ggml_type_size(GGML_TYPE_F32);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
ctx_size += (8 + 14*n_enc_layer)*ggml_tensor_overhead();
|
|
634
|
+
|
|
635
|
+
// prompt encoder
|
|
636
|
+
{
|
|
637
|
+
ctx_size += n_enc_out_chans*ggml_type_size(GGML_TYPE_F16); // 2*(n_enc_out_chans/2)
|
|
638
|
+
|
|
639
|
+
ctx_size += n_enc_out_chans*ggml_type_size(GGML_TYPE_F32);
|
|
640
|
+
ctx_size += n_pt_embd*n_enc_out_chans*ggml_type_size(GGML_TYPE_F32);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
ctx_size += (2 + n_pt_embd)*ggml_tensor_overhead();
|
|
644
|
+
|
|
645
|
+
// mask decoder
|
|
646
|
+
{
|
|
647
|
+
//transformer
|
|
648
|
+
{
|
|
649
|
+
const int tfm_layers_count = 2;
|
|
650
|
+
const int qkv_count = 3;
|
|
651
|
+
const int norm_count = 4;
|
|
652
|
+
const int n_hypernet_mpls_count = 4;
|
|
653
|
+
|
|
654
|
+
// self_attn
|
|
655
|
+
ctx_size += tfm_layers_count*qkv_count*n_enc_state*n_enc_state*ggml_type_size(GGML_TYPE_F16);
|
|
656
|
+
ctx_size += tfm_layers_count*qkv_count*n_enc_state* ggml_type_size(GGML_TYPE_F32);
|
|
657
|
+
ctx_size += tfm_layers_count*n_enc_state* ggml_type_size(GGML_TYPE_F32);
|
|
658
|
+
|
|
659
|
+
// all norms
|
|
660
|
+
ctx_size += tfm_layers_count*norm_count*n_enc_state*ggml_type_size(GGML_TYPE_F32);
|
|
661
|
+
ctx_size += tfm_layers_count*norm_count*n_enc_state*ggml_type_size(GGML_TYPE_F32);
|
|
662
|
+
|
|
663
|
+
// cross_attn_token_to_img
|
|
664
|
+
ctx_size += tfm_layers_count*qkv_count*n_enc_state*(n_enc_state/2)*ggml_type_size(GGML_TYPE_F16);
|
|
665
|
+
ctx_size += tfm_layers_count*qkv_count*(n_enc_state/2)* ggml_type_size(GGML_TYPE_F32);
|
|
666
|
+
ctx_size += tfm_layers_count*n_enc_state* ggml_type_size(GGML_TYPE_F32);
|
|
667
|
+
|
|
668
|
+
// mlp
|
|
669
|
+
ctx_size += tfm_layers_count*8*n_enc_out_chans*n_enc_out_chans*ggml_type_size(GGML_TYPE_F16);
|
|
670
|
+
ctx_size += tfm_layers_count*8*n_enc_out_chans* ggml_type_size(GGML_TYPE_F32);
|
|
671
|
+
ctx_size += tfm_layers_count*n_enc_out_chans*8*n_enc_out_chans*ggml_type_size(GGML_TYPE_F16);
|
|
672
|
+
ctx_size += tfm_layers_count*n_enc_out_chans* ggml_type_size(GGML_TYPE_F32);
|
|
673
|
+
|
|
674
|
+
// cross_attn_img_to_token
|
|
675
|
+
ctx_size += tfm_layers_count*qkv_count*n_enc_state*(n_enc_state/2)*ggml_type_size(GGML_TYPE_F16);
|
|
676
|
+
ctx_size += tfm_layers_count*qkv_count*(n_enc_state/2)* ggml_type_size(GGML_TYPE_F32);
|
|
677
|
+
ctx_size += tfm_layers_count*n_enc_state* ggml_type_size(GGML_TYPE_F32);
|
|
678
|
+
|
|
679
|
+
// transformer_final_attn_token_to_img
|
|
680
|
+
ctx_size += qkv_count*n_enc_state*(n_enc_state/2)*ggml_type_size(GGML_TYPE_F16);
|
|
681
|
+
ctx_size += qkv_count*(n_enc_state/2)* ggml_type_size(GGML_TYPE_F32);
|
|
682
|
+
ctx_size += n_enc_state* ggml_type_size(GGML_TYPE_F32);
|
|
683
|
+
|
|
684
|
+
// transformer_norm_final
|
|
685
|
+
ctx_size += norm_count*n_enc_state*ggml_type_size(GGML_TYPE_F32);
|
|
686
|
+
ctx_size += norm_count*n_enc_state*ggml_type_size(GGML_TYPE_F32);
|
|
687
|
+
|
|
688
|
+
// output_upscaling
|
|
689
|
+
ctx_size += n_enc_out_chans*n_img_embd*2*2*ggml_type_size(GGML_TYPE_F16);
|
|
690
|
+
ctx_size += 3*n_img_embd* ggml_type_size(GGML_TYPE_F32);
|
|
691
|
+
ctx_size += n_enc_out_chans*n_img_embd*(n_img_embd/2)*2*2*ggml_type_size(GGML_TYPE_F16);
|
|
692
|
+
ctx_size += (n_img_embd/2)* ggml_type_size(GGML_TYPE_F32);
|
|
693
|
+
|
|
694
|
+
// output_hypernetworks_mlps
|
|
695
|
+
ctx_size += n_hypernet_mpls_count*2*n_enc_out_chans*n_enc_out_chans*ggml_type_size(GGML_TYPE_F16);
|
|
696
|
+
ctx_size += n_hypernet_mpls_count*2*n_enc_out_chans* ggml_type_size(GGML_TYPE_F32);
|
|
697
|
+
ctx_size += n_hypernet_mpls_count*n_enc_out_chans*(n_img_embd/2)*ggml_type_size(GGML_TYPE_F16);
|
|
698
|
+
ctx_size += n_hypernet_mpls_count*(n_img_embd/2)* ggml_type_size(GGML_TYPE_F32);
|
|
699
|
+
|
|
700
|
+
// iou_prediction_head
|
|
701
|
+
ctx_size += 2*n_enc_out_chans*n_enc_out_chans*ggml_type_size(GGML_TYPE_F16);
|
|
702
|
+
ctx_size += 2*n_enc_out_chans* ggml_type_size(GGML_TYPE_F32);
|
|
703
|
+
ctx_size += n_pt_embd*n_enc_out_chans*ggml_type_size(GGML_TYPE_F16);
|
|
704
|
+
ctx_size += n_pt_embd* ggml_type_size(GGML_TYPE_F32);
|
|
705
|
+
|
|
706
|
+
// iou_token_w
|
|
707
|
+
ctx_size += n_enc_out_chans*ggml_type_size(GGML_TYPE_F32);
|
|
708
|
+
|
|
709
|
+
// mask_tokens_w
|
|
710
|
+
ctx_size += n_pt_embd*n_enc_out_chans*ggml_type_size(GGML_TYPE_F32);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
fprintf(stderr, "%s: ggml ctx size = %6.2f MB\n", __func__, ctx_size/(1024.0*1024.0));
|
|
714
|
+
|
|
715
|
+
return ctx_size;
|
|
716
|
+
}();
|
|
717
|
+
|
|
718
|
+
// create the ggml context
|
|
719
|
+
{
|
|
720
|
+
struct ggml_init_params params = {
|
|
721
|
+
/*.mem_size =*/ ctx_size,
|
|
722
|
+
/*.mem_buffer =*/ NULL,
|
|
723
|
+
/*.no_alloc =*/ false,
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
ctx = ggml_init(params);
|
|
727
|
+
if (!ctx) {
|
|
728
|
+
fprintf(stderr, "%s: ggml_init() failed\n", __func__);
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// prepare memory for the weights
|
|
734
|
+
{
|
|
735
|
+
const auto & hparams = model.hparams;
|
|
736
|
+
|
|
737
|
+
const int32_t n_enc_state = hparams.n_enc_state;
|
|
738
|
+
const int32_t n_enc_layer = hparams.n_enc_layer;
|
|
739
|
+
const int32_t n_enc_head_dim = hparams.n_enc_head_dim();
|
|
740
|
+
const int32_t n_enc_out_chans = hparams.n_enc_out_chans;
|
|
741
|
+
const int32_t n_pt_embd = hparams.n_pt_embd;
|
|
742
|
+
|
|
743
|
+
const int32_t n_img_embd = hparams.n_img_embd();
|
|
744
|
+
const int32_t n_window_size = hparams.n_window_size();
|
|
745
|
+
const int32_t n_patch_size = hparams.n_patch_size();
|
|
746
|
+
|
|
747
|
+
model.enc_img.layers.resize(n_enc_layer);
|
|
748
|
+
|
|
749
|
+
// image encoder
|
|
750
|
+
{
|
|
751
|
+
auto & enc = model.enc_img;
|
|
752
|
+
|
|
753
|
+
enc.pe = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, n_enc_state, n_img_embd, n_img_embd, 1);
|
|
754
|
+
|
|
755
|
+
enc.proj_w = ggml_new_tensor_4d(ctx, GGML_TYPE_F16, n_patch_size, n_patch_size, 3, n_enc_state);
|
|
756
|
+
enc.proj_b = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, 1, 1, n_enc_state);
|
|
757
|
+
|
|
758
|
+
enc.neck_conv_0 = ggml_new_tensor_4d(ctx, GGML_TYPE_F16, 1, 1, n_enc_state, n_enc_out_chans);
|
|
759
|
+
enc.neck_conv_1 = ggml_new_tensor_4d(ctx, GGML_TYPE_F16, 3, 3, n_enc_out_chans, n_enc_out_chans);
|
|
760
|
+
|
|
761
|
+
enc.neck_norm_0_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
762
|
+
enc.neck_norm_0_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
763
|
+
|
|
764
|
+
enc.neck_norm_1_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
765
|
+
enc.neck_norm_1_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
766
|
+
|
|
767
|
+
model.tensors["image_encoder.pos_embed"] = enc.pe;
|
|
768
|
+
|
|
769
|
+
model.tensors["image_encoder.patch_embed.proj.weight"] = enc.proj_w;
|
|
770
|
+
model.tensors["image_encoder.patch_embed.proj.bias"] = enc.proj_b;
|
|
771
|
+
|
|
772
|
+
model.tensors["image_encoder.neck.0.weight"] = enc.neck_conv_0;
|
|
773
|
+
model.tensors["image_encoder.neck.2.weight"] = enc.neck_conv_1;
|
|
774
|
+
|
|
775
|
+
model.tensors["image_encoder.neck.1.weight"] = enc.neck_norm_0_w;
|
|
776
|
+
model.tensors["image_encoder.neck.1.bias"] = enc.neck_norm_0_b;
|
|
777
|
+
|
|
778
|
+
model.tensors["image_encoder.neck.3.weight"] = enc.neck_norm_1_w;
|
|
779
|
+
model.tensors["image_encoder.neck.3.bias"] = enc.neck_norm_1_b;
|
|
780
|
+
|
|
781
|
+
for (int i = 0; i < n_enc_layer; ++i) {
|
|
782
|
+
auto & layer = enc.layers[i];
|
|
783
|
+
|
|
784
|
+
layer.norm1_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_state);
|
|
785
|
+
layer.norm1_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_state);
|
|
786
|
+
|
|
787
|
+
if (hparams.is_global_attn(i)) {
|
|
788
|
+
layer.rel_pos_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_head_dim, 2*n_img_embd - 1);
|
|
789
|
+
layer.rel_pos_h = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_head_dim, 2*n_img_embd - 1);
|
|
790
|
+
} else {
|
|
791
|
+
layer.rel_pos_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_head_dim, 2*n_window_size - 1);
|
|
792
|
+
layer.rel_pos_h = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_head_dim, 2*n_window_size - 1);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
layer.qkv_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_state, 3*n_enc_state);
|
|
796
|
+
layer.qkv_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 3*n_enc_state);
|
|
797
|
+
|
|
798
|
+
layer.proj_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_state, n_enc_state);
|
|
799
|
+
layer.proj_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_state);
|
|
800
|
+
|
|
801
|
+
layer.norm2_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_state);
|
|
802
|
+
layer.norm2_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_state);
|
|
803
|
+
|
|
804
|
+
layer.mlp_lin1_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_state, 4*n_enc_state);
|
|
805
|
+
layer.mlp_lin1_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 4*n_enc_state);
|
|
806
|
+
|
|
807
|
+
layer.mlp_lin2_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, 4*n_enc_state, n_enc_state);
|
|
808
|
+
layer.mlp_lin2_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_state);
|
|
809
|
+
|
|
810
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".norm1.weight"] = layer.norm1_w;
|
|
811
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".norm1.bias"] = layer.norm1_b;
|
|
812
|
+
|
|
813
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".attn.rel_pos_w"] = layer.rel_pos_w;
|
|
814
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".attn.rel_pos_h"] = layer.rel_pos_h;
|
|
815
|
+
|
|
816
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".attn.qkv.weight"] = layer.qkv_w;
|
|
817
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".attn.qkv.bias"] = layer.qkv_b;
|
|
818
|
+
|
|
819
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".attn.proj.weight"] = layer.proj_w;
|
|
820
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".attn.proj.bias"] = layer.proj_b;
|
|
821
|
+
|
|
822
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".norm2.weight"] = layer.norm2_w;
|
|
823
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".norm2.bias"] = layer.norm2_b;
|
|
824
|
+
|
|
825
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".mlp.lin1.weight"] = layer.mlp_lin1_w;
|
|
826
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".mlp.lin1.bias"] = layer.mlp_lin1_b;
|
|
827
|
+
|
|
828
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".mlp.lin2.weight"] = layer.mlp_lin2_w;
|
|
829
|
+
model.tensors["image_encoder.blocks." + std::to_string(i) + ".mlp.lin2.bias"] = layer.mlp_lin2_b;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// prompt encoder
|
|
834
|
+
{
|
|
835
|
+
auto & enc = model.enc_prompt;
|
|
836
|
+
|
|
837
|
+
enc.pe = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, n_enc_out_chans/2, 2);
|
|
838
|
+
|
|
839
|
+
enc.not_a_pt_embd_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
840
|
+
enc.no_mask_embd_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
841
|
+
|
|
842
|
+
model.tensors["prompt_encoder.pe_layer.positional_encoding_gaussian_matrix"] = enc.pe;
|
|
843
|
+
model.tensors["prompt_encoder.not_a_point_embed.weight"] = enc.not_a_pt_embd_w;
|
|
844
|
+
model.tensors["prompt_encoder.no_mask_embed.weight"] = enc.no_mask_embd_w;
|
|
845
|
+
|
|
846
|
+
enc.pt_embd.resize(n_pt_embd);
|
|
847
|
+
for (int i = 0; i < n_pt_embd; i++) {
|
|
848
|
+
enc.pt_embd[i] = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
849
|
+
|
|
850
|
+
model.tensors["prompt_encoder.point_embeddings." + std::to_string(i) + ".weight"] = enc.pt_embd[i];
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// mask decoder
|
|
855
|
+
{
|
|
856
|
+
auto & dec = model.dec;
|
|
857
|
+
auto & tfm_layers = dec.transformer_layers;
|
|
858
|
+
|
|
859
|
+
const int tfm_layers_count = 2;
|
|
860
|
+
tfm_layers.resize(tfm_layers_count);
|
|
861
|
+
for (int i = 0; i < tfm_layers_count; ++i) {
|
|
862
|
+
auto& l = tfm_layers[i];
|
|
863
|
+
l.self_attn.q_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans);
|
|
864
|
+
l.self_attn.q_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
865
|
+
l.self_attn.k_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans);
|
|
866
|
+
l.self_attn.k_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
867
|
+
l.self_attn.v_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans);
|
|
868
|
+
l.self_attn.v_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
869
|
+
l.self_attn.out_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans);
|
|
870
|
+
l.self_attn.out_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
871
|
+
|
|
872
|
+
l.norm1_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
873
|
+
l.norm1_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
874
|
+
|
|
875
|
+
l.cross_attn_token_to_img.q_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans/2);
|
|
876
|
+
l.cross_attn_token_to_img.q_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans/2);
|
|
877
|
+
l.cross_attn_token_to_img.k_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans/2);
|
|
878
|
+
l.cross_attn_token_to_img.k_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans/2);
|
|
879
|
+
l.cross_attn_token_to_img.v_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans/2);
|
|
880
|
+
l.cross_attn_token_to_img.v_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans/2);
|
|
881
|
+
l.cross_attn_token_to_img.out_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans/2, n_enc_out_chans);
|
|
882
|
+
l.cross_attn_token_to_img.out_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
883
|
+
|
|
884
|
+
l.norm2_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
885
|
+
l.norm2_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
886
|
+
|
|
887
|
+
l.mlp_lin1_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, 8*n_enc_out_chans);
|
|
888
|
+
l.mlp_lin1_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 8*n_enc_out_chans);
|
|
889
|
+
l.mlp_lin2_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, 8*n_enc_out_chans, n_enc_out_chans);
|
|
890
|
+
l.mlp_lin2_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
891
|
+
|
|
892
|
+
l.norm3_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
893
|
+
l.norm3_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
894
|
+
|
|
895
|
+
l.norm4_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
896
|
+
l.norm4_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
897
|
+
|
|
898
|
+
l.cross_attn_img_to_token.q_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans/2);
|
|
899
|
+
l.cross_attn_img_to_token.q_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans/2);
|
|
900
|
+
l.cross_attn_img_to_token.k_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans/2);
|
|
901
|
+
l.cross_attn_img_to_token.k_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans/2);
|
|
902
|
+
l.cross_attn_img_to_token.v_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans/2);
|
|
903
|
+
l.cross_attn_img_to_token.v_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans/2);
|
|
904
|
+
l.cross_attn_img_to_token.out_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans/2, n_enc_out_chans);
|
|
905
|
+
l.cross_attn_img_to_token.out_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
906
|
+
|
|
907
|
+
const auto prefix = "mask_decoder.transformer.layers." + std::to_string(i) + ".";
|
|
908
|
+
model.tensors[prefix + "self_attn.q_proj.weight"] = l.self_attn.q_w;
|
|
909
|
+
model.tensors[prefix + "self_attn.q_proj.bias"] = l.self_attn.q_b;
|
|
910
|
+
model.tensors[prefix + "self_attn.k_proj.weight"] = l.self_attn.k_w;
|
|
911
|
+
model.tensors[prefix + "self_attn.k_proj.bias"] = l.self_attn.k_b;
|
|
912
|
+
model.tensors[prefix + "self_attn.v_proj.weight"] = l.self_attn.v_w;
|
|
913
|
+
model.tensors[prefix + "self_attn.v_proj.bias"] = l.self_attn.v_b;
|
|
914
|
+
model.tensors[prefix + "self_attn.out_proj.weight"] = l.self_attn.out_w;
|
|
915
|
+
model.tensors[prefix + "self_attn.out_proj.bias"] = l.self_attn.out_b;
|
|
916
|
+
|
|
917
|
+
model.tensors[prefix + "norm1.weight"] = l.norm1_w;
|
|
918
|
+
model.tensors[prefix + "norm1.bias"] = l.norm1_b;
|
|
919
|
+
|
|
920
|
+
model.tensors[prefix + "cross_attn_token_to_image.q_proj.weight"] = l.cross_attn_token_to_img.q_w;
|
|
921
|
+
model.tensors[prefix + "cross_attn_token_to_image.q_proj.bias"] = l.cross_attn_token_to_img.q_b;
|
|
922
|
+
model.tensors[prefix + "cross_attn_token_to_image.k_proj.weight"] = l.cross_attn_token_to_img.k_w;
|
|
923
|
+
model.tensors[prefix + "cross_attn_token_to_image.k_proj.bias"] = l.cross_attn_token_to_img.k_b;
|
|
924
|
+
model.tensors[prefix + "cross_attn_token_to_image.v_proj.weight"] = l.cross_attn_token_to_img.v_w;
|
|
925
|
+
model.tensors[prefix + "cross_attn_token_to_image.v_proj.bias"] = l.cross_attn_token_to_img.v_b;
|
|
926
|
+
model.tensors[prefix + "cross_attn_token_to_image.out_proj.weight"] = l.cross_attn_token_to_img.out_w;
|
|
927
|
+
model.tensors[prefix + "cross_attn_token_to_image.out_proj.bias"] = l.cross_attn_token_to_img.out_b;
|
|
928
|
+
|
|
929
|
+
model.tensors[prefix + "norm2.weight"] = l.norm2_w;
|
|
930
|
+
model.tensors[prefix + "norm2.bias"] = l.norm2_b;
|
|
931
|
+
|
|
932
|
+
model.tensors[prefix + "mlp.lin1.weight"] = l.mlp_lin1_w;
|
|
933
|
+
model.tensors[prefix + "mlp.lin1.bias"] = l.mlp_lin1_b;
|
|
934
|
+
model.tensors[prefix + "mlp.lin2.weight"] = l.mlp_lin2_w;
|
|
935
|
+
model.tensors[prefix + "mlp.lin2.bias"] = l.mlp_lin2_b;
|
|
936
|
+
|
|
937
|
+
model.tensors[prefix + "norm3.weight"] = l.norm3_w;
|
|
938
|
+
model.tensors[prefix + "norm3.bias"] = l.norm3_b;
|
|
939
|
+
model.tensors[prefix + "norm4.weight"] = l.norm4_w;
|
|
940
|
+
model.tensors[prefix + "norm4.bias"] = l.norm4_b;
|
|
941
|
+
|
|
942
|
+
model.tensors[prefix + "cross_attn_image_to_token.q_proj.weight"] = l.cross_attn_img_to_token.q_w;
|
|
943
|
+
model.tensors[prefix + "cross_attn_image_to_token.q_proj.bias"] = l.cross_attn_img_to_token.q_b;
|
|
944
|
+
model.tensors[prefix + "cross_attn_image_to_token.k_proj.weight"] = l.cross_attn_img_to_token.k_w;
|
|
945
|
+
model.tensors[prefix + "cross_attn_image_to_token.k_proj.bias"] = l.cross_attn_img_to_token.k_b;
|
|
946
|
+
model.tensors[prefix + "cross_attn_image_to_token.v_proj.weight"] = l.cross_attn_img_to_token.v_w;
|
|
947
|
+
model.tensors[prefix + "cross_attn_image_to_token.v_proj.bias"] = l.cross_attn_img_to_token.v_b;
|
|
948
|
+
model.tensors[prefix + "cross_attn_image_to_token.out_proj.weight"] = l.cross_attn_img_to_token.out_w;
|
|
949
|
+
model.tensors[prefix + "cross_attn_image_to_token.out_proj.bias"] = l.cross_attn_img_to_token.out_b;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
dec.transformer_final_attn_token_to_img.q_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans/2);
|
|
953
|
+
dec.transformer_final_attn_token_to_img.q_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans/2);
|
|
954
|
+
dec.transformer_final_attn_token_to_img.k_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans/2);
|
|
955
|
+
dec.transformer_final_attn_token_to_img.k_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans/2);
|
|
956
|
+
dec.transformer_final_attn_token_to_img.v_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans/2);
|
|
957
|
+
dec.transformer_final_attn_token_to_img.v_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans/2);
|
|
958
|
+
dec.transformer_final_attn_token_to_img.out_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans/2, n_enc_out_chans);
|
|
959
|
+
dec.transformer_final_attn_token_to_img.out_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
960
|
+
|
|
961
|
+
model.tensors["mask_decoder.transformer.final_attn_token_to_image.q_proj.weight"] = dec.transformer_final_attn_token_to_img.q_w;
|
|
962
|
+
model.tensors["mask_decoder.transformer.final_attn_token_to_image.q_proj.bias"] = dec.transformer_final_attn_token_to_img.q_b;
|
|
963
|
+
model.tensors["mask_decoder.transformer.final_attn_token_to_image.k_proj.weight"] = dec.transformer_final_attn_token_to_img.k_w;
|
|
964
|
+
model.tensors["mask_decoder.transformer.final_attn_token_to_image.k_proj.bias"] = dec.transformer_final_attn_token_to_img.k_b;
|
|
965
|
+
model.tensors["mask_decoder.transformer.final_attn_token_to_image.v_proj.weight"] = dec.transformer_final_attn_token_to_img.v_w;
|
|
966
|
+
model.tensors["mask_decoder.transformer.final_attn_token_to_image.v_proj.bias"] = dec.transformer_final_attn_token_to_img.v_b;
|
|
967
|
+
model.tensors["mask_decoder.transformer.final_attn_token_to_image.out_proj.weight"] = dec.transformer_final_attn_token_to_img.out_w;
|
|
968
|
+
model.tensors["mask_decoder.transformer.final_attn_token_to_image.out_proj.bias"] = dec.transformer_final_attn_token_to_img.out_b;
|
|
969
|
+
|
|
970
|
+
dec.transformer_norm_final_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
971
|
+
dec.transformer_norm_final_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
972
|
+
|
|
973
|
+
model.tensors["mask_decoder.transformer.norm_final_attn.weight"] = dec.transformer_norm_final_w;
|
|
974
|
+
model.tensors["mask_decoder.transformer.norm_final_attn.bias"] = dec.transformer_norm_final_b;
|
|
975
|
+
|
|
976
|
+
dec.output_upscaling_0_w = ggml_new_tensor_4d(ctx, GGML_TYPE_F16, 2, 2, n_img_embd, n_enc_out_chans);
|
|
977
|
+
dec.output_upscaling_0_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_img_embd);
|
|
978
|
+
dec.output_upscaling_1_w = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_img_embd);
|
|
979
|
+
dec.output_upscaling_1_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_img_embd);
|
|
980
|
+
dec.output_upscaling_3_w = ggml_new_tensor_4d(ctx, GGML_TYPE_F16, 2, 2, n_img_embd/2, n_img_embd);
|
|
981
|
+
dec.output_upscaling_3_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_img_embd/2);
|
|
982
|
+
|
|
983
|
+
model.tensors["mask_decoder.output_upscaling.0.weight"] = dec.output_upscaling_0_w;
|
|
984
|
+
model.tensors["mask_decoder.output_upscaling.0.bias"] = dec.output_upscaling_0_b;
|
|
985
|
+
model.tensors["mask_decoder.output_upscaling.1.weight"] = dec.output_upscaling_1_w;
|
|
986
|
+
model.tensors["mask_decoder.output_upscaling.1.bias"] = dec.output_upscaling_1_b;
|
|
987
|
+
model.tensors["mask_decoder.output_upscaling.3.weight"] = dec.output_upscaling_3_w;
|
|
988
|
+
model.tensors["mask_decoder.output_upscaling.3.bias"] = dec.output_upscaling_3_b;
|
|
989
|
+
|
|
990
|
+
const int n_hypernet_mpls_count = 4;
|
|
991
|
+
dec.output_hypernet_mlps.resize(n_hypernet_mpls_count);
|
|
992
|
+
for (int i = 0; i < n_hypernet_mpls_count; ++i) {
|
|
993
|
+
auto& mlp = dec.output_hypernet_mlps[i];
|
|
994
|
+
|
|
995
|
+
mlp.w_0 = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans);
|
|
996
|
+
mlp.b_0 = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
997
|
+
mlp.w_1 = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans);
|
|
998
|
+
mlp.b_1 = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
999
|
+
mlp.w_2 = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_img_embd/2);
|
|
1000
|
+
mlp.b_2 = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_img_embd/2);
|
|
1001
|
+
|
|
1002
|
+
const auto prefix = "mask_decoder.output_hypernetworks_mlps." + std::to_string(i) + ".";
|
|
1003
|
+
model.tensors[prefix + "layers.0.weight"] = mlp.w_0;
|
|
1004
|
+
model.tensors[prefix + "layers.0.bias"] = mlp.b_0;
|
|
1005
|
+
model.tensors[prefix + "layers.1.weight"] = mlp.w_1;
|
|
1006
|
+
model.tensors[prefix + "layers.1.bias"] = mlp.b_1;
|
|
1007
|
+
model.tensors[prefix + "layers.2.weight"] = mlp.w_2;
|
|
1008
|
+
model.tensors[prefix + "layers.2.bias"] = mlp.b_2;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
dec.iou_prediction_head_0_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans);
|
|
1012
|
+
dec.iou_prediction_head_0_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
1013
|
+
dec.iou_prediction_head_1_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_enc_out_chans);
|
|
1014
|
+
dec.iou_prediction_head_1_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_enc_out_chans);
|
|
1015
|
+
dec.iou_prediction_head_2_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F16, n_enc_out_chans, n_pt_embd);
|
|
1016
|
+
dec.iou_prediction_head_2_b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_pt_embd);
|
|
1017
|
+
|
|
1018
|
+
dec.iou_token_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, n_enc_out_chans, 1);
|
|
1019
|
+
dec.mask_tokens_w = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, n_enc_out_chans, n_pt_embd);
|
|
1020
|
+
|
|
1021
|
+
model.tensors["mask_decoder.iou_prediction_head.layers.0.weight"] = dec.iou_prediction_head_0_w;
|
|
1022
|
+
model.tensors["mask_decoder.iou_prediction_head.layers.0.bias"] = dec.iou_prediction_head_0_b;
|
|
1023
|
+
model.tensors["mask_decoder.iou_prediction_head.layers.1.weight"] = dec.iou_prediction_head_1_w;
|
|
1024
|
+
model.tensors["mask_decoder.iou_prediction_head.layers.1.bias"] = dec.iou_prediction_head_1_b;
|
|
1025
|
+
model.tensors["mask_decoder.iou_prediction_head.layers.2.weight"] = dec.iou_prediction_head_2_w;
|
|
1026
|
+
model.tensors["mask_decoder.iou_prediction_head.layers.2.bias"] = dec.iou_prediction_head_2_b;
|
|
1027
|
+
|
|
1028
|
+
model.tensors["mask_decoder.iou_token.weight"] = dec.iou_token_w;
|
|
1029
|
+
model.tensors["mask_decoder.mask_tokens.weight"] = dec.mask_tokens_w;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// load weights
|
|
1034
|
+
{
|
|
1035
|
+
int n_tensors = 0;
|
|
1036
|
+
size_t total_size = 0;
|
|
1037
|
+
|
|
1038
|
+
fprintf(stderr, "%s: ", __func__);
|
|
1039
|
+
|
|
1040
|
+
while (true) {
|
|
1041
|
+
int32_t n_dims;
|
|
1042
|
+
int32_t length;
|
|
1043
|
+
int32_t ftype;
|
|
1044
|
+
|
|
1045
|
+
fin.read(reinterpret_cast<char *>(&n_dims), sizeof(n_dims));
|
|
1046
|
+
fin.read(reinterpret_cast<char *>(&length), sizeof(length));
|
|
1047
|
+
fin.read(reinterpret_cast<char *>(&ftype), sizeof(ftype));
|
|
1048
|
+
|
|
1049
|
+
if (fin.eof()) {
|
|
1050
|
+
break;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
int64_t nelements = 1;
|
|
1054
|
+
int64_t ne[4] = { 1, 1, 1, 1 };
|
|
1055
|
+
for (int i = 0; i < n_dims; ++i) {
|
|
1056
|
+
int32_t ne_cur;
|
|
1057
|
+
fin.read(reinterpret_cast<char *>(&ne_cur), sizeof(ne_cur));
|
|
1058
|
+
ne[i] = ne_cur;
|
|
1059
|
+
nelements *= ne[i];
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
std::string name(length, 0);
|
|
1063
|
+
fin.read(&name[0], length);
|
|
1064
|
+
|
|
1065
|
+
if (model.tensors.find(name.data()) == model.tensors.end()) {
|
|
1066
|
+
fprintf(stderr, "%s: unknown tensor '%s' in model file\n", __func__, name.data());
|
|
1067
|
+
return false;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
auto tensor = model.tensors[name.data()];
|
|
1071
|
+
//printf("ne0 = %jd, ne1 = %jd, ne2 = %jd, ne3 = %jd\n", ne[0], ne[1], ne[2], ne[3]);
|
|
1072
|
+
|
|
1073
|
+
if (ggml_nelements(tensor) != nelements) {
|
|
1074
|
+
fprintf(stderr, "%s: tensor '%s' has wrong size in model file: got %d, expected %d\n",
|
|
1075
|
+
__func__, name.data(), (int) nelements, (int) ggml_nelements(tensor));
|
|
1076
|
+
return false;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
if (tensor->ne[0] != ne[0] || tensor->ne[1] != ne[1] || tensor->ne[2] != ne[2] || tensor->ne[3] != ne[3]) {
|
|
1080
|
+
fprintf(stderr, "%s: tensor '%s' has wrong shape in model file: got [%d, %d, %d, %d], expected [%d, %d, %d, %d]\n",
|
|
1081
|
+
__func__, name.data(),
|
|
1082
|
+
(int) ne[0], (int) ne[1], (int) ne[2], (int) ne[3],
|
|
1083
|
+
(int) tensor->ne[0], (int) tensor->ne[1], (int) tensor->ne[2], (int) tensor->ne[3]);
|
|
1084
|
+
return false;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
size_t bpe = 0;
|
|
1088
|
+
|
|
1089
|
+
switch (ftype) {
|
|
1090
|
+
case 0: bpe = ggml_type_size(GGML_TYPE_F32); break;
|
|
1091
|
+
case 1: bpe = ggml_type_size(GGML_TYPE_F16); break;
|
|
1092
|
+
case 2: bpe = ggml_type_size(GGML_TYPE_Q4_0); assert(ne[0] % 64 == 0); break;
|
|
1093
|
+
case 3: bpe = ggml_type_size(GGML_TYPE_Q4_1); assert(ne[0] % 64 == 0); break;
|
|
1094
|
+
default:
|
|
1095
|
+
{
|
|
1096
|
+
fprintf(stderr, "%s: unknown ftype %d in model file\n", __func__, ftype);
|
|
1097
|
+
return false;
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
if ((nelements*bpe)/ggml_blck_size(tensor->type) != ggml_nbytes(tensor)) {
|
|
1102
|
+
fprintf(stderr, "%s: tensor '%s' has wrong size in model file: got %zu, expected %zu\n",
|
|
1103
|
+
__func__, name.data(), ggml_nbytes(tensor), (size_t) nelements*bpe);
|
|
1104
|
+
return false;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
fin.read(reinterpret_cast<char *>(tensor->data), ggml_nbytes(tensor));
|
|
1108
|
+
|
|
1109
|
+
total_size += ggml_nbytes(tensor);
|
|
1110
|
+
if (++n_tensors % 8 == 0) {
|
|
1111
|
+
fprintf(stderr, ".");
|
|
1112
|
+
fflush(stdout);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
if (n_tensors != int(model.tensors.size())) {
|
|
1117
|
+
fprintf(stderr, "%s: model file has %d tensors, but %d tensors were expected\n", __func__, n_tensors, (int) model.tensors.size());
|
|
1118
|
+
return false;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
fprintf(stderr, " done\n");
|
|
1122
|
+
|
|
1123
|
+
fprintf(stderr, "%s: model size = %8.2f MB / num tensors = %d\n", __func__, total_size/1024.0/1024.0, n_tensors);
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
fin.close();
|
|
1127
|
+
|
|
1128
|
+
return true;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
struct ggml_tensor * sam_fill_dense_pe(
|
|
1132
|
+
const sam_model & model,
|
|
1133
|
+
struct ggml_context * ctx0,
|
|
1134
|
+
struct ggml_cgraph * gf,
|
|
1135
|
+
sam_state & state) {
|
|
1136
|
+
const auto & hparams = model.hparams;
|
|
1137
|
+
const auto & enc = model.enc_prompt;
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
const int32_t n_img_embd = hparams.n_img_embd();
|
|
1141
|
+
struct ggml_tensor * xy_embed_stacked = ggml_new_tensor_3d(ctx0, GGML_TYPE_F32, 2, n_img_embd, n_img_embd);
|
|
1142
|
+
ggml_set_name(xy_embed_stacked, "xy_embed_stacked");
|
|
1143
|
+
ggml_set_input(xy_embed_stacked);
|
|
1144
|
+
|
|
1145
|
+
struct ggml_tensor * cur = ggml_mul_mat(ctx0, ggml_cont(ctx0, ggml_transpose(ctx0, enc.pe)), xy_embed_stacked);
|
|
1146
|
+
|
|
1147
|
+
cur = ggml_scale(ctx0, cur, float(2.0*M_PI));
|
|
1148
|
+
|
|
1149
|
+
// concat
|
|
1150
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/prompt_encoder.py#L192
|
|
1151
|
+
{
|
|
1152
|
+
struct ggml_tensor * t_sin = ggml_map_custom1(ctx0, cur, ggml_sam_sin, GGML_N_TASKS_MAX, NULL);
|
|
1153
|
+
struct ggml_tensor * t_cos = ggml_map_custom1(ctx0, cur, ggml_sam_cos, GGML_N_TASKS_MAX, NULL);
|
|
1154
|
+
|
|
1155
|
+
cur = ggml_new_tensor_3d(ctx0, GGML_TYPE_F32, t_sin->ne[0] + t_cos->ne[0], cur->ne[1], cur->ne[2]);
|
|
1156
|
+
|
|
1157
|
+
ggml_build_forward_expand(gf, ggml_cpy(ctx0, t_sin, ggml_view_3d(ctx0, cur, t_sin->ne[0], t_sin->ne[1], t_sin->ne[2], cur->nb[1], cur->nb[2], 0)));
|
|
1158
|
+
ggml_build_forward_expand(gf, ggml_cpy(ctx0, t_cos, ggml_view_3d(ctx0, cur, t_sin->ne[0], t_sin->ne[1], t_sin->ne[2], cur->nb[1], cur->nb[2], t_sin->nb[1])));
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
struct ggml_tensor * pe_img_dense = ggml_cont(ctx0, ggml_permute(ctx0, cur, 2, 0, 1, 3));
|
|
1162
|
+
ggml_build_forward_expand(gf, pe_img_dense);
|
|
1163
|
+
|
|
1164
|
+
return pe_img_dense;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
struct ggml_tensor* sam_layer_norm_2d(
|
|
1168
|
+
struct ggml_context * ctx0,
|
|
1169
|
+
struct ggml_tensor * layer,
|
|
1170
|
+
int n_channels,
|
|
1171
|
+
struct ggml_tensor * w,
|
|
1172
|
+
struct ggml_tensor * b,
|
|
1173
|
+
float eps) {
|
|
1174
|
+
// LayerNorm2d
|
|
1175
|
+
// normalize along channel dimmension
|
|
1176
|
+
// TODO: better implementation
|
|
1177
|
+
layer = ggml_permute(ctx0,
|
|
1178
|
+
ggml_norm(ctx0, ggml_cont(ctx0, ggml_permute(ctx0, layer, 1, 2, 0, 3)), eps),
|
|
1179
|
+
2, 0, 1, 3);
|
|
1180
|
+
|
|
1181
|
+
layer = ggml_add(ctx0,
|
|
1182
|
+
ggml_mul(ctx0,
|
|
1183
|
+
ggml_repeat(ctx0, ggml_reshape_3d(ctx0, w, 1, 1, n_channels), layer),
|
|
1184
|
+
layer),
|
|
1185
|
+
ggml_repeat(ctx0, ggml_reshape_3d(ctx0, b, 1, 1, n_channels), layer));
|
|
1186
|
+
|
|
1187
|
+
return layer;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
struct ggml_cgraph * sam_encode_image(
|
|
1191
|
+
const sam_model & model,
|
|
1192
|
+
sam_state & state,
|
|
1193
|
+
const sam_image_f32 & img) {
|
|
1194
|
+
|
|
1195
|
+
const auto & hparams = model.hparams;
|
|
1196
|
+
const auto & enc = model.enc_img;
|
|
1197
|
+
|
|
1198
|
+
const int32_t n_enc_state = hparams.n_enc_state;
|
|
1199
|
+
const int32_t n_enc_layer = hparams.n_enc_layer;
|
|
1200
|
+
const int32_t n_enc_head = hparams.n_enc_head;
|
|
1201
|
+
const int32_t n_enc_head_dim = hparams.n_enc_head_dim();
|
|
1202
|
+
const int32_t n_enc_out_chans = hparams.n_enc_out_chans;
|
|
1203
|
+
const int32_t n_img_size = hparams.n_img_size();
|
|
1204
|
+
const int32_t n_window_size = hparams.n_window_size();
|
|
1205
|
+
|
|
1206
|
+
struct ggml_init_params ggml_params = {
|
|
1207
|
+
/*.mem_size =*/ state.buf_compute_img_enc.size(),
|
|
1208
|
+
/*.mem_buffer =*/ state.buf_compute_img_enc.data(),
|
|
1209
|
+
/*.no_alloc =*/ true, // skip allocating as we use ggml_alloc to allocate exact memory requirements
|
|
1210
|
+
};
|
|
1211
|
+
|
|
1212
|
+
struct ggml_context * ctx0 = ggml_init(ggml_params);
|
|
1213
|
+
struct ggml_cgraph * gf = ggml_new_graph(ctx0);
|
|
1214
|
+
|
|
1215
|
+
struct ggml_tensor * inp = ggml_new_tensor_4d(ctx0, GGML_TYPE_F32, n_img_size, n_img_size, 3, 1);
|
|
1216
|
+
ggml_set_name(inp, "inp");
|
|
1217
|
+
ggml_set_input(inp);
|
|
1218
|
+
|
|
1219
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/image_encoder.py#L392
|
|
1220
|
+
struct ggml_tensor * cur = ggml_conv_2d_sk_p0(ctx0, enc.proj_w, inp);
|
|
1221
|
+
cur = ggml_add_inplace(ctx0,
|
|
1222
|
+
cur,
|
|
1223
|
+
ggml_repeat(ctx0, enc.proj_b, cur));
|
|
1224
|
+
|
|
1225
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/image_encoder.py#L394
|
|
1226
|
+
// keep in F32
|
|
1227
|
+
cur = ggml_cont(ctx0,
|
|
1228
|
+
ggml_permute(ctx0, cur, 1, 2, 0, 3));
|
|
1229
|
+
|
|
1230
|
+
// convert to F16
|
|
1231
|
+
//cur = ggml_cpy(ctx0,
|
|
1232
|
+
// ggml_permute(ctx0, cur, 1, 2, 0, 3),
|
|
1233
|
+
// ggml_new_tensor_3d(ctx0, GGML_TYPE_F16, n_enc_state, n_img_embd, n_img_embd));
|
|
1234
|
+
|
|
1235
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/image_encoder.py#L108-L109
|
|
1236
|
+
cur = ggml_add_inplace(ctx0, cur, enc.pe);
|
|
1237
|
+
|
|
1238
|
+
struct ggml_tensor * inpL = cur;
|
|
1239
|
+
|
|
1240
|
+
for (int il = 0; il < n_enc_layer; ++il) {
|
|
1241
|
+
const auto & layer = enc.layers[il];
|
|
1242
|
+
|
|
1243
|
+
// norm
|
|
1244
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/image_encoder.py#L168
|
|
1245
|
+
{
|
|
1246
|
+
cur = ggml_norm(ctx0, inpL, hparams.eps);
|
|
1247
|
+
|
|
1248
|
+
// cur = ln_0_w*cur + ln_0_b
|
|
1249
|
+
cur = ggml_mul(ctx0, cur, layer.norm1_w);
|
|
1250
|
+
cur = ggml_add_inplace(ctx0, cur, layer.norm1_b);
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
const int64_t w0 = cur->ne[1];
|
|
1254
|
+
const int64_t h0 = cur->ne[2];
|
|
1255
|
+
|
|
1256
|
+
if (hparams.is_global_attn(il) == false) {
|
|
1257
|
+
// local attention layer - apply window partition
|
|
1258
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/image_encoder.py#L169-L172
|
|
1259
|
+
cur = ggml_win_part(ctx0, cur, n_window_size);
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
const int64_t W = cur->ne[1];
|
|
1263
|
+
const int64_t H = cur->ne[2];
|
|
1264
|
+
|
|
1265
|
+
// self-attention
|
|
1266
|
+
{
|
|
1267
|
+
cur = ggml_mul_mat(ctx0, layer.qkv_w, cur);
|
|
1268
|
+
cur = ggml_add_inplace(ctx0, cur, layer.qkv_b);
|
|
1269
|
+
|
|
1270
|
+
// split qkv into separate tensors
|
|
1271
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/image_encoder.py#L225-L229
|
|
1272
|
+
const int B = cur->ne[3];
|
|
1273
|
+
|
|
1274
|
+
cur = ggml_reshape_4d(ctx0, cur, n_enc_state, 3, W*H, B);
|
|
1275
|
+
cur = ggml_cont(ctx0, ggml_permute(ctx0, cur, 0, 3, 1, 2));
|
|
1276
|
+
|
|
1277
|
+
struct ggml_tensor * Q;
|
|
1278
|
+
struct ggml_tensor * K;
|
|
1279
|
+
struct ggml_tensor * V;
|
|
1280
|
+
|
|
1281
|
+
Q = ggml_view_3d (ctx0, cur, n_enc_state, W*H, B, cur->nb[1], cur->nb[2], 0*cur->nb[3]);
|
|
1282
|
+
Q = ggml_reshape_4d(ctx0, Q, n_enc_head_dim, n_enc_head, W*H, B);
|
|
1283
|
+
Q = ggml_cont (ctx0, ggml_permute(ctx0, Q, 0, 2, 1, 3));
|
|
1284
|
+
Q = ggml_reshape_3d(ctx0, Q, n_enc_head_dim, W*H, B*n_enc_head);
|
|
1285
|
+
|
|
1286
|
+
K = ggml_view_3d (ctx0, cur, n_enc_state, W*H, B, cur->nb[1], cur->nb[2], 1*cur->nb[3]);
|
|
1287
|
+
K = ggml_reshape_4d(ctx0, K, n_enc_head_dim, n_enc_head, W*H, B);
|
|
1288
|
+
K = ggml_cont (ctx0, ggml_permute(ctx0, K, 0, 2, 1, 3));
|
|
1289
|
+
K = ggml_reshape_3d(ctx0, K, n_enc_head_dim, W*H, B*n_enc_head);
|
|
1290
|
+
|
|
1291
|
+
V = ggml_view_3d (ctx0, cur, n_enc_state, W*H, B, cur->nb[1], cur->nb[2], 2*cur->nb[3]);
|
|
1292
|
+
V = ggml_reshape_4d(ctx0, V, n_enc_head_dim, n_enc_head, W*H, B);
|
|
1293
|
+
V = ggml_cont (ctx0, ggml_permute(ctx0, V, 1, 2, 0, 3)); // transposed
|
|
1294
|
+
V = ggml_reshape_3d(ctx0, V, W*H, n_enc_head_dim, B*n_enc_head);
|
|
1295
|
+
|
|
1296
|
+
struct ggml_tensor * KQ = ggml_mul_mat(ctx0, K, Q);
|
|
1297
|
+
|
|
1298
|
+
struct ggml_tensor * KQ_scaled =
|
|
1299
|
+
ggml_scale_inplace(ctx0,
|
|
1300
|
+
KQ,
|
|
1301
|
+
1.0f/sqrtf(n_enc_head_dim));
|
|
1302
|
+
|
|
1303
|
+
struct ggml_tensor * rw = ggml_get_rel_pos(ctx0, layer.rel_pos_w, W, W);
|
|
1304
|
+
struct ggml_tensor * rh = ggml_get_rel_pos(ctx0, layer.rel_pos_h, H, H);
|
|
1305
|
+
|
|
1306
|
+
struct ggml_tensor * q_r = ggml_reshape_4d(ctx0, Q, n_enc_head_dim, W, H, B*n_enc_head);
|
|
1307
|
+
|
|
1308
|
+
struct ggml_tensor * rel_w = ggml_cont(ctx0, ggml_permute(ctx0,
|
|
1309
|
+
ggml_mul_mat(ctx0,
|
|
1310
|
+
rw,
|
|
1311
|
+
ggml_cont(ctx0, ggml_permute(ctx0, q_r, 0, 2, 1, 3))),
|
|
1312
|
+
0, 2, 1, 3));
|
|
1313
|
+
struct ggml_tensor * rel_h = ggml_mul_mat(ctx0, rh, q_r);
|
|
1314
|
+
|
|
1315
|
+
struct ggml_tensor * attn = ggml_add_rel_pos_inplace(ctx0, KQ_scaled, rel_w, rel_h);
|
|
1316
|
+
|
|
1317
|
+
struct ggml_tensor * KQ_soft_max = ggml_soft_max_inplace(ctx0, attn);
|
|
1318
|
+
|
|
1319
|
+
struct ggml_tensor * KQV = ggml_mul_mat(ctx0, V, KQ_soft_max);
|
|
1320
|
+
|
|
1321
|
+
cur =
|
|
1322
|
+
ggml_reshape_4d(ctx0,
|
|
1323
|
+
ggml_cont(ctx0,
|
|
1324
|
+
ggml_permute(ctx0,
|
|
1325
|
+
ggml_reshape_4d(ctx0, KQV, n_enc_head_dim, W*H, n_enc_head, B),
|
|
1326
|
+
0, 2, 1, 3)),
|
|
1327
|
+
n_enc_state, W, H, B);
|
|
1328
|
+
|
|
1329
|
+
cur = ggml_mul_mat(ctx0, layer.proj_w, cur);
|
|
1330
|
+
cur = ggml_add_inplace(ctx0, cur, layer.proj_b);
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
if (hparams.is_global_attn(il) == false) {
|
|
1334
|
+
// local attention layer - reverse window partition
|
|
1335
|
+
cur = ggml_win_unpart(ctx0, cur, w0, h0, n_window_size);
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
cur = ggml_add_inplace(ctx0, cur, inpL);
|
|
1339
|
+
|
|
1340
|
+
struct ggml_tensor * inpFF = cur;
|
|
1341
|
+
|
|
1342
|
+
// feed-forward network
|
|
1343
|
+
{
|
|
1344
|
+
// norm
|
|
1345
|
+
{
|
|
1346
|
+
cur = ggml_norm(ctx0, inpFF, hparams.eps);
|
|
1347
|
+
|
|
1348
|
+
// cur = mlp_ln_w*cur + mlp_ln_b
|
|
1349
|
+
cur = ggml_mul(ctx0, cur, layer.norm2_w);
|
|
1350
|
+
cur = ggml_add_inplace(ctx0, cur, layer.norm2_b);
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// fully connected
|
|
1354
|
+
cur = ggml_mul_mat(ctx0, layer.mlp_lin1_w, cur);
|
|
1355
|
+
cur = ggml_add_inplace(ctx0, cur, layer.mlp_lin1_b);
|
|
1356
|
+
|
|
1357
|
+
// GELU activation
|
|
1358
|
+
cur = ggml_gelu(ctx0, cur);
|
|
1359
|
+
|
|
1360
|
+
// projection
|
|
1361
|
+
cur = ggml_mul_mat(ctx0, layer.mlp_lin2_w, cur);
|
|
1362
|
+
cur = ggml_add_inplace(ctx0, cur, layer.mlp_lin2_b);
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
inpL = ggml_add(ctx0, cur, inpFF);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
cur = ggml_cont(ctx0, ggml_permute(ctx0, inpL, 2, 0, 1, 3));
|
|
1369
|
+
|
|
1370
|
+
cur = ggml_conv_2d_sk_p0(ctx0, enc.neck_conv_0, cur);
|
|
1371
|
+
|
|
1372
|
+
cur = sam_layer_norm_2d(ctx0, cur, n_enc_out_chans, enc.neck_norm_0_w, enc.neck_norm_0_b, hparams.eps);
|
|
1373
|
+
|
|
1374
|
+
cur = ggml_conv_2d_s1_ph(ctx0, enc.neck_conv_1, cur);
|
|
1375
|
+
|
|
1376
|
+
cur = sam_layer_norm_2d(ctx0, cur, n_enc_out_chans, enc.neck_norm_1_w, enc.neck_norm_1_b, hparams.eps);
|
|
1377
|
+
|
|
1378
|
+
cur = ggml_cpy(ctx0, cur, state.embd_img);
|
|
1379
|
+
|
|
1380
|
+
ggml_build_forward_expand(gf, cur);
|
|
1381
|
+
ggml_disconnect_node_from_graph(state.embd_img);
|
|
1382
|
+
|
|
1383
|
+
//ggml_graph_print(&gf);
|
|
1384
|
+
|
|
1385
|
+
ggml_free(ctx0);
|
|
1386
|
+
|
|
1387
|
+
ggml_gallocr_alloc_graph(state.allocr, gf);
|
|
1388
|
+
|
|
1389
|
+
{
|
|
1390
|
+
struct ggml_tensor * inp = ggml_graph_get_tensor(gf, "inp");
|
|
1391
|
+
float * data = (float *) ggml_get_data(inp);
|
|
1392
|
+
|
|
1393
|
+
const int nx = img.nx;
|
|
1394
|
+
const int ny = img.ny;
|
|
1395
|
+
const int n = nx*ny;
|
|
1396
|
+
|
|
1397
|
+
GGML_ASSERT(nx == n_img_size && ny == n_img_size);
|
|
1398
|
+
|
|
1399
|
+
for (int k = 0; k < 3; k++) {
|
|
1400
|
+
for (int y = 0; y < ny; y++) {
|
|
1401
|
+
for (int x = 0; x < nx; x++) {
|
|
1402
|
+
data[k*n + y*nx + x] = img.data[3*(y*nx + x) + k];
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
return gf;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
struct prompt_encoder_result {
|
|
1413
|
+
struct ggml_tensor * embd_prompt_sparse = {};
|
|
1414
|
+
struct ggml_tensor * embd_prompt_dense = {};
|
|
1415
|
+
};
|
|
1416
|
+
|
|
1417
|
+
struct ggml_tensor * sam_prompt_encode_pe_encoding(
|
|
1418
|
+
const sam_encoder_prompt & enc,
|
|
1419
|
+
struct ggml_context * ctx0,
|
|
1420
|
+
struct ggml_cgraph * gf,
|
|
1421
|
+
struct ggml_tensor * coords) {
|
|
1422
|
+
|
|
1423
|
+
auto * cur = ggml_mul_mat(ctx0, ggml_cont(ctx0, ggml_transpose(ctx0, enc.pe)), coords);
|
|
1424
|
+
cur = ggml_scale(ctx0, cur, float(2.0*M_PI));
|
|
1425
|
+
|
|
1426
|
+
// concat
|
|
1427
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/prompt_encoder.py#L192
|
|
1428
|
+
{
|
|
1429
|
+
struct ggml_tensor * t_sin = ggml_map_custom1(ctx0, cur, ggml_sam_sin, GGML_N_TASKS_MAX, NULL);
|
|
1430
|
+
struct ggml_tensor * t_cos = ggml_map_custom1(ctx0, cur, ggml_sam_cos, GGML_N_TASKS_MAX, NULL);
|
|
1431
|
+
|
|
1432
|
+
cur = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, t_sin->ne[0] + t_cos->ne[0], cur->ne[1]);
|
|
1433
|
+
|
|
1434
|
+
ggml_build_forward_expand(gf, ggml_cpy(ctx0, t_sin, ggml_view_2d(ctx0, cur, t_sin->ne[0], t_sin->ne[1], cur->nb[1], 0)));
|
|
1435
|
+
ggml_build_forward_expand(gf, ggml_cpy(ctx0, t_cos, ggml_view_2d(ctx0, cur, t_sin->ne[0], t_sin->ne[1], cur->nb[1], t_sin->nb[1])));
|
|
1436
|
+
|
|
1437
|
+
}
|
|
1438
|
+
return cur;
|
|
1439
|
+
|
|
1440
|
+
}
|
|
1441
|
+
// encode a prompt
|
|
1442
|
+
//
|
|
1443
|
+
// - points
|
|
1444
|
+
// - boxes
|
|
1445
|
+
// - masks
|
|
1446
|
+
//
|
|
1447
|
+
// TODO: currently just encode a single point for simplicity
|
|
1448
|
+
//
|
|
1449
|
+
prompt_encoder_result sam_encode_prompt(
|
|
1450
|
+
const sam_model & model,
|
|
1451
|
+
struct ggml_context * ctx0,
|
|
1452
|
+
struct ggml_cgraph * gf,
|
|
1453
|
+
sam_state & state,
|
|
1454
|
+
const sam_prompt & prompt) {
|
|
1455
|
+
|
|
1456
|
+
const auto & hparams = model.hparams;
|
|
1457
|
+
const auto & enc = model.enc_prompt;
|
|
1458
|
+
|
|
1459
|
+
struct ggml_tensor * inp = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, 2, 2);
|
|
1460
|
+
ggml_set_name(inp, "prompt_input");
|
|
1461
|
+
ggml_set_input(inp);
|
|
1462
|
+
|
|
1463
|
+
auto * embd_prompt_sparse = [&]() -> struct ggml_tensor * {
|
|
1464
|
+
switch (prompt.prompt_type) {
|
|
1465
|
+
case SAM_PROMPT_TYPE_POINT: {
|
|
1466
|
+
// PromptEncoder._embed_points
|
|
1467
|
+
auto * pt_embd = sam_prompt_encode_pe_encoding(enc, ctx0, gf, inp);
|
|
1468
|
+
|
|
1469
|
+
// overwrite label == -1 with not_a_point_embed.weight
|
|
1470
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/prompt_encoder.py#L86
|
|
1471
|
+
// TODO: extend for multiple points
|
|
1472
|
+
auto * pt_embd_not = ggml_view_2d(ctx0, pt_embd, pt_embd->ne[0], 1, pt_embd->nb[1], pt_embd->nb[1]);
|
|
1473
|
+
ggml_build_forward_expand(gf, ggml_cpy(ctx0, enc.not_a_pt_embd_w, pt_embd_not));
|
|
1474
|
+
|
|
1475
|
+
// add point_embeddings[1] to label == 1
|
|
1476
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/prompt_encoder.py#L90
|
|
1477
|
+
auto * pt_embd1 = ggml_view_2d(ctx0, pt_embd, pt_embd->ne[0], 1, pt_embd->nb[1], 0);
|
|
1478
|
+
ggml_build_forward_expand(gf, ggml_add_inplace(ctx0, pt_embd1, enc.pt_embd[1]));
|
|
1479
|
+
|
|
1480
|
+
return pt_embd;
|
|
1481
|
+
} break;
|
|
1482
|
+
case SAM_PROMPT_TYPE_BOX: {
|
|
1483
|
+
// PromptEncoder._embed_boxes
|
|
1484
|
+
auto * corner_embd = sam_prompt_encode_pe_encoding(enc, ctx0, gf, inp);
|
|
1485
|
+
|
|
1486
|
+
// corner_embd[:, 0, :] += self.point_embeddings[2].weight
|
|
1487
|
+
// corner_embd[:, 1, :] += self.point_embeddings[3].weight
|
|
1488
|
+
auto * corner0 = ggml_view_2d(
|
|
1489
|
+
ctx0, corner_embd, corner_embd->ne[0], 1, corner_embd->nb[1], 0);
|
|
1490
|
+
auto * corner1 = ggml_view_2d(
|
|
1491
|
+
ctx0, corner_embd, corner_embd->ne[0], 1, corner_embd->nb[1], corner_embd->nb[1]);
|
|
1492
|
+
|
|
1493
|
+
ggml_build_forward_expand(gf, ggml_add_inplace(ctx0, corner0, enc.pt_embd[2]));
|
|
1494
|
+
ggml_build_forward_expand(gf, ggml_add_inplace(ctx0, corner1, enc.pt_embd[3]));
|
|
1495
|
+
|
|
1496
|
+
return corner_embd;
|
|
1497
|
+
} break;
|
|
1498
|
+
default: {
|
|
1499
|
+
fprintf(stderr, "%s: unsupported prompt type %d\n", __func__, prompt.prompt_type);
|
|
1500
|
+
return nullptr;
|
|
1501
|
+
} break;
|
|
1502
|
+
}
|
|
1503
|
+
}();
|
|
1504
|
+
|
|
1505
|
+
ggml_build_forward_expand(gf, embd_prompt_sparse);
|
|
1506
|
+
|
|
1507
|
+
struct ggml_tensor * embd_prompt_dense = ggml_repeat(ctx0,
|
|
1508
|
+
ggml_cont(ctx0,
|
|
1509
|
+
ggml_view_3d(ctx0, enc.no_mask_embd_w,
|
|
1510
|
+
1, 1, enc.no_mask_embd_w->ne[0], enc.no_mask_embd_w->nb[0], enc.no_mask_embd_w->nb[0], 0)),
|
|
1511
|
+
ggml_new_tensor_3d(ctx0, GGML_TYPE_F32, hparams.n_img_embd(), hparams.n_img_embd(), hparams.n_enc_out_chans));
|
|
1512
|
+
|
|
1513
|
+
ggml_build_forward_expand(gf, embd_prompt_dense);
|
|
1514
|
+
|
|
1515
|
+
//printf("used_mem = %zu\n", ggml_used_mem(ctx0));
|
|
1516
|
+
|
|
1517
|
+
prompt_encoder_result res;
|
|
1518
|
+
res.embd_prompt_sparse = embd_prompt_sparse;
|
|
1519
|
+
res.embd_prompt_dense = embd_prompt_dense;
|
|
1520
|
+
return res;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
struct ggml_tensor* sam_decode_mask_transformer_attn(
|
|
1524
|
+
const sam_layer_dec_transformer_attn & attn,
|
|
1525
|
+
struct ggml_tensor * queries,
|
|
1526
|
+
struct ggml_tensor * keys,
|
|
1527
|
+
struct ggml_tensor * values,
|
|
1528
|
+
struct ggml_context * ctx0,
|
|
1529
|
+
const sam_model & model) {
|
|
1530
|
+
const auto & hparams = model.hparams;
|
|
1531
|
+
const int n_head = hparams.n_dec_heads;
|
|
1532
|
+
|
|
1533
|
+
struct ggml_tensor * Qcur = {};
|
|
1534
|
+
struct ggml_tensor * Kcur = {};
|
|
1535
|
+
struct ggml_tensor * Vcur = {};
|
|
1536
|
+
|
|
1537
|
+
Qcur = ggml_mul_mat(ctx0, attn.q_w, queries);
|
|
1538
|
+
Qcur = ggml_add_inplace(ctx0, Qcur, attn.q_b);
|
|
1539
|
+
|
|
1540
|
+
Kcur = ggml_mul_mat(ctx0, attn.k_w, keys);
|
|
1541
|
+
Kcur = ggml_add_inplace(ctx0, Kcur, attn.k_b);
|
|
1542
|
+
|
|
1543
|
+
Vcur = ggml_mul_mat(ctx0, attn.v_w, values);
|
|
1544
|
+
Vcur = ggml_add_inplace(ctx0, Vcur, attn.v_b);
|
|
1545
|
+
|
|
1546
|
+
struct ggml_tensor * Q = {};
|
|
1547
|
+
struct ggml_tensor * K = {};
|
|
1548
|
+
struct ggml_tensor * V = {};
|
|
1549
|
+
|
|
1550
|
+
Q = ggml_reshape_4d(ctx0, Qcur, Qcur->ne[0]/n_head, n_head, Qcur->ne[1], Qcur->ne[2]);
|
|
1551
|
+
Q = ggml_cont(ctx0, ggml_permute(ctx0, Q, 0, 2, 1, 3));
|
|
1552
|
+
|
|
1553
|
+
K = ggml_reshape_4d(ctx0, Kcur, Kcur->ne[0]/n_head, n_head, Kcur->ne[1], Kcur->ne[2]);
|
|
1554
|
+
K = ggml_cont(ctx0, ggml_permute(ctx0, K, 0, 2, 1, 3));
|
|
1555
|
+
|
|
1556
|
+
V = ggml_reshape_4d(ctx0, Vcur, Vcur->ne[0]/n_head, n_head, Vcur->ne[1], Vcur->ne[2]);
|
|
1557
|
+
V = ggml_cont(ctx0, ggml_permute(ctx0, V, 0, 2, 1, 3));
|
|
1558
|
+
|
|
1559
|
+
// Q * K
|
|
1560
|
+
struct ggml_tensor * KQ = ggml_mul_mat(ctx0, K, Q);
|
|
1561
|
+
|
|
1562
|
+
struct ggml_tensor * KQ_scaled = ggml_scale_inplace(ctx0, KQ, 1.0f/sqrt(float(Q->ne[0])));
|
|
1563
|
+
|
|
1564
|
+
struct ggml_tensor * KQ_soft_max = ggml_soft_max_inplace(ctx0, KQ_scaled);
|
|
1565
|
+
|
|
1566
|
+
struct ggml_tensor * KQV = ggml_mul_mat(ctx0, KQ_soft_max, ggml_cont(ctx0, ggml_transpose(ctx0, V)));
|
|
1567
|
+
|
|
1568
|
+
struct ggml_tensor * KQV_merged = ggml_cont(ctx0, ggml_transpose(ctx0, KQV));
|
|
1569
|
+
KQV_merged = ggml_cont(ctx0, ggml_permute(ctx0, KQV_merged, 0, 2, 1, 3));
|
|
1570
|
+
KQV_merged = ggml_reshape_3d(ctx0, KQV_merged, KQV_merged->ne[0]*KQV_merged->ne[1], KQV_merged->ne[2], KQV_merged->ne[3]);
|
|
1571
|
+
KQV_merged = ggml_mul_mat(ctx0, attn.out_w, KQV_merged);
|
|
1572
|
+
KQV_merged = ggml_add_inplace(ctx0, KQV_merged, attn.out_b);
|
|
1573
|
+
|
|
1574
|
+
return KQV_merged;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
struct ggml_tensor * sam_decode_mask_mlp_relu_3(
|
|
1578
|
+
struct ggml_tensor * in,
|
|
1579
|
+
struct ggml_tensor * w_0,
|
|
1580
|
+
struct ggml_tensor * b_0,
|
|
1581
|
+
struct ggml_tensor * w_1,
|
|
1582
|
+
struct ggml_tensor * b_1,
|
|
1583
|
+
struct ggml_tensor * w_2,
|
|
1584
|
+
struct ggml_tensor * b_2,
|
|
1585
|
+
struct ggml_context * ctx0) {
|
|
1586
|
+
|
|
1587
|
+
struct ggml_tensor * cur = {};
|
|
1588
|
+
cur = ggml_mul_mat(ctx0, w_0, in);
|
|
1589
|
+
cur = ggml_add_inplace(ctx0, cur, b_0);
|
|
1590
|
+
|
|
1591
|
+
cur = ggml_relu_inplace(ctx0, cur);
|
|
1592
|
+
|
|
1593
|
+
cur = ggml_mul_mat(ctx0, w_1, cur);
|
|
1594
|
+
cur = ggml_add_inplace(ctx0, cur, b_1);
|
|
1595
|
+
|
|
1596
|
+
cur = ggml_relu_inplace(ctx0, cur);
|
|
1597
|
+
|
|
1598
|
+
cur = ggml_mul_mat(ctx0, w_2, cur);
|
|
1599
|
+
cur = ggml_add_inplace(ctx0, cur, b_2);
|
|
1600
|
+
|
|
1601
|
+
return cur;
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
bool sam_decode_mask(
|
|
1605
|
+
const sam_model & model,
|
|
1606
|
+
const prompt_encoder_result & prompt,
|
|
1607
|
+
struct ggml_tensor * pe_img,
|
|
1608
|
+
struct ggml_context * ctx0,
|
|
1609
|
+
struct ggml_cgraph * gf,
|
|
1610
|
+
sam_state & state,
|
|
1611
|
+
const bool multimask_output) {
|
|
1612
|
+
|
|
1613
|
+
const auto & hparams = model.hparams;
|
|
1614
|
+
const auto & dec = model.dec;
|
|
1615
|
+
const int n_img_embd = hparams.n_img_embd();
|
|
1616
|
+
|
|
1617
|
+
struct ggml_tensor * tokens = {};
|
|
1618
|
+
{
|
|
1619
|
+
// Concatenate output tokens
|
|
1620
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/mask_decoder.py#L120
|
|
1621
|
+
const auto& sparse = prompt.embd_prompt_sparse;
|
|
1622
|
+
|
|
1623
|
+
tokens = ggml_new_tensor_3d(ctx0, GGML_TYPE_F32, dec.iou_token_w->ne[0], dec.iou_token_w->ne[1] + dec.mask_tokens_w->ne[1] + sparse->ne[1], sparse->ne[2]);
|
|
1624
|
+
|
|
1625
|
+
const size_t offsets[3] = { 0, dec.iou_token_w->ne[1]*tokens->nb[1], dec.iou_token_w->ne[1]*tokens->nb[1] + dec.mask_tokens_w->ne[1]*tokens->nb[1] };
|
|
1626
|
+
ggml_build_forward_expand(gf, ggml_cpy(ctx0, dec.iou_token_w, ggml_view_2d(ctx0, tokens, tokens->ne[0], dec.iou_token_w->ne[1], tokens->nb[1], offsets[0])));
|
|
1627
|
+
ggml_build_forward_expand(gf, ggml_cpy(ctx0, dec.mask_tokens_w, ggml_view_2d(ctx0, tokens, tokens->ne[0], dec.mask_tokens_w->ne[1], tokens->nb[1], offsets[1])));
|
|
1628
|
+
ggml_build_forward_expand(gf, ggml_cpy(ctx0, sparse, ggml_view_2d(ctx0, tokens, tokens->ne[0], sparse->ne[1], tokens->nb[1], offsets[2])));
|
|
1629
|
+
// TODO: Sparse prompt embeddings can have more than one point
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
|
|
1633
|
+
struct ggml_tensor * src = {};
|
|
1634
|
+
struct ggml_tensor * pos_src = {};
|
|
1635
|
+
int srcNE[4] = { 0, 0, 0, 0 };
|
|
1636
|
+
{
|
|
1637
|
+
// Expand per-image data in the batch direction to be per-mask
|
|
1638
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/mask_decoder.py#L125
|
|
1639
|
+
src = ggml_new_tensor_4d(ctx0, GGML_TYPE_F32, state.embd_img->ne[0], state.embd_img->ne[1], state.embd_img->ne[2], tokens->ne[2]);
|
|
1640
|
+
|
|
1641
|
+
src = ggml_add(ctx0,
|
|
1642
|
+
ggml_repeat(ctx0,
|
|
1643
|
+
state.embd_img,
|
|
1644
|
+
src),
|
|
1645
|
+
prompt.embd_prompt_dense);
|
|
1646
|
+
|
|
1647
|
+
srcNE[0] = src->ne[0];
|
|
1648
|
+
srcNE[1] = src->ne[1];
|
|
1649
|
+
srcNE[2] = src->ne[2];
|
|
1650
|
+
srcNE[3] = src->ne[3];
|
|
1651
|
+
|
|
1652
|
+
// flatten & permute
|
|
1653
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/transformer.py#L83
|
|
1654
|
+
src = ggml_cont(ctx0, ggml_permute(ctx0,
|
|
1655
|
+
ggml_view_3d(ctx0,
|
|
1656
|
+
src,
|
|
1657
|
+
src->ne[0]*src->ne[1],
|
|
1658
|
+
src->ne[2],
|
|
1659
|
+
src->ne[3],
|
|
1660
|
+
src->nb[2],
|
|
1661
|
+
src->nb[3],
|
|
1662
|
+
0),
|
|
1663
|
+
1, 0, 2, 3));
|
|
1664
|
+
|
|
1665
|
+
pos_src = ggml_new_tensor_4d(ctx0, GGML_TYPE_F32, pe_img->ne[0], pe_img->ne[1], pe_img->ne[2], tokens->ne[2]);
|
|
1666
|
+
pos_src = ggml_repeat(ctx0,
|
|
1667
|
+
pe_img,
|
|
1668
|
+
pos_src);
|
|
1669
|
+
|
|
1670
|
+
// flatten & permute
|
|
1671
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/transformer.py#L83
|
|
1672
|
+
pos_src = ggml_cont(ctx0, ggml_permute(ctx0,
|
|
1673
|
+
ggml_view_3d(ctx0,
|
|
1674
|
+
pos_src,
|
|
1675
|
+
pos_src->ne[0]*pos_src->ne[1],
|
|
1676
|
+
pos_src->ne[2],
|
|
1677
|
+
pos_src->ne[3],
|
|
1678
|
+
pos_src->nb[2],
|
|
1679
|
+
pos_src->nb[3],
|
|
1680
|
+
0),
|
|
1681
|
+
1, 0, 2, 3));
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
struct ggml_tensor * queries = tokens;
|
|
1685
|
+
struct ggml_tensor * keys = src;
|
|
1686
|
+
{
|
|
1687
|
+
// Run the transformer
|
|
1688
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/transformer.py#L62
|
|
1689
|
+
for (int i = 0; i < int(model.dec.transformer_layers.size()); ++i) {
|
|
1690
|
+
const auto& tfm_layer = model.dec.transformer_layers[i];
|
|
1691
|
+
|
|
1692
|
+
// Self attention block
|
|
1693
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/transformer.py#L154
|
|
1694
|
+
const bool skip_first_layer_pe = i == 0;
|
|
1695
|
+
if (skip_first_layer_pe) {
|
|
1696
|
+
queries = sam_decode_mask_transformer_attn(tfm_layer.self_attn, queries, queries, queries, ctx0, model);
|
|
1697
|
+
}
|
|
1698
|
+
else {
|
|
1699
|
+
struct ggml_tensor * q_0 = ggml_add(ctx0, queries, tokens);
|
|
1700
|
+
|
|
1701
|
+
struct ggml_tensor * self_attn = sam_decode_mask_transformer_attn(tfm_layer.self_attn, q_0, q_0, queries, ctx0, model);
|
|
1702
|
+
queries = ggml_add(ctx0, queries, self_attn);
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
queries = ggml_norm(ctx0, queries, hparams.eps_decoder_transformer);
|
|
1706
|
+
queries = ggml_add_inplace(ctx0,
|
|
1707
|
+
ggml_mul(ctx0, queries, tfm_layer.norm1_w),
|
|
1708
|
+
tfm_layer.norm1_b);
|
|
1709
|
+
|
|
1710
|
+
// Cross attention block, tokens attending to image embedding
|
|
1711
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/transformer.py#L163
|
|
1712
|
+
struct ggml_tensor * q_1 = ggml_add(ctx0, queries, tokens);
|
|
1713
|
+
struct ggml_tensor * k_1 = ggml_add(ctx0, keys, pos_src);
|
|
1714
|
+
|
|
1715
|
+
struct ggml_tensor * cross_attn_token_to_img = sam_decode_mask_transformer_attn(tfm_layer.cross_attn_token_to_img, q_1, k_1, keys, ctx0, model);
|
|
1716
|
+
|
|
1717
|
+
queries = ggml_add_inplace(ctx0, queries, cross_attn_token_to_img);
|
|
1718
|
+
queries = ggml_norm_inplace(ctx0, queries, hparams.eps_decoder_transformer);
|
|
1719
|
+
queries = ggml_add_inplace(ctx0,
|
|
1720
|
+
ggml_mul(ctx0, queries, tfm_layer.norm2_w),
|
|
1721
|
+
tfm_layer.norm2_b);
|
|
1722
|
+
|
|
1723
|
+
// MLP block
|
|
1724
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/transformer.py#L170
|
|
1725
|
+
struct ggml_tensor * mlp_out = ggml_mul_mat(ctx0,
|
|
1726
|
+
tfm_layer.mlp_lin1_w,
|
|
1727
|
+
queries);
|
|
1728
|
+
|
|
1729
|
+
mlp_out = ggml_add_inplace(ctx0, mlp_out, tfm_layer.mlp_lin1_b);
|
|
1730
|
+
|
|
1731
|
+
// RELU activation
|
|
1732
|
+
mlp_out = ggml_relu_inplace(ctx0, mlp_out);
|
|
1733
|
+
mlp_out = ggml_mul_mat(ctx0, tfm_layer.mlp_lin2_w, mlp_out);
|
|
1734
|
+
|
|
1735
|
+
mlp_out = ggml_add_inplace(ctx0, mlp_out, tfm_layer.mlp_lin2_b);
|
|
1736
|
+
|
|
1737
|
+
queries = ggml_add_inplace(ctx0, queries, mlp_out);
|
|
1738
|
+
queries = ggml_norm_inplace(ctx0, queries, hparams.eps_decoder_transformer);
|
|
1739
|
+
queries = ggml_add_inplace(ctx0,
|
|
1740
|
+
ggml_mul(ctx0, queries, tfm_layer.norm3_w),
|
|
1741
|
+
tfm_layer.norm3_b);
|
|
1742
|
+
|
|
1743
|
+
// Cross attention block, image embedding attending to tokens
|
|
1744
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/transformer.py#L175
|
|
1745
|
+
struct ggml_tensor * q_2 = ggml_add(ctx0, queries, tokens);
|
|
1746
|
+
struct ggml_tensor * k_2 = ggml_add(ctx0, keys, pos_src);
|
|
1747
|
+
|
|
1748
|
+
struct ggml_tensor * cross_attn_img_to_token = sam_decode_mask_transformer_attn(tfm_layer.cross_attn_img_to_token, k_2, q_2, queries, ctx0, model);
|
|
1749
|
+
keys = ggml_add_inplace(ctx0, keys, cross_attn_img_to_token);
|
|
1750
|
+
keys = ggml_norm_inplace(ctx0, keys, hparams.eps_decoder_transformer);
|
|
1751
|
+
keys = ggml_add_inplace(ctx0,
|
|
1752
|
+
ggml_mul(ctx0, keys, tfm_layer.norm4_w),
|
|
1753
|
+
tfm_layer.norm4_b);
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
// Apply the final attention layer from the points to the image
|
|
1757
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/transformer.py#L99
|
|
1758
|
+
struct ggml_tensor * q = ggml_add(ctx0, queries, tokens);
|
|
1759
|
+
struct ggml_tensor * k = ggml_add(ctx0, keys, pos_src);
|
|
1760
|
+
|
|
1761
|
+
struct ggml_tensor * final_attn_token_to_img = sam_decode_mask_transformer_attn(dec.transformer_final_attn_token_to_img, q, k, keys, ctx0, model);
|
|
1762
|
+
|
|
1763
|
+
queries = ggml_add_inplace(ctx0, queries, final_attn_token_to_img);
|
|
1764
|
+
queries = ggml_norm_inplace(ctx0, queries, hparams.eps_decoder_transformer);
|
|
1765
|
+
queries = ggml_add_inplace(ctx0,
|
|
1766
|
+
ggml_mul(ctx0, queries, dec.transformer_norm_final_w),
|
|
1767
|
+
dec.transformer_norm_final_b);
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
|
|
1771
|
+
struct ggml_tensor * iou_pred = ggml_view_2d(ctx0, queries, queries->ne[0], queries->ne[2], queries->nb[2], 0);
|
|
1772
|
+
const int num_mask_tokens = 4; // num_multimask_outputs + 1
|
|
1773
|
+
struct ggml_tensor * mask_tokens_out = ggml_view_3d(ctx0, queries, queries->ne[0], num_mask_tokens, queries->ne[2], queries->nb[1], num_mask_tokens*queries->nb[1], queries->nb[1]);
|
|
1774
|
+
|
|
1775
|
+
// Upscale mask embeddings and predict masks using the mask tokens
|
|
1776
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/mask_decoder.py#L136
|
|
1777
|
+
keys = ggml_cont(ctx0, ggml_transpose(ctx0, keys));
|
|
1778
|
+
keys = ggml_view_4d(ctx0, keys, srcNE[0], srcNE[1], srcNE[2], srcNE[3], srcNE[0]*keys->nb[0], keys->nb[1], keys->nb[2], 0);
|
|
1779
|
+
// ggml_build_forward_expand(gf, keys);
|
|
1780
|
+
struct ggml_tensor * upscaled_embedding = {};
|
|
1781
|
+
{
|
|
1782
|
+
// ConvTranspose2d
|
|
1783
|
+
keys = ggml_conv_transpose_2d_p0(ctx0, dec.output_upscaling_0_w, keys, 2);
|
|
1784
|
+
keys = ggml_add_inplace(ctx0, keys, ggml_repeat(ctx0,
|
|
1785
|
+
ggml_reshape_3d(ctx0, dec.output_upscaling_0_b, 1, 1, dec.output_upscaling_0_b->ne[0]),
|
|
1786
|
+
keys));
|
|
1787
|
+
|
|
1788
|
+
keys = sam_layer_norm_2d(ctx0, keys, n_img_embd, dec.output_upscaling_1_w, dec.output_upscaling_1_b, hparams.eps);
|
|
1789
|
+
|
|
1790
|
+
// GELU activation
|
|
1791
|
+
keys = ggml_gelu_inplace(ctx0, keys);
|
|
1792
|
+
|
|
1793
|
+
// ConvTranspose2d
|
|
1794
|
+
keys = ggml_conv_transpose_2d_p0(ctx0, dec.output_upscaling_3_w, keys, 2);
|
|
1795
|
+
keys = ggml_add_inplace(ctx0, ggml_repeat(ctx0,
|
|
1796
|
+
ggml_reshape_3d(ctx0, dec.output_upscaling_3_b, 1, 1, dec.output_upscaling_3_b->ne[0]),
|
|
1797
|
+
keys), keys);
|
|
1798
|
+
// GELU activation
|
|
1799
|
+
keys = ggml_gelu_inplace(ctx0, keys);
|
|
1800
|
+
upscaled_embedding = ggml_reshape_3d(ctx0, keys, keys->ne[0]*keys->ne[1], keys->ne[2], keys->ne[3]);
|
|
1801
|
+
upscaled_embedding = ggml_cont(ctx0, ggml_transpose(ctx0, upscaled_embedding)); // TODO: Shouldn't be needed
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
struct ggml_tensor * hyper_in = ggml_new_tensor_3d(ctx0, GGML_TYPE_F32, n_img_embd/2, num_mask_tokens, mask_tokens_out->ne[2]);
|
|
1805
|
+
|
|
1806
|
+
for (int i = 0; i < num_mask_tokens; ++i) {
|
|
1807
|
+
const auto& mlp = dec.output_hypernet_mlps[i];
|
|
1808
|
+
struct ggml_tensor * in = ggml_view_2d(ctx0, mask_tokens_out, mask_tokens_out->ne[0], mask_tokens_out->ne[2], mask_tokens_out->nb[1], i*mask_tokens_out->nb[1]);
|
|
1809
|
+
struct ggml_tensor * out = sam_decode_mask_mlp_relu_3(in, mlp.w_0, mlp.b_0, mlp.w_1, mlp.b_1, mlp.w_2, mlp.b_2, ctx0);
|
|
1810
|
+
ggml_build_forward_expand(gf, ggml_cpy(ctx0, out, ggml_view_2d(ctx0, hyper_in, hyper_in->ne[0], hyper_in->ne[2], hyper_in->nb[1], i*hyper_in->nb[1])));
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
struct ggml_tensor * masks = ggml_mul_mat(ctx0, hyper_in, upscaled_embedding);
|
|
1814
|
+
masks = ggml_cont(ctx0, ggml_transpose(ctx0, masks)); // TODO: Shouldn't be needed
|
|
1815
|
+
masks = ggml_reshape_4d(ctx0, masks, keys->ne[0], keys->ne[1], masks->ne[1], keys->ne[3]);
|
|
1816
|
+
|
|
1817
|
+
// Generate mask quality predictions
|
|
1818
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/mask_decoder.py#L146
|
|
1819
|
+
iou_pred = sam_decode_mask_mlp_relu_3(iou_pred, dec.iou_prediction_head_0_w, dec.iou_prediction_head_0_b, dec.iou_prediction_head_1_w, dec.iou_prediction_head_1_b, dec.iou_prediction_head_2_w, dec.iou_prediction_head_2_b, ctx0);
|
|
1820
|
+
|
|
1821
|
+
// Select the correct mask or masks for output
|
|
1822
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/mask_decoder.py#L101
|
|
1823
|
+
if (multimask_output) {
|
|
1824
|
+
iou_pred = ggml_cpy(state.ctx, ggml_view_1d(ctx0, iou_pred, iou_pred->ne[0] - 1, iou_pred->nb[0]), state.iou_predictions);
|
|
1825
|
+
masks = ggml_view_4d(ctx0, masks, masks->ne[0], masks->ne[1], masks->ne[2] - 1, masks->ne[3],
|
|
1826
|
+
masks->nb[1], masks->nb[2], masks->nb[3], masks->nb[2] /* offset*/);
|
|
1827
|
+
masks = ggml_cpy(state.ctx, masks, state.low_res_masks);
|
|
1828
|
+
} else {
|
|
1829
|
+
iou_pred = ggml_cpy(state.ctx, ggml_view_1d(ctx0, iou_pred, 1, 0), ggml_view_1d(ctx0, state.iou_predictions, 1, 0));
|
|
1830
|
+
masks = ggml_view_4d(ctx0, masks, masks->ne[0], masks->ne[1], 1, masks->ne[3],
|
|
1831
|
+
masks->nb[1], masks->nb[2], masks->nb[3], 0);
|
|
1832
|
+
auto * low_res_mask = ggml_view_4d(ctx0, state.low_res_masks, masks->ne[0], masks->ne[1], 1, masks->ne[3],
|
|
1833
|
+
masks->nb[1], masks->nb[2], masks->nb[3], 0);
|
|
1834
|
+
masks = ggml_cpy(state.ctx, masks, low_res_mask);
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
ggml_build_forward_expand(gf, masks);
|
|
1838
|
+
ggml_build_forward_expand(gf, iou_pred);
|
|
1839
|
+
|
|
1840
|
+
ggml_disconnect_node_from_graph(state.low_res_masks);
|
|
1841
|
+
ggml_disconnect_node_from_graph(state.iou_predictions);
|
|
1842
|
+
|
|
1843
|
+
return true;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
bool sam_write_masks(const sam_hparams& hparams, int nx, int ny, const sam_state & state, const std::string & fname, const bool multimask_output) {
|
|
1847
|
+
if (state.low_res_masks->ne[2] == 0) return true;
|
|
1848
|
+
if (state.low_res_masks->ne[2] != state.iou_predictions->ne[0]) {
|
|
1849
|
+
printf("Error: number of masks (%d) does not match number of iou predictions (%d)\n", (int)state.low_res_masks->ne[2], (int)state.iou_predictions->ne[0]);
|
|
1850
|
+
return false;
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
const int n_img_size = hparams.n_img_size();
|
|
1854
|
+
const float mask_threshold = hparams.mask_threshold;
|
|
1855
|
+
const float iou_threshold = hparams.iou_threshold;
|
|
1856
|
+
const float stability_score_threshold = hparams.stability_score_threshold;
|
|
1857
|
+
const float intersection_threshold = mask_threshold + hparams.stability_score_offset;
|
|
1858
|
+
const float union_threshold = mask_threshold - hparams.stability_score_offset;
|
|
1859
|
+
|
|
1860
|
+
const int ne0 = state.low_res_masks->ne[0];
|
|
1861
|
+
const int ne1 = state.low_res_masks->ne[1];
|
|
1862
|
+
const int ne2 = multimask_output ? state.low_res_masks->ne[2] : 1;
|
|
1863
|
+
|
|
1864
|
+
// Remove padding and upscale masks to the original image size.
|
|
1865
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/efeab7296ab579d4a261e554eca80faf6b33924a/segment_anything/modeling/sam.py#L140
|
|
1866
|
+
|
|
1867
|
+
const float preprocess_scale = std::max(nx, ny) / float(n_img_size);
|
|
1868
|
+
const int cropped_nx = int(nx / preprocess_scale + 0.5f);
|
|
1869
|
+
const int cropped_ny = int(ny / preprocess_scale + 0.5f);
|
|
1870
|
+
|
|
1871
|
+
const float scale_x_1 = (float)ne0 / (float)n_img_size;
|
|
1872
|
+
const float scale_y_1 = (float)ne1 / (float)n_img_size;
|
|
1873
|
+
|
|
1874
|
+
const float scale_x_2 = float(cropped_nx) / float(nx);
|
|
1875
|
+
const float scale_y_2 = float(cropped_ny) / float(ny);
|
|
1876
|
+
|
|
1877
|
+
const auto iou_data = (float*)state.iou_predictions->data;
|
|
1878
|
+
|
|
1879
|
+
for (int i = 0; i < ne2; ++i) {
|
|
1880
|
+
if (iou_threshold > 0.f && iou_data[i] < iou_threshold) {
|
|
1881
|
+
printf("Skipping mask %d with iou %f below threshold %f\n", i, iou_data[i], iou_threshold);
|
|
1882
|
+
continue; // Filtering masks with iou below the threshold
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
std::vector<float> mask_data(n_img_size*n_img_size);
|
|
1886
|
+
{
|
|
1887
|
+
const float* data = (float *) state.low_res_masks->data + i*ne0*ne1;
|
|
1888
|
+
|
|
1889
|
+
for (int iy = 0; iy < n_img_size; ++iy) {
|
|
1890
|
+
for (int ix = 0; ix < n_img_size; ++ix) {
|
|
1891
|
+
const float sx = std::max(scale_x_1*(ix + 0.5f) - 0.5f, 0.0f);
|
|
1892
|
+
const float sy = std::max(scale_y_1*(iy + 0.5f) - 0.5f, 0.0f);
|
|
1893
|
+
|
|
1894
|
+
const int x0 = std::max(0, (int)sx);
|
|
1895
|
+
const int y0 = std::max(0, (int)sy);
|
|
1896
|
+
|
|
1897
|
+
const int x1 = std::min(x0 + 1, ne0 - 1);
|
|
1898
|
+
const int y1 = std::min(y0 + 1, ne1 - 1);
|
|
1899
|
+
|
|
1900
|
+
const float dx = sx - x0;
|
|
1901
|
+
const float dy = sy - y0;
|
|
1902
|
+
|
|
1903
|
+
const int j00 = y0*ne0 + x0;
|
|
1904
|
+
const int j01 = y0*ne0 + x1;
|
|
1905
|
+
const int j10 = y1*ne0 + x0;
|
|
1906
|
+
const int j11 = y1*ne0 + x1;
|
|
1907
|
+
|
|
1908
|
+
const float v00 = data[j00];
|
|
1909
|
+
const float v01 = data[j01];
|
|
1910
|
+
const float v10 = data[j10];
|
|
1911
|
+
const float v11 = data[j11];
|
|
1912
|
+
|
|
1913
|
+
const float v0 = (1-dx)*v00 + dx*v01;
|
|
1914
|
+
const float v1 = (1-dx)*v10 + dx*v11;
|
|
1915
|
+
|
|
1916
|
+
const float v = (1-dy)*v0 + dy*v1;
|
|
1917
|
+
|
|
1918
|
+
mask_data[iy*n_img_size + ix] = v;
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
int intersections = 0;
|
|
1924
|
+
int unions = 0;
|
|
1925
|
+
sam_image_u8 res;
|
|
1926
|
+
int min_iy = ny;
|
|
1927
|
+
int max_iy = 0;
|
|
1928
|
+
int min_ix = nx;
|
|
1929
|
+
int max_ix = 0;
|
|
1930
|
+
{
|
|
1931
|
+
const float* data = mask_data.data();
|
|
1932
|
+
|
|
1933
|
+
res.nx = nx;
|
|
1934
|
+
res.ny = ny;
|
|
1935
|
+
res.data.resize(nx*ny);
|
|
1936
|
+
|
|
1937
|
+
for (int iy = 0; iy < ny; ++iy) {
|
|
1938
|
+
for (int ix = 0; ix < nx; ++ix) {
|
|
1939
|
+
const float sx = std::max(scale_x_2*(ix + 0.5f) - 0.5f, 0.0f);
|
|
1940
|
+
const float sy = std::max(scale_y_2*(iy + 0.5f) - 0.5f, 0.0f);
|
|
1941
|
+
|
|
1942
|
+
const int x0 = std::max(0, (int)sx);
|
|
1943
|
+
const int y0 = std::max(0, (int)sy);
|
|
1944
|
+
|
|
1945
|
+
const int x1 = std::min(x0 + 1, cropped_nx - 1);
|
|
1946
|
+
const int y1 = std::min(y0 + 1, cropped_ny - 1);
|
|
1947
|
+
|
|
1948
|
+
const float dx = sx - x0;
|
|
1949
|
+
const float dy = sy - y0;
|
|
1950
|
+
|
|
1951
|
+
const int j00 = y0*n_img_size + x0;
|
|
1952
|
+
const int j01 = y0*n_img_size + x1;
|
|
1953
|
+
const int j10 = y1*n_img_size + x0;
|
|
1954
|
+
const int j11 = y1*n_img_size + x1;
|
|
1955
|
+
|
|
1956
|
+
const float v00 = data[j00];
|
|
1957
|
+
const float v01 = data[j01];
|
|
1958
|
+
const float v10 = data[j10];
|
|
1959
|
+
const float v11 = data[j11];
|
|
1960
|
+
|
|
1961
|
+
const float v0 = (1-dx)*v00 + dx*v01;
|
|
1962
|
+
const float v1 = (1-dx)*v10 + dx*v11;
|
|
1963
|
+
|
|
1964
|
+
const float v = (1-dy)*v0 + dy*v1;
|
|
1965
|
+
|
|
1966
|
+
if (v > intersection_threshold) {
|
|
1967
|
+
intersections++;
|
|
1968
|
+
}
|
|
1969
|
+
if (v > union_threshold) {
|
|
1970
|
+
unions++;
|
|
1971
|
+
}
|
|
1972
|
+
if (v > mask_threshold) {
|
|
1973
|
+
min_iy = std::min(min_iy, iy);
|
|
1974
|
+
max_iy = std::max(max_iy, iy);
|
|
1975
|
+
min_ix = std::min(min_ix, ix);
|
|
1976
|
+
max_ix = std::max(max_ix, ix);
|
|
1977
|
+
|
|
1978
|
+
res.data[iy*nx + ix] = 255;
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
const float stability_score = float(intersections) / float(unions);
|
|
1985
|
+
if (stability_score_threshold > 0.f && stability_score < stability_score_threshold) {
|
|
1986
|
+
printf("Skipping mask %d with stability score %f below threshold %f\n", i, stability_score, stability_score_threshold);
|
|
1987
|
+
continue; // Filtering masks with stability score below the threshold
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
printf("Mask %d: iou = %f, stability_score = %f, bbox (%d, %d), (%d, %d)\n",
|
|
1991
|
+
i, iou_data[i], stability_score, min_ix, max_ix, min_iy, max_iy);
|
|
1992
|
+
|
|
1993
|
+
const std::string filename = multimask_output ? fname + std::to_string(i) + ".png" : fname + ".png";
|
|
1994
|
+
if (!stbi_write_png(filename.c_str(), res.nx, res.ny, 1, res.data.data(), res.nx)) {
|
|
1995
|
+
printf("%s: failed to write mask %s\n", __func__, filename.c_str());
|
|
1996
|
+
return false;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
return true;
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
|
|
2005
|
+
struct ggml_cgraph * sam_build_fast_graph(
|
|
2006
|
+
const sam_model & model,
|
|
2007
|
+
sam_state & state,
|
|
2008
|
+
const int nx,
|
|
2009
|
+
const int ny,
|
|
2010
|
+
const sam_prompt & prompt,
|
|
2011
|
+
const bool multimask_output) {
|
|
2012
|
+
|
|
2013
|
+
struct ggml_init_params ggml_params = {
|
|
2014
|
+
/*.mem_size =*/ state.buf_compute_fast.size(),
|
|
2015
|
+
/*.mem_buffer =*/ state.buf_compute_fast.data(),
|
|
2016
|
+
/*.no_alloc =*/ true, // skip allocating as we use ggml_alloc to allocate exact memory requirements
|
|
2017
|
+
};
|
|
2018
|
+
|
|
2019
|
+
struct ggml_context * ctx0 = ggml_init(ggml_params);
|
|
2020
|
+
struct ggml_cgraph * gf = ggml_new_graph(ctx0);
|
|
2021
|
+
|
|
2022
|
+
prompt_encoder_result enc_res = sam_encode_prompt(model, ctx0, gf, state, prompt);
|
|
2023
|
+
if (!enc_res.embd_prompt_sparse || !enc_res.embd_prompt_dense) {
|
|
2024
|
+
fprintf(stderr, "%s: failed to encode prompt\n", __func__);
|
|
2025
|
+
return {};
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
struct ggml_tensor * pe_img_dense = sam_fill_dense_pe(model, ctx0, gf, state);
|
|
2029
|
+
if (!pe_img_dense) {
|
|
2030
|
+
fprintf(stderr, "%s: failed to get dense positional encoding\n", __func__);
|
|
2031
|
+
return {};
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
if (!sam_decode_mask(model, enc_res, pe_img_dense, ctx0, gf, state, multimask_output)) {
|
|
2035
|
+
fprintf(stderr, "%s: failed to decode mask\n", __func__);
|
|
2036
|
+
return {};
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
ggml_free(ctx0);
|
|
2040
|
+
|
|
2041
|
+
ggml_gallocr_alloc_graph(state.allocr, gf);
|
|
2042
|
+
|
|
2043
|
+
struct ggml_tensor * inp = ggml_graph_get_tensor(gf, "prompt_input");
|
|
2044
|
+
auto * data = (float *) inp->data;
|
|
2045
|
+
|
|
2046
|
+
// Transform prompt (point or box)
|
|
2047
|
+
{
|
|
2048
|
+
// https://github.com/facebookresearch/segment-anything/blob/dca509fe793f601edb92606367a655c15ac00fdf/segment_anything/utils/transforms.py#L33
|
|
2049
|
+
// The point scaling here is greatly simplified but mathematically equivalent.
|
|
2050
|
+
const auto scale = 1.0F / std::max(nx, ny);
|
|
2051
|
+
|
|
2052
|
+
switch (prompt.prompt_type) {
|
|
2053
|
+
case SAM_PROMPT_TYPE_POINT: {
|
|
2054
|
+
const auto & pt = prompt.pt;
|
|
2055
|
+
|
|
2056
|
+
// set the input by converting the [0, 1] coordinates to [-1, 1]
|
|
2057
|
+
data[0] = 2.0f*pt.x*scale - 1.0f;
|
|
2058
|
+
data[1] = 2.0f*pt.y*scale - 1.0f;
|
|
2059
|
+
|
|
2060
|
+
// padding
|
|
2061
|
+
// ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/prompt_encoder.py#L81-L85
|
|
2062
|
+
data[2] = 2.0f*(0.0f) - 1.0f;
|
|
2063
|
+
data[3] = 2.0f*(0.0f) - 1.0f;
|
|
2064
|
+
} break;
|
|
2065
|
+
case SAM_PROMPT_TYPE_BOX: {
|
|
2066
|
+
const auto & box = prompt.box;
|
|
2067
|
+
|
|
2068
|
+
data[0] = 2.0f*box.x1*scale - 1.0f;
|
|
2069
|
+
data[1] = 2.0f*box.y1*scale - 1.0f;
|
|
2070
|
+
data[2] = 2.0f*box.x2*scale - 1.0f;
|
|
2071
|
+
data[3] = 2.0f*box.y2*scale - 1.0f;
|
|
2072
|
+
} break;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
// from sam_fill_dense_pe
|
|
2077
|
+
{
|
|
2078
|
+
struct ggml_tensor * xy_embed_stacked = ggml_graph_get_tensor(gf, "xy_embed_stacked");
|
|
2079
|
+
const int32_t n_img_embd = model.hparams.n_img_embd();
|
|
2080
|
+
const float n_img_embd_inv = 1.0f / n_img_embd;
|
|
2081
|
+
float * data = (float *) ggml_get_data(xy_embed_stacked);
|
|
2082
|
+
for (int i = 0; i < n_img_embd; ++i) {
|
|
2083
|
+
const int row = 2*i*n_img_embd;
|
|
2084
|
+
const float y_val = 2 * (i + 0.5f) * n_img_embd_inv - 1;
|
|
2085
|
+
for (int j = 0; j < n_img_embd; ++j) {
|
|
2086
|
+
const float x_val = 2 * (j + 0.5f) * n_img_embd_inv - 1;
|
|
2087
|
+
data[row + 2*j + 0] = x_val;
|
|
2088
|
+
data[row + 2*j + 1] = y_val;
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
return gf;
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
void sam_print_usage(int argc, char ** argv, const sam_params & params) {
|
|
2097
|
+
fprintf(stderr, "usage: %s [options]\n", argv[0]);
|
|
2098
|
+
fprintf(stderr, "\n");
|
|
2099
|
+
fprintf(stderr, "options:\n");
|
|
2100
|
+
fprintf(stderr, " -h, --help show this help message and exit\n");
|
|
2101
|
+
fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1)\n");
|
|
2102
|
+
fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
|
|
2103
|
+
fprintf(stderr, " -m FNAME, --model FNAME\n");
|
|
2104
|
+
fprintf(stderr, " model path (default: %s)\n", params.model.c_str());
|
|
2105
|
+
fprintf(stderr, " -i FNAME, --inp FNAME\n");
|
|
2106
|
+
fprintf(stderr, " input file (default: %s)\n", params.fname_inp.c_str());
|
|
2107
|
+
fprintf(stderr, " -o FNAME, --out FNAME\n");
|
|
2108
|
+
fprintf(stderr, " mask file name prefix (default: %s)\n", params.fname_out.c_str());
|
|
2109
|
+
fprintf(stderr, " -sm, --single-mask\n");
|
|
2110
|
+
fprintf(stderr, " single mask output (default multi mask output)\n");
|
|
2111
|
+
fprintf(stderr, "SAM hyperparameters:\n");
|
|
2112
|
+
fprintf(stderr, " -mt FLOAT, --mask-threshold\n");
|
|
2113
|
+
fprintf(stderr, " mask threshold (default: %f)\n", params.mask_threshold);
|
|
2114
|
+
fprintf(stderr, " -it FLOAT, --iou-threshold\n");
|
|
2115
|
+
fprintf(stderr, " iou threshold (default: %f)\n", params.iou_threshold);
|
|
2116
|
+
fprintf(stderr, " -st FLOAT, --score-threshold\n");
|
|
2117
|
+
fprintf(stderr, " score threshold (default: %f)\n", params.stability_score_threshold);
|
|
2118
|
+
fprintf(stderr, " -so FLOAT, --score-offset\n");
|
|
2119
|
+
fprintf(stderr, " score offset (default: %f)\n", params.stability_score_offset);
|
|
2120
|
+
fprintf(stderr, " -e FLOAT, --epsilon\n");
|
|
2121
|
+
fprintf(stderr, " epsilon (default: %f)\n", params.eps);
|
|
2122
|
+
fprintf(stderr, " -ed FLOAT, --epsilon-decoder-transformer\n");
|
|
2123
|
+
fprintf(stderr, " epsilon decoder transformer (default: %f)\n", params.eps_decoder_transformer);
|
|
2124
|
+
fprintf(stderr, "SAM prompt:\n");
|
|
2125
|
+
fprintf(stderr, " -p [x,y], --point-prompt\n");
|
|
2126
|
+
fprintf(stderr, " point to be used as prompt for SAM (default: %f,%f). Must be in a format FLOAT,FLOAT \n", params.prompt.pt.x, params.prompt.pt.y);
|
|
2127
|
+
fprintf(stderr, " -b [x1,y1,x2,y2], --box-prompt\n");
|
|
2128
|
+
fprintf(stderr, " box to be used as prompt for SAM (default: %f,%f,%f,%f). Must be in a format FLOAT,FLOAT,FLOAT,FLOAT \n",
|
|
2129
|
+
params.prompt.box.x1, params.prompt.box.y1, params.prompt.box.x2, params.prompt.box.y2);
|
|
2130
|
+
fprintf(stderr, "\n");
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
bool sam_params_parse(int argc, char ** argv, sam_params & params) {
|
|
2134
|
+
|
|
2135
|
+
bool use_point_prompt = false;
|
|
2136
|
+
bool use_box_prompt = false;
|
|
2137
|
+
|
|
2138
|
+
for (int i = 1; i < argc; i++) {
|
|
2139
|
+
std::string arg = argv[i];
|
|
2140
|
+
|
|
2141
|
+
if (arg == "-s" || arg == "--seed") {
|
|
2142
|
+
params.seed = std::stoi(argv[++i]);
|
|
2143
|
+
} else if (arg == "-t" || arg == "--threads") {
|
|
2144
|
+
params.n_threads = std::stoi(argv[++i]);
|
|
2145
|
+
} else if (arg == "-m" || arg == "--model") {
|
|
2146
|
+
params.model = argv[++i];
|
|
2147
|
+
} else if (arg == "-i" || arg == "--inp") {
|
|
2148
|
+
params.fname_inp = argv[++i];
|
|
2149
|
+
} else if (arg == "-o" || arg == "--out") {
|
|
2150
|
+
params.fname_out = argv[++i];
|
|
2151
|
+
} else if (arg == "-sm" || arg == "--single-mask") {
|
|
2152
|
+
params.multimask_output = false;
|
|
2153
|
+
} else if (arg == "-mt" || arg == "--mask-threshold") {
|
|
2154
|
+
params.mask_threshold = std::stof(argv[++i]);
|
|
2155
|
+
} else if (arg == "-it" || arg == "--iou-threshold") {
|
|
2156
|
+
params.iou_threshold = std::stof(argv[++i]);
|
|
2157
|
+
} else if (arg == "-st" || arg == "--score-threshold") {
|
|
2158
|
+
params.stability_score_threshold = std::stof(argv[++i]);
|
|
2159
|
+
} else if (arg == "-so" || arg == "--score-offset") {
|
|
2160
|
+
params.stability_score_offset = std::stof(argv[++i]);
|
|
2161
|
+
} else if (arg == "-e" || arg == "--epsilon") {
|
|
2162
|
+
params.eps = std::stof(argv[++i]);
|
|
2163
|
+
} else if (arg == "-ed" || arg == "--epsilon-decoder-transformer") {
|
|
2164
|
+
params.eps_decoder_transformer = std::stof(argv[++i]);
|
|
2165
|
+
} else if (arg == "-p" || arg == "--point-prompt") {
|
|
2166
|
+
// TODO multiple points per model invocation
|
|
2167
|
+
use_point_prompt = true;
|
|
2168
|
+
char* point = argv[++i];
|
|
2169
|
+
|
|
2170
|
+
char* coord = strtok(point, ",");
|
|
2171
|
+
if (!coord){
|
|
2172
|
+
fprintf(stderr, "Error while parsing prompt!\n");
|
|
2173
|
+
exit(1);
|
|
2174
|
+
}
|
|
2175
|
+
params.prompt.pt.x = std::stof(coord);
|
|
2176
|
+
|
|
2177
|
+
coord = strtok(NULL, ",");
|
|
2178
|
+
if (!coord){
|
|
2179
|
+
fprintf(stderr, "Error while parsing prompt!\n");
|
|
2180
|
+
exit(1);
|
|
2181
|
+
}
|
|
2182
|
+
params.prompt.pt.y = std::stof(coord);
|
|
2183
|
+
} else if (arg == "-b" || arg == "--box-prompt") {
|
|
2184
|
+
use_box_prompt = true;
|
|
2185
|
+
char * box_prompt = argv[++i];
|
|
2186
|
+
float box_vals[4];
|
|
2187
|
+
|
|
2188
|
+
char * val = strtok(box_prompt, ",");
|
|
2189
|
+
if (!val) {
|
|
2190
|
+
fprintf(stderr, "Error while parsing prompt!\n");
|
|
2191
|
+
exit(1);
|
|
2192
|
+
}
|
|
2193
|
+
box_vals[0] = std::stof(val);
|
|
2194
|
+
|
|
2195
|
+
for (int j = 1; j < 4; ++j) {
|
|
2196
|
+
char * val = strtok(NULL, ",");
|
|
2197
|
+
if (!val) {
|
|
2198
|
+
fprintf(stderr, "Error while parsing prompt!\n");
|
|
2199
|
+
exit(1);
|
|
2200
|
+
}
|
|
2201
|
+
box_vals[j] = std::stof(val);
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
params.prompt.box.x1 = box_vals[0];
|
|
2205
|
+
params.prompt.box.y1 = box_vals[1];
|
|
2206
|
+
params.prompt.box.x2 = box_vals[2];
|
|
2207
|
+
params.prompt.box.y2 = box_vals[3];
|
|
2208
|
+
} else if (arg == "-h" || arg == "--help") {
|
|
2209
|
+
sam_print_usage(argc, argv, params);
|
|
2210
|
+
exit(0);
|
|
2211
|
+
} else {
|
|
2212
|
+
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
|
|
2213
|
+
sam_print_usage(argc, argv, params);
|
|
2214
|
+
exit(0);
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
if (use_box_prompt && use_point_prompt) {
|
|
2219
|
+
fprintf(stderr, "Error: use either point or box prompt, not both.\n");
|
|
2220
|
+
exit(1);
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
params.prompt.prompt_type = SAM_PROMPT_TYPE_POINT;
|
|
2224
|
+
if (use_box_prompt) {
|
|
2225
|
+
params.prompt.prompt_type = SAM_PROMPT_TYPE_BOX;
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
return true;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
|
|
2232
|
+
int main(int argc, char ** argv) {
|
|
2233
|
+
ggml_time_init();
|
|
2234
|
+
const int64_t t_main_start_us = ggml_time_us();
|
|
2235
|
+
|
|
2236
|
+
sam_params params;
|
|
2237
|
+
params.model = "models/sam-vit-b/ggml-model-f16.bin";
|
|
2238
|
+
|
|
2239
|
+
sam_model model;
|
|
2240
|
+
sam_state state;
|
|
2241
|
+
int64_t t_load_us = 0;
|
|
2242
|
+
|
|
2243
|
+
if (sam_params_parse(argc, argv, params) == false) {
|
|
2244
|
+
return 1;
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
if (params.seed < 0) {
|
|
2248
|
+
params.seed = time(NULL);
|
|
2249
|
+
}
|
|
2250
|
+
fprintf(stderr, "%s: seed = %d\n", __func__, params.seed);
|
|
2251
|
+
|
|
2252
|
+
// load the image
|
|
2253
|
+
sam_image_u8 img0;
|
|
2254
|
+
if (!sam_image_load_from_file(params.fname_inp, img0)) {
|
|
2255
|
+
fprintf(stderr, "%s: failed to load image from '%s'\n", __func__, params.fname_inp.c_str());
|
|
2256
|
+
return 1;
|
|
2257
|
+
}
|
|
2258
|
+
fprintf(stderr, "%s: loaded image '%s' (%d x %d)\n", __func__, params.fname_inp.c_str(), img0.nx, img0.ny);
|
|
2259
|
+
|
|
2260
|
+
// preprocess to f32
|
|
2261
|
+
sam_image_f32 img1;
|
|
2262
|
+
if (!sam_image_preprocess(img0, img1)) {
|
|
2263
|
+
fprintf(stderr, "%s: failed to preprocess image\n", __func__);
|
|
2264
|
+
return 1;
|
|
2265
|
+
}
|
|
2266
|
+
fprintf(stderr, "%s: preprocessed image (%d x %d)\n", __func__, img1.nx, img1.ny);
|
|
2267
|
+
|
|
2268
|
+
|
|
2269
|
+
// load the model
|
|
2270
|
+
{
|
|
2271
|
+
const int64_t t_start_us = ggml_time_us();
|
|
2272
|
+
|
|
2273
|
+
if (!sam_model_load(params, model)) {
|
|
2274
|
+
fprintf(stderr, "%s: failed to load model from '%s'\n", __func__, params.model.c_str());
|
|
2275
|
+
return 1;
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
t_load_us = ggml_time_us() - t_start_us;
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
{
|
|
2282
|
+
static size_t buf_size = 256u*1024*1024;
|
|
2283
|
+
|
|
2284
|
+
struct ggml_init_params ggml_params = {
|
|
2285
|
+
/*.mem_size =*/ buf_size,
|
|
2286
|
+
/*.mem_buffer =*/ NULL,
|
|
2287
|
+
/*.no_alloc =*/ false,
|
|
2288
|
+
};
|
|
2289
|
+
|
|
2290
|
+
state.ctx = ggml_init(ggml_params);
|
|
2291
|
+
|
|
2292
|
+
state.embd_img = ggml_new_tensor_3d(state.ctx, GGML_TYPE_F32,
|
|
2293
|
+
model.hparams.n_img_embd(), model.hparams.n_img_embd(), model.hparams.n_enc_out_chans);
|
|
2294
|
+
|
|
2295
|
+
state.low_res_masks = ggml_new_tensor_3d(state.ctx, GGML_TYPE_F32,
|
|
2296
|
+
model.hparams.n_enc_out_chans, model.hparams.n_enc_out_chans, 3);
|
|
2297
|
+
|
|
2298
|
+
state.iou_predictions = ggml_new_tensor_1d(state.ctx, GGML_TYPE_F32, 3);
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
// Encode image
|
|
2302
|
+
{
|
|
2303
|
+
state.buf_compute_img_enc.resize(ggml_tensor_overhead()*GGML_DEFAULT_GRAPH_SIZE + ggml_graph_overhead());
|
|
2304
|
+
state.allocr = ggml_gallocr_new(ggml_backend_cpu_buffer_type());
|
|
2305
|
+
|
|
2306
|
+
struct ggml_cgraph * gf = sam_encode_image(model, state, img1);
|
|
2307
|
+
if (!gf) {
|
|
2308
|
+
fprintf(stderr, "%s: failed to encode image\n", __func__);
|
|
2309
|
+
return 1;
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
ggml_graph_compute_helper(state.work_buffer, gf, params.n_threads);
|
|
2313
|
+
|
|
2314
|
+
// print_t_f32("embd_img", state.embd_img);
|
|
2315
|
+
|
|
2316
|
+
ggml_gallocr_free(state.allocr);
|
|
2317
|
+
state.allocr = NULL;
|
|
2318
|
+
state.work_buffer.clear();
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
// Encode prompt and decode mask
|
|
2322
|
+
{
|
|
2323
|
+
state.buf_compute_fast.resize(ggml_tensor_overhead()*GGML_DEFAULT_GRAPH_SIZE + ggml_graph_overhead());
|
|
2324
|
+
state.allocr = ggml_gallocr_new(ggml_backend_cpu_buffer_type());
|
|
2325
|
+
|
|
2326
|
+
switch (params.prompt.prompt_type) {
|
|
2327
|
+
case SAM_PROMPT_TYPE_POINT:
|
|
2328
|
+
fprintf(stderr, "Using point prompt: (%f, %f)\n", params.prompt.pt.x, params.prompt.pt.y);
|
|
2329
|
+
break;
|
|
2330
|
+
case SAM_PROMPT_TYPE_BOX:
|
|
2331
|
+
fprintf(stderr, "Using box prompt: (%f, %f, %f, %f)\n",
|
|
2332
|
+
params.prompt.box.x1,
|
|
2333
|
+
params.prompt.box.y1,
|
|
2334
|
+
params.prompt.box.x2,
|
|
2335
|
+
params.prompt.box.y2);
|
|
2336
|
+
break;
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
struct ggml_cgraph * gf = sam_build_fast_graph(model, state, img0.nx, img0.ny, params.prompt, params.multimask_output);
|
|
2340
|
+
if (!gf) {
|
|
2341
|
+
fprintf(stderr, "%s: failed to build fast graph\n", __func__);
|
|
2342
|
+
return 1;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
ggml_graph_compute_helper(state.work_buffer, gf, params.n_threads);
|
|
2346
|
+
|
|
2347
|
+
//print_t_f32("iou_predictions", state.iou_predictions);
|
|
2348
|
+
//print_t_f32("low_res_masks", state.low_res_masks);
|
|
2349
|
+
ggml_gallocr_free(state.allocr);
|
|
2350
|
+
state.allocr = NULL;
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
if (!sam_write_masks(model.hparams, img0.nx, img0.ny, state, params.fname_out, params.multimask_output)) {
|
|
2354
|
+
fprintf(stderr, "%s: failed to write masks\n", __func__);
|
|
2355
|
+
return 1;
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
// report timing
|
|
2359
|
+
{
|
|
2360
|
+
const int64_t t_main_end_us = ggml_time_us();
|
|
2361
|
+
|
|
2362
|
+
fprintf(stderr, "\n\n");
|
|
2363
|
+
fprintf(stderr, "%s: load time = %8.2f ms\n", __func__, t_load_us/1000.0f);
|
|
2364
|
+
fprintf(stderr, "%s: total time = %8.2f ms\n", __func__, (t_main_end_us - t_main_start_us)/1000.0f);
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
ggml_free(model.ctx);
|
|
2368
|
+
|
|
2369
|
+
return 0;
|
|
2370
|
+
}
|