@fugood/llama.node 0.6.3 → 1.0.0-beta.2
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.
- package/CMakeLists.txt +40 -30
- package/README.md +4 -1
- package/lib/binding.js +41 -29
- package/lib/binding.ts +26 -25
- package/package.json +40 -7
- package/scripts/build.js +47 -0
- package/scripts/llama.cpp.patch +109 -0
- package/src/anyascii.c +22223 -0
- package/src/anyascii.h +42 -0
- package/src/tts_utils.cpp +20 -7
- package/src/tts_utils.h +2 -0
- package/bin/darwin/arm64/llama-node.node +0 -0
- package/bin/darwin/x64/llama-node.node +0 -0
- package/bin/linux/arm64/llama-node.node +0 -0
- package/bin/linux/x64/llama-node.node +0 -0
- package/bin/linux-cuda/arm64/llama-node.node +0 -0
- package/bin/linux-cuda/x64/llama-node.node +0 -0
- package/bin/linux-vulkan/arm64/llama-node.node +0 -0
- package/bin/linux-vulkan/x64/llama-node.node +0 -0
- package/bin/win32/x64/llama-node.node +0 -0
- package/bin/win32/x64/node.lib +0 -0
- package/bin/win32-vulkan/arm64/llama-node.node +0 -0
- package/bin/win32-vulkan/arm64/node.lib +0 -0
- package/bin/win32-vulkan/x64/llama-node.node +0 -0
- package/bin/win32-vulkan/x64/node.lib +0 -0
- package/src/llama.cpp/.github/workflows/build-linux-cross.yml +0 -233
- package/src/llama.cpp/.github/workflows/build.yml +0 -1078
- package/src/llama.cpp/.github/workflows/close-issue.yml +0 -28
- package/src/llama.cpp/.github/workflows/docker.yml +0 -178
- package/src/llama.cpp/.github/workflows/editorconfig.yml +0 -29
- package/src/llama.cpp/.github/workflows/gguf-publish.yml +0 -44
- package/src/llama.cpp/.github/workflows/labeler.yml +0 -17
- package/src/llama.cpp/.github/workflows/python-check-requirements.yml +0 -33
- package/src/llama.cpp/.github/workflows/python-lint.yml +0 -30
- package/src/llama.cpp/.github/workflows/python-type-check.yml +0 -40
- package/src/llama.cpp/.github/workflows/release.yml +0 -739
- package/src/llama.cpp/.github/workflows/server.yml +0 -237
- package/src/llama.cpp/.github/workflows/winget.yml +0 -42
- package/src/llama.cpp/cmake/arm64-apple-clang.cmake +0 -16
- package/src/llama.cpp/cmake/arm64-windows-llvm.cmake +0 -16
- package/src/llama.cpp/cmake/build-info.cmake +0 -64
- package/src/llama.cpp/cmake/common.cmake +0 -35
- package/src/llama.cpp/cmake/git-vars.cmake +0 -22
- package/src/llama.cpp/cmake/x64-windows-llvm.cmake +0 -5
- package/src/llama.cpp/common/build-info.cpp.in +0 -4
- package/src/llama.cpp/docs/build.md +0 -561
- package/src/llama.cpp/examples/CMakeLists.txt +0 -43
- package/src/llama.cpp/examples/batched/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/batched/batched.cpp +0 -246
- package/src/llama.cpp/examples/chat-13B.bat +0 -57
- package/src/llama.cpp/examples/convert-llama2c-to-ggml/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +0 -941
- package/src/llama.cpp/examples/deprecation-warning/deprecation-warning.cpp +0 -35
- package/src/llama.cpp/examples/embedding/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/embedding/embedding.cpp +0 -323
- package/src/llama.cpp/examples/eval-callback/CMakeLists.txt +0 -10
- package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +0 -194
- package/src/llama.cpp/examples/gen-docs/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +0 -83
- package/src/llama.cpp/examples/gguf/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/gguf/gguf.cpp +0 -265
- package/src/llama.cpp/examples/gguf-hash/CMakeLists.txt +0 -22
- package/src/llama.cpp/examples/gguf-hash/deps/rotate-bits/rotate-bits.h +0 -46
- package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.c +0 -295
- package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.h +0 -52
- package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.c +0 -221
- package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.h +0 -24
- package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.c +0 -42
- package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.h +0 -7093
- package/src/llama.cpp/examples/gguf-hash/gguf-hash.cpp +0 -694
- package/src/llama.cpp/examples/gritlm/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/gritlm/gritlm.cpp +0 -229
- package/src/llama.cpp/examples/jeopardy/questions.txt +0 -100
- package/src/llama.cpp/examples/llama.android/app/build.gradle.kts +0 -65
- package/src/llama.cpp/examples/llama.android/build.gradle.kts +0 -6
- package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +0 -71
- package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/CMakeLists.txt +0 -53
- package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +0 -452
- package/src/llama.cpp/examples/llama.android/settings.gradle.kts +0 -18
- package/src/llama.cpp/examples/lookahead/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/lookahead/lookahead.cpp +0 -472
- package/src/llama.cpp/examples/lookup/CMakeLists.txt +0 -23
- package/src/llama.cpp/examples/lookup/lookup-create.cpp +0 -40
- package/src/llama.cpp/examples/lookup/lookup-merge.cpp +0 -47
- package/src/llama.cpp/examples/lookup/lookup-stats.cpp +0 -157
- package/src/llama.cpp/examples/lookup/lookup.cpp +0 -242
- package/src/llama.cpp/examples/parallel/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/parallel/parallel.cpp +0 -492
- package/src/llama.cpp/examples/passkey/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/passkey/passkey.cpp +0 -277
- package/src/llama.cpp/examples/retrieval/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/retrieval/retrieval.cpp +0 -304
- package/src/llama.cpp/examples/save-load-state/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +0 -246
- package/src/llama.cpp/examples/simple/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/simple/simple.cpp +0 -206
- package/src/llama.cpp/examples/simple-chat/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +0 -206
- package/src/llama.cpp/examples/simple-cmake-pkg/CMakeLists.txt +0 -11
- package/src/llama.cpp/examples/speculative/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/speculative/speculative.cpp +0 -644
- package/src/llama.cpp/examples/speculative-simple/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/speculative-simple/speculative-simple.cpp +0 -261
- package/src/llama.cpp/examples/sycl/CMakeLists.txt +0 -9
- package/src/llama.cpp/examples/sycl/build.sh +0 -23
- package/src/llama.cpp/examples/sycl/ls-sycl-device.cpp +0 -13
- package/src/llama.cpp/examples/sycl/run-llama2.sh +0 -27
- package/src/llama.cpp/examples/sycl/run-llama3.sh +0 -28
- package/src/llama.cpp/examples/sycl/win-build-sycl.bat +0 -33
- package/src/llama.cpp/examples/sycl/win-run-llama2.bat +0 -9
- package/src/llama.cpp/examples/sycl/win-run-llama3.bat +0 -9
- package/src/llama.cpp/examples/training/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/training/finetune.cpp +0 -96
- package/src/llama.cpp/ggml/cmake/GitVars.cmake +0 -22
- package/src/llama.cpp/ggml/cmake/common.cmake +0 -26
- package/src/llama.cpp/ggml/src/ggml-alloc.c +0 -1042
- package/src/llama.cpp/ggml/src/ggml-backend-impl.h +0 -255
- package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +0 -586
- package/src/llama.cpp/ggml/src/ggml-backend.cpp +0 -2008
- package/src/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +0 -87
- package/src/llama.cpp/ggml/src/ggml-blas/ggml-blas.cpp +0 -517
- package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +0 -74
- package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +0 -179
- package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +0 -258
- package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +0 -2863
- package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +0 -1110
- package/src/llama.cpp/ggml/src/ggml-cann/common.h +0 -420
- package/src/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +0 -2570
- package/src/llama.cpp/ggml/src/ggml-common.h +0 -1857
- package/src/llama.cpp/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +0 -100
- package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +0 -184
- package/src/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +0 -15
- package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +0 -243
- package/src/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +0 -140
- package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +0 -131
- package/src/llama.cpp/ggml/src/ggml-impl.h +0 -601
- package/src/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +0 -166
- package/src/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +0 -2251
- package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +0 -120
- package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +0 -622
- package/src/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +0 -113
- package/src/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +0 -96
- package/src/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +0 -5124
- package/src/llama.cpp/ggml/src/ggml-opt.cpp +0 -1037
- package/src/llama.cpp/ggml/src/ggml-quants.c +0 -5232
- package/src/llama.cpp/ggml/src/ggml-quants.h +0 -100
- package/src/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +0 -9
- package/src/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +0 -1813
- package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +0 -189
- package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +0 -37
- package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +0 -239
- package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.hpp +0 -39
- package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +0 -83
- package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +0 -493
- package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +0 -197
- package/src/llama.cpp/ggml/src/ggml-sycl/concat.hpp +0 -20
- package/src/llama.cpp/ggml/src/ggml-sycl/conv.cpp +0 -100
- package/src/llama.cpp/ggml/src/ggml-sycl/conv.hpp +0 -20
- package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +0 -623
- package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +0 -34
- package/src/llama.cpp/ggml/src/ggml-sycl/cpy.cpp +0 -701
- package/src/llama.cpp/ggml/src/ggml-sycl/cpy.hpp +0 -11
- package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +0 -791
- package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +0 -1160
- package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +0 -27
- package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +0 -2957
- package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +0 -1536
- package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +0 -75
- package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +0 -99
- package/src/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +0 -311
- package/src/llama.cpp/ggml/src/ggml-sycl/getrows.hpp +0 -20
- package/src/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +0 -4443
- package/src/llama.cpp/ggml/src/ggml-sycl/gla.cpp +0 -105
- package/src/llama.cpp/ggml/src/ggml-sycl/gla.hpp +0 -8
- package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +0 -136
- package/src/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +0 -21
- package/src/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +0 -3030
- package/src/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +0 -33
- package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +0 -1108
- package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +0 -27
- package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +0 -474
- package/src/llama.cpp/ggml/src/ggml-sycl/norm.hpp +0 -26
- package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +0 -46
- package/src/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +0 -10
- package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +0 -74
- package/src/llama.cpp/ggml/src/ggml-sycl/quants.hpp +0 -83
- package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +0 -362
- package/src/llama.cpp/ggml/src/ggml-sycl/rope.hpp +0 -20
- package/src/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +0 -264
- package/src/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +0 -20
- package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.cpp +0 -13
- package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.hpp +0 -23
- package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +0 -73
- package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +0 -20
- package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +0 -1215
- package/src/llama.cpp/ggml/src/ggml-sycl/wkv.cpp +0 -305
- package/src/llama.cpp/ggml/src/ggml-sycl/wkv.hpp +0 -10
- package/src/llama.cpp/ggml/src/ggml-threading.cpp +0 -12
- package/src/llama.cpp/ggml/src/ggml-threading.h +0 -14
- package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +0 -196
- package/src/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +0 -10699
- package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +0 -39
- package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +0 -751
- package/src/llama.cpp/ggml/src/ggml.c +0 -6550
- package/src/llama.cpp/ggml/src/gguf.cpp +0 -1330
- package/src/llama.cpp/models/.editorconfig +0 -1
- package/src/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-command-r.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-command-r.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-falcon.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-falcon.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-llama4.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-llama4.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-mpt.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-mpt.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-phi-3.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-refact.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-refact.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +0 -46
- package/src/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
- package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +0 -112
- package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.out +0 -46
- package/src/llama.cpp/pocs/CMakeLists.txt +0 -14
- package/src/llama.cpp/pocs/vdot/CMakeLists.txt +0 -9
- package/src/llama.cpp/pocs/vdot/q8dot.cpp +0 -173
- package/src/llama.cpp/pocs/vdot/vdot.cpp +0 -311
- package/src/llama.cpp/prompts/LLM-questions.txt +0 -49
- package/src/llama.cpp/prompts/alpaca.txt +0 -1
- package/src/llama.cpp/prompts/assistant.txt +0 -31
- package/src/llama.cpp/prompts/chat-with-baichuan.txt +0 -4
- package/src/llama.cpp/prompts/chat-with-bob.txt +0 -7
- package/src/llama.cpp/prompts/chat-with-qwen.txt +0 -1
- package/src/llama.cpp/prompts/chat-with-vicuna-v0.txt +0 -7
- package/src/llama.cpp/prompts/chat-with-vicuna-v1.txt +0 -7
- package/src/llama.cpp/prompts/chat.txt +0 -28
- package/src/llama.cpp/prompts/dan-modified.txt +0 -1
- package/src/llama.cpp/prompts/dan.txt +0 -1
- package/src/llama.cpp/prompts/mnemonics.txt +0 -93
- package/src/llama.cpp/prompts/parallel-questions.txt +0 -43
- package/src/llama.cpp/prompts/reason-act.txt +0 -18
- package/src/llama.cpp/requirements/requirements-all.txt +0 -15
- package/src/llama.cpp/requirements/requirements-compare-llama-bench.txt +0 -2
- package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +0 -7
- package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +0 -7
- package/src/llama.cpp/requirements/requirements-convert_legacy_llama.txt +0 -5
- package/src/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +0 -1
- package/src/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +0 -4
- package/src/llama.cpp/requirements/requirements-gguf_editor_gui.txt +0 -3
- package/src/llama.cpp/requirements/requirements-pydantic.txt +0 -3
- package/src/llama.cpp/requirements/requirements-test-tokenizer-random.txt +0 -1
- package/src/llama.cpp/requirements/requirements-tool_bench.txt +0 -12
- package/src/llama.cpp/requirements.txt +0 -13
- package/src/llama.cpp/scripts/build-info.sh +0 -30
- package/src/llama.cpp/scripts/install-oneapi.bat +0 -19
- package/src/llama.cpp/scripts/xxd.cmake +0 -16
- package/src/llama.cpp/tests/CMakeLists.txt +0 -177
- package/src/llama.cpp/tests/get-model.cpp +0 -21
- package/src/llama.cpp/tests/get-model.h +0 -2
- package/src/llama.cpp/tests/test-arg-parser.cpp +0 -178
- package/src/llama.cpp/tests/test-autorelease.cpp +0 -24
- package/src/llama.cpp/tests/test-backend-ops.cpp +0 -4793
- package/src/llama.cpp/tests/test-barrier.cpp +0 -94
- package/src/llama.cpp/tests/test-c.c +0 -7
- package/src/llama.cpp/tests/test-chat-template.cpp +0 -417
- package/src/llama.cpp/tests/test-chat.cpp +0 -985
- package/src/llama.cpp/tests/test-double-float.cpp +0 -57
- package/src/llama.cpp/tests/test-gbnf-validator.cpp +0 -109
- package/src/llama.cpp/tests/test-gguf.cpp +0 -1338
- package/src/llama.cpp/tests/test-grammar-integration.cpp +0 -1308
- package/src/llama.cpp/tests/test-grammar-llguidance.cpp +0 -1201
- package/src/llama.cpp/tests/test-grammar-parser.cpp +0 -519
- package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +0 -1304
- package/src/llama.cpp/tests/test-llama-grammar.cpp +0 -408
- package/src/llama.cpp/tests/test-log.cpp +0 -39
- package/src/llama.cpp/tests/test-model-load-cancel.cpp +0 -27
- package/src/llama.cpp/tests/test-mtmd-c-api.c +0 -63
- package/src/llama.cpp/tests/test-opt.cpp +0 -904
- package/src/llama.cpp/tests/test-quantize-fns.cpp +0 -186
- package/src/llama.cpp/tests/test-quantize-perf.cpp +0 -365
- package/src/llama.cpp/tests/test-quantize-stats.cpp +0 -424
- package/src/llama.cpp/tests/test-regex-partial.cpp +0 -288
- package/src/llama.cpp/tests/test-rope.cpp +0 -262
- package/src/llama.cpp/tests/test-sampling.cpp +0 -399
- package/src/llama.cpp/tests/test-tokenizer-0.cpp +0 -312
- package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +0 -155
- package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +0 -125
- package/src/llama.cpp/tools/CMakeLists.txt +0 -39
- package/src/llama.cpp/tools/batched-bench/CMakeLists.txt +0 -5
- package/src/llama.cpp/tools/batched-bench/batched-bench.cpp +0 -204
- package/src/llama.cpp/tools/cvector-generator/CMakeLists.txt +0 -5
- package/src/llama.cpp/tools/cvector-generator/completions.txt +0 -582
- package/src/llama.cpp/tools/cvector-generator/cvector-generator.cpp +0 -508
- package/src/llama.cpp/tools/cvector-generator/mean.hpp +0 -48
- package/src/llama.cpp/tools/cvector-generator/negative.txt +0 -4
- package/src/llama.cpp/tools/cvector-generator/pca.hpp +0 -315
- package/src/llama.cpp/tools/cvector-generator/positive.txt +0 -4
- package/src/llama.cpp/tools/export-lora/CMakeLists.txt +0 -5
- package/src/llama.cpp/tools/export-lora/export-lora.cpp +0 -434
- package/src/llama.cpp/tools/gguf-split/CMakeLists.txt +0 -5
- package/src/llama.cpp/tools/gguf-split/gguf-split.cpp +0 -583
- package/src/llama.cpp/tools/imatrix/CMakeLists.txt +0 -5
- package/src/llama.cpp/tools/imatrix/imatrix.cpp +0 -667
- package/src/llama.cpp/tools/llama-bench/CMakeLists.txt +0 -5
- package/src/llama.cpp/tools/llama-bench/llama-bench.cpp +0 -2024
- package/src/llama.cpp/tools/main/CMakeLists.txt +0 -5
- package/src/llama.cpp/tools/main/main.cpp +0 -977
- package/src/llama.cpp/tools/mtmd/CMakeLists.txt +0 -58
- package/src/llama.cpp/tools/mtmd/clip-impl.h +0 -462
- package/src/llama.cpp/tools/mtmd/clip.cpp +0 -4024
- package/src/llama.cpp/tools/mtmd/clip.h +0 -101
- package/src/llama.cpp/tools/mtmd/deprecation-warning.cpp +0 -22
- package/src/llama.cpp/tools/mtmd/miniaudio.h +0 -93468
- package/src/llama.cpp/tools/mtmd/mtmd-audio.cpp +0 -855
- package/src/llama.cpp/tools/mtmd/mtmd-audio.h +0 -62
- package/src/llama.cpp/tools/mtmd/mtmd-cli.cpp +0 -377
- package/src/llama.cpp/tools/mtmd/mtmd-helper.cpp +0 -297
- package/src/llama.cpp/tools/mtmd/mtmd.cpp +0 -942
- package/src/llama.cpp/tools/mtmd/mtmd.h +0 -362
- package/src/llama.cpp/tools/mtmd/requirements.txt +0 -5
- package/src/llama.cpp/tools/perplexity/CMakeLists.txt +0 -5
- package/src/llama.cpp/tools/perplexity/perplexity.cpp +0 -2063
- package/src/llama.cpp/tools/quantize/CMakeLists.txt +0 -6
- package/src/llama.cpp/tools/quantize/quantize.cpp +0 -519
- package/src/llama.cpp/tools/rpc/CMakeLists.txt +0 -4
- package/src/llama.cpp/tools/rpc/rpc-server.cpp +0 -322
- package/src/llama.cpp/tools/run/CMakeLists.txt +0 -16
- package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.cpp +0 -1995
- package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.h +0 -137
- package/src/llama.cpp/tools/run/run.cpp +0 -1261
- package/src/llama.cpp/tools/server/CMakeLists.txt +0 -51
- package/src/llama.cpp/tools/server/bench/requirements.txt +0 -2
- package/src/llama.cpp/tools/server/httplib.h +0 -10506
- package/src/llama.cpp/tools/server/server.cpp +0 -4966
- package/src/llama.cpp/tools/server/tests/requirements.txt +0 -8
- package/src/llama.cpp/tools/server/utils.hpp +0 -1337
- package/src/llama.cpp/tools/tokenize/CMakeLists.txt +0 -5
- package/src/llama.cpp/tools/tokenize/tokenize.cpp +0 -416
- package/src/llama.cpp/tools/tts/CMakeLists.txt +0 -5
- package/src/llama.cpp/tools/tts/tts.cpp +0 -1092
|
@@ -1,904 +0,0 @@
|
|
|
1
|
-
#include "ggml.h"
|
|
2
|
-
#include "ggml-alloc.h"
|
|
3
|
-
#include "ggml-backend.h"
|
|
4
|
-
#include "ggml-cpu.h"
|
|
5
|
-
#include "ggml-opt.h"
|
|
6
|
-
|
|
7
|
-
#include <cmath>
|
|
8
|
-
#include <cinttypes>
|
|
9
|
-
#include <random>
|
|
10
|
-
#include <string>
|
|
11
|
-
#include <thread>
|
|
12
|
-
#include <vector>
|
|
13
|
-
|
|
14
|
-
static bool almost_equal(const double a, const double b, const double atol) {
|
|
15
|
-
return fabs(a - b) < atol;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
constexpr int64_t ne_datapoint = 2;
|
|
19
|
-
constexpr int64_t ne_label = 1;
|
|
20
|
-
constexpr int64_t ndata = 6;
|
|
21
|
-
|
|
22
|
-
struct helper_ctx_data {
|
|
23
|
-
std::vector<ggml_opt_dataset_t> datasets_supervised;
|
|
24
|
-
std::vector<struct ggml_tensor *> data_batch;
|
|
25
|
-
std::vector<struct ggml_tensor *> labels_batch;
|
|
26
|
-
|
|
27
|
-
ggml_opt_dataset_t dataset_unsupervised;
|
|
28
|
-
struct ggml_context * ctx_static;
|
|
29
|
-
struct ggml_context * ctx_compute;
|
|
30
|
-
struct ggml_opt_params opt_params;
|
|
31
|
-
ggml_opt_context_t opt_ctx;
|
|
32
|
-
struct ggml_tensor * inputs;
|
|
33
|
-
struct ggml_tensor * weights;
|
|
34
|
-
struct ggml_tensor * outputs;
|
|
35
|
-
ggml_backend_buffer_t buf;
|
|
36
|
-
ggml_opt_result_t result;
|
|
37
|
-
ggml_opt_result_t result2;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// These default values make it easier to check optimization results vs. expected values.
|
|
41
|
-
static ggml_opt_optimizer_params helper_get_test_opt_pars(void * userdata) {
|
|
42
|
-
ggml_opt_optimizer_params result = ggml_opt_get_default_optimizer_params(userdata);
|
|
43
|
-
result.adamw.alpha = 1.0f;
|
|
44
|
-
result.adamw.beta1 = 0.0f;
|
|
45
|
-
result.adamw.beta2 = 0.0f;
|
|
46
|
-
result.adamw.eps = 0.0f;
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static helper_ctx_data helper_get_ctx_data(
|
|
51
|
-
ggml_backend_sched_t backend_sched,
|
|
52
|
-
ggml_backend_t backend,
|
|
53
|
-
const bool init_opt_ctx = true,
|
|
54
|
-
const bool optimizer_defaults = true,
|
|
55
|
-
int64_t nbatch_logical = 1,
|
|
56
|
-
int64_t nbatch_physical = 1,
|
|
57
|
-
enum ggml_opt_loss_type loss_type = GGML_OPT_LOSS_TYPE_SUM) {
|
|
58
|
-
std::vector<ggml_opt_dataset_t> datasets(ndata);
|
|
59
|
-
for (int64_t ndata_shard = 1; ndata_shard <= ndata; ++ndata_shard) {
|
|
60
|
-
ggml_opt_dataset_t dataset = ggml_opt_dataset_init(
|
|
61
|
-
GGML_TYPE_F32, GGML_TYPE_F32, ne_datapoint, ne_label, ndata, ndata_shard);
|
|
62
|
-
|
|
63
|
-
float * data = ggml_get_data_f32(ggml_opt_dataset_data( dataset));
|
|
64
|
-
float * labels = ggml_get_data_f32(ggml_opt_dataset_labels(dataset));
|
|
65
|
-
|
|
66
|
-
for (int64_t idata = 0; idata < ndata; ++idata) {
|
|
67
|
-
for (int64_t id = 0; id < ne_datapoint; ++id) {
|
|
68
|
-
data[ idata*ne_datapoint + id] = 16*idata + id;
|
|
69
|
-
}
|
|
70
|
-
for (int64_t il = 0; il < ne_label; ++il) {
|
|
71
|
-
labels[idata*ne_label + il] = 16*(16*idata + il);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
datasets[ndata_shard-1] = dataset;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
ggml_opt_dataset_t dataset_unsupervised = ggml_opt_dataset_init(
|
|
79
|
-
GGML_TYPE_F32, GGML_TYPE_F32, 1, 0, ndata, /*ndata_shard =*/ 1);
|
|
80
|
-
|
|
81
|
-
float * data = ggml_get_data_f32(ggml_opt_dataset_data(dataset_unsupervised));
|
|
82
|
-
|
|
83
|
-
for (int64_t idata = 0; idata < ndata; ++idata) {
|
|
84
|
-
data[idata] = idata;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
struct ggml_context * ctx_static;
|
|
88
|
-
struct ggml_context * ctx_compute;
|
|
89
|
-
{
|
|
90
|
-
struct ggml_init_params params = {
|
|
91
|
-
/*.mem_size =*/ (2*ndata + 2)*ggml_tensor_overhead(),
|
|
92
|
-
/*.mem_buffer =*/ nullptr,
|
|
93
|
-
/*.no_alloc =*/ true,
|
|
94
|
-
};
|
|
95
|
-
ctx_static = ggml_init(params);
|
|
96
|
-
}
|
|
97
|
-
{
|
|
98
|
-
struct ggml_init_params params = {
|
|
99
|
-
/*.mem_size =*/ GGML_DEFAULT_GRAPH_SIZE*ggml_tensor_overhead() + 3*ggml_graph_overhead(),
|
|
100
|
-
/*.mem_buffer =*/ nullptr,
|
|
101
|
-
/*.no_alloc =*/ true,
|
|
102
|
-
};
|
|
103
|
-
ctx_compute = ggml_init(params);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
std::vector<struct ggml_tensor *> data_batch(ndata);
|
|
107
|
-
std::vector<struct ggml_tensor *> labels_batch(ndata);
|
|
108
|
-
for (int64_t ndata_batch = 1; ndata_batch <= ndata; ++ndata_batch) {
|
|
109
|
-
data_batch[ndata_batch-1] = ggml_new_tensor_1d(ctx_static, GGML_TYPE_F32, ndata_batch*ne_datapoint);
|
|
110
|
-
labels_batch[ndata_batch-1] = ggml_new_tensor_1d(ctx_static, GGML_TYPE_F32, ndata_batch*ne_label);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
struct ggml_tensor * inputs = ggml_new_tensor_1d(ctx_static, GGML_TYPE_F32, nbatch_physical);
|
|
114
|
-
ggml_set_name(inputs, "inputs");
|
|
115
|
-
|
|
116
|
-
struct ggml_tensor * weights = ggml_new_tensor_1d(ctx_static, GGML_TYPE_F32, 1);
|
|
117
|
-
ggml_set_name(weights, "weights");
|
|
118
|
-
ggml_set_param(weights);
|
|
119
|
-
|
|
120
|
-
struct ggml_tensor * intermediary = ggml_add(ctx_compute, inputs, weights);
|
|
121
|
-
|
|
122
|
-
struct ggml_tensor * outputs = ggml_scale(ctx_compute, intermediary, 1.0f);
|
|
123
|
-
ggml_set_name(outputs, "outputs");
|
|
124
|
-
|
|
125
|
-
ggml_backend_buffer_t buf = ggml_backend_alloc_ctx_tensors(ctx_static, backend);
|
|
126
|
-
const float w0 = float(ndata)/2;
|
|
127
|
-
ggml_backend_tensor_set(weights, &w0, 0, sizeof(float));
|
|
128
|
-
|
|
129
|
-
GGML_ASSERT(nbatch_logical % nbatch_physical == 0);
|
|
130
|
-
const int32_t opt_period = nbatch_logical / nbatch_physical;
|
|
131
|
-
|
|
132
|
-
struct ggml_opt_params opt_params = ggml_opt_default_params(backend_sched, loss_type);
|
|
133
|
-
opt_params.ctx_compute = ctx_compute;
|
|
134
|
-
opt_params.inputs = inputs;
|
|
135
|
-
opt_params.outputs = outputs;
|
|
136
|
-
opt_params.opt_period = opt_period;
|
|
137
|
-
if (!optimizer_defaults) {
|
|
138
|
-
opt_params.get_opt_pars = helper_get_test_opt_pars;
|
|
139
|
-
}
|
|
140
|
-
ggml_opt_context_t opt_ctx = init_opt_ctx ? ggml_opt_init(opt_params) : nullptr;
|
|
141
|
-
|
|
142
|
-
ggml_opt_result_t result = ggml_opt_result_init();
|
|
143
|
-
ggml_opt_result_t result2 = ggml_opt_result_init();
|
|
144
|
-
|
|
145
|
-
return {datasets, data_batch, labels_batch, dataset_unsupervised, ctx_static, ctx_compute, opt_params, opt_ctx, inputs, weights, outputs, buf, result, result2};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
static void helper_free_ctx_data(struct helper_ctx_data ctx_data) {
|
|
149
|
-
ggml_opt_result_free(ctx_data.result);
|
|
150
|
-
ggml_opt_result_free(ctx_data.result2);
|
|
151
|
-
ggml_opt_free(ctx_data.opt_ctx);
|
|
152
|
-
ggml_backend_buffer_free(ctx_data.buf);
|
|
153
|
-
ggml_free(ctx_data.ctx_static);
|
|
154
|
-
ggml_free(ctx_data.ctx_compute);
|
|
155
|
-
for (ggml_opt_dataset_t dataset : ctx_data.datasets_supervised) {
|
|
156
|
-
ggml_opt_dataset_free(dataset);
|
|
157
|
-
}
|
|
158
|
-
ggml_opt_dataset_free(ctx_data.dataset_unsupervised);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
static void helper_after_test(
|
|
162
|
-
const char * func, const bool high_level, const std::string options,
|
|
163
|
-
const std::string subtest, const bool subtest_ok, int & ntest, int & npass) {
|
|
164
|
-
printf(" %s(high_level=%s%s, subtest=%s): ",
|
|
165
|
-
func, high_level ? "yes" : "no", options.c_str(), subtest.c_str());
|
|
166
|
-
if (subtest_ok) {
|
|
167
|
-
printf("\033[1;32mOK\033[0m\n");
|
|
168
|
-
npass++;
|
|
169
|
-
} else {
|
|
170
|
-
printf("\033[1;31mFAIL\033[0m\n");
|
|
171
|
-
}
|
|
172
|
-
ntest++;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
static std::pair<int, int> test_dataset(ggml_backend_sched_t backend_sched, ggml_backend_t backend, const bool shuffle) {
|
|
176
|
-
int ntest = 0;
|
|
177
|
-
int npass = 0;
|
|
178
|
-
|
|
179
|
-
struct helper_ctx_data cd = helper_get_ctx_data(backend_sched, backend);
|
|
180
|
-
|
|
181
|
-
for (int64_t ndata_shard = 1; ndata_shard <= ndata; ++ndata_shard) {
|
|
182
|
-
ggml_opt_dataset_t dataset = cd.datasets_supervised[ndata_shard-1];
|
|
183
|
-
|
|
184
|
-
if (shuffle) {
|
|
185
|
-
ggml_opt_dataset_shuffle(cd.opt_ctx, dataset, -1);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
for (int64_t ndata_batch = 1; ndata_batch <= ndata; ++ndata_batch) {
|
|
189
|
-
if (ndata_batch % ndata_shard != 0) {
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
bool subtest_ok = true;
|
|
193
|
-
|
|
194
|
-
struct ggml_tensor * data_batch = cd.data_batch[ndata_batch-1];
|
|
195
|
-
struct ggml_tensor * labels_batch = cd.labels_batch[ndata_batch-1];
|
|
196
|
-
|
|
197
|
-
std::vector<float> data(ggml_nelements( data_batch));
|
|
198
|
-
std::vector<float> labels(ggml_nelements(labels_batch));
|
|
199
|
-
|
|
200
|
-
std::vector<int64_t> idata_shuffled;
|
|
201
|
-
const int64_t nbatches = ndata / ndata_batch;
|
|
202
|
-
for (int64_t ibatch = 0; ibatch < nbatches; ++ibatch) {
|
|
203
|
-
ggml_opt_dataset_get_batch(dataset, data_batch, labels_batch, ibatch);
|
|
204
|
-
|
|
205
|
-
ggml_backend_tensor_get( data_batch, data.data(), 0, ggml_nbytes( data_batch));
|
|
206
|
-
ggml_backend_tensor_get(labels_batch, labels.data(), 0, ggml_nbytes(labels_batch));
|
|
207
|
-
|
|
208
|
-
for (int64_t idata_batch = 0; idata_batch < ndata_batch; ++idata_batch) {
|
|
209
|
-
const int64_t idata = ibatch*ndata_batch + idata_batch;
|
|
210
|
-
const int64_t idata_found = data[idata_batch*ne_datapoint] / 16;
|
|
211
|
-
subtest_ok = subtest_ok && (shuffle || idata_found == idata);
|
|
212
|
-
idata_shuffled.push_back(idata_found);
|
|
213
|
-
|
|
214
|
-
for (int64_t id = 0; id < ne_datapoint; ++id) {
|
|
215
|
-
if (data[ idata_batch*ne_datapoint + id] != 16*idata_found + id) {
|
|
216
|
-
subtest_ok = false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
for (int64_t il = 0; il < ne_label; ++il) {
|
|
220
|
-
if (labels[idata_batch*ne_label + il] != 16*(16*idata_found + il)) {
|
|
221
|
-
subtest_ok = false;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (!shuffle || ndata % ndata_batch == 0) {
|
|
228
|
-
const int ndata_max = (ndata / ndata_batch) * ndata_batch;
|
|
229
|
-
|
|
230
|
-
for (int64_t idata = 0; subtest_ok && idata < ndata_max; ++idata) {
|
|
231
|
-
int ninstances = 0;
|
|
232
|
-
for (int64_t id : idata_shuffled) {
|
|
233
|
-
ninstances += id == idata;
|
|
234
|
-
}
|
|
235
|
-
if (ninstances != 1) {
|
|
236
|
-
subtest_ok = false;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
printf(" %s(shuffle=%s, ndata_shard=%" PRId64 ", ndata_batch=%" PRId64 "): ",
|
|
242
|
-
__func__, shuffle ? "yes" : "no", ndata_shard, ndata_batch);
|
|
243
|
-
if (subtest_ok) {
|
|
244
|
-
printf("\033[1;32mOK\033[0m\n");
|
|
245
|
-
npass++;
|
|
246
|
-
} else {
|
|
247
|
-
printf("\033[1;31mFAIL\033[0m\n");
|
|
248
|
-
}
|
|
249
|
-
ntest++;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
helper_free_ctx_data(cd);
|
|
254
|
-
|
|
255
|
-
return std::make_pair(npass, ntest);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
static std::pair<int, int> test_grad(ggml_backend_sched_t backend_sched, ggml_backend_t backend) {
|
|
259
|
-
int ntest = 0;
|
|
260
|
-
int npass = 0;
|
|
261
|
-
|
|
262
|
-
struct helper_ctx_data cd = helper_get_ctx_data(backend_sched, backend, /*init_opt_ctx =*/ true, /*optimizer_defaults =*/ false,
|
|
263
|
-
/*nbatch_logical =*/ 999999, /*nbatch_physical =*/ 1);
|
|
264
|
-
|
|
265
|
-
std::vector<float> grad_history(ndata);
|
|
266
|
-
for (int64_t idata = 0; idata < ndata; ++idata) {
|
|
267
|
-
grad_history[idata] = NAN;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
for (int idata = 0; idata < ndata; ++idata) {
|
|
271
|
-
const float idataf = idata;
|
|
272
|
-
ggml_opt_alloc(cd.opt_ctx, /*backward =*/ true);
|
|
273
|
-
ggml_backend_tensor_set(cd.inputs, &idataf, 0, ggml_nbytes(cd.inputs));
|
|
274
|
-
ggml_opt_eval(cd.opt_ctx, cd.result);
|
|
275
|
-
ggml_backend_tensor_get(ggml_opt_grad_acc(cd.opt_ctx, cd.weights), grad_history.data() + idata, 0, sizeof(float));
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
{
|
|
279
|
-
bool subtest_ok = true;
|
|
280
|
-
for (int idata = 0; idata < ndata; ++idata) {
|
|
281
|
-
if (grad_history[idata] != idata + 1) {
|
|
282
|
-
subtest_ok = false;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
printf(" %s(): ", __func__);
|
|
286
|
-
if (subtest_ok) {
|
|
287
|
-
printf("\033[1;32mOK\033[0m\n");
|
|
288
|
-
npass++;
|
|
289
|
-
} else {
|
|
290
|
-
printf("\033[1;31mFAIL\033[0m\n");
|
|
291
|
-
}
|
|
292
|
-
ntest++;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
helper_free_ctx_data(cd);
|
|
296
|
-
|
|
297
|
-
return std::make_pair(npass, ntest);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
static void helper_after_test_forward_backward(
|
|
301
|
-
const char * func, const bool high_level, const bool shuffle,
|
|
302
|
-
const std::string subtest, const bool subtest_ok, int & ntest, int & npass) {
|
|
303
|
-
std::string options = ", shuffle=";
|
|
304
|
-
options += shuffle ? "yes" : "no";
|
|
305
|
-
helper_after_test(func, high_level, options, subtest, subtest_ok, ntest, npass);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
static std::pair<int, int> test_forward_backward(
|
|
309
|
-
ggml_backend_sched_t backend_sched, ggml_backend_t backend, const bool high_level, const bool shuffle) {
|
|
310
|
-
int ntest = 0;
|
|
311
|
-
int npass = 0;
|
|
312
|
-
|
|
313
|
-
struct helper_ctx_data cd = helper_get_ctx_data(backend_sched, backend, /*init_opt_ctx =*/ true, /*optimizer_defaults =*/ false);
|
|
314
|
-
struct ggml_tensor * loss = ggml_opt_loss(cd.opt_ctx);
|
|
315
|
-
|
|
316
|
-
std::vector<float> loss_history(ndata);
|
|
317
|
-
for (int64_t idata = 0; idata < ndata; ++idata) {
|
|
318
|
-
loss_history[idata] = NAN;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
{
|
|
322
|
-
int64_t ndata;
|
|
323
|
-
ggml_opt_result_ndata(cd.result, &ndata);
|
|
324
|
-
double loss;
|
|
325
|
-
double loss_unc;
|
|
326
|
-
ggml_opt_result_loss(cd.result, &loss, &loss_unc);
|
|
327
|
-
double accuracy;
|
|
328
|
-
double accuracy_unc;
|
|
329
|
-
ggml_opt_result_accuracy(cd.result, &accuracy, &accuracy_unc);
|
|
330
|
-
const bool subtest_ok = ndata == 0 && loss == 0.0 && std::isnan(loss_unc) && std::isnan(accuracy) && std::isnan(accuracy_unc);
|
|
331
|
-
helper_after_test_forward_backward(__func__, high_level, shuffle, "results_initial", subtest_ok, ntest, npass);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (high_level) {
|
|
335
|
-
ggml_opt_dataset_t dataset = cd.dataset_unsupervised;
|
|
336
|
-
if (shuffle) {
|
|
337
|
-
ggml_opt_dataset_shuffle(cd.opt_ctx, dataset, -1);
|
|
338
|
-
}
|
|
339
|
-
ggml_opt_epoch(cd.opt_ctx, dataset, nullptr, cd.result, 0, nullptr, nullptr);
|
|
340
|
-
} else {
|
|
341
|
-
for (int idata = 0; idata < ndata; ++idata) {
|
|
342
|
-
const float idataf = idata;
|
|
343
|
-
ggml_opt_alloc(cd.opt_ctx, /*backward =*/ false);
|
|
344
|
-
ggml_backend_tensor_set(cd.inputs, &idataf, 0, ggml_nbytes(cd.inputs));
|
|
345
|
-
ggml_opt_eval(cd.opt_ctx, cd.result);
|
|
346
|
-
ggml_backend_tensor_get(loss, loss_history.data() + idata, 0, sizeof(float));
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
{
|
|
351
|
-
float weights;
|
|
352
|
-
ggml_backend_tensor_get(cd.weights, &weights, 0, sizeof(float));
|
|
353
|
-
const bool subtest_ok = weights == ndata/2;
|
|
354
|
-
helper_after_test_forward_backward(__func__, high_level, shuffle, "weights_after_forward", subtest_ok, ntest, npass);
|
|
355
|
-
}
|
|
356
|
-
{
|
|
357
|
-
int64_t ndata;
|
|
358
|
-
ggml_opt_result_ndata(cd.result, &ndata);
|
|
359
|
-
bool subtest_ok = ndata == 6;
|
|
360
|
-
|
|
361
|
-
double loss;
|
|
362
|
-
double loss_unc;
|
|
363
|
-
ggml_opt_result_loss(cd.result, &loss, &loss_unc);
|
|
364
|
-
subtest_ok = subtest_ok && loss == 33.0 && almost_equal(loss_unc, sqrt(3.5), 1e-10);
|
|
365
|
-
|
|
366
|
-
double accuracy;
|
|
367
|
-
double accuracy_unc;
|
|
368
|
-
ggml_opt_result_accuracy(cd.result, &accuracy, &accuracy_unc);
|
|
369
|
-
subtest_ok = subtest_ok && std::isnan(accuracy) && std::isnan(accuracy_unc);
|
|
370
|
-
|
|
371
|
-
helper_after_test_forward_backward(__func__, high_level, shuffle, "results_after_forward", subtest_ok, ntest, npass);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
float w0;
|
|
375
|
-
ggml_backend_tensor_get(cd.weights, &w0, 0, sizeof(float));
|
|
376
|
-
for (int i = 0; i < 10; ++i) {
|
|
377
|
-
ggml_opt_alloc(cd.opt_ctx, /*backward =*/ true);
|
|
378
|
-
ggml_opt_eval(cd.opt_ctx, cd.result);
|
|
379
|
-
}
|
|
380
|
-
ggml_backend_tensor_set(cd.weights, &w0, 0, sizeof(float));
|
|
381
|
-
|
|
382
|
-
ggml_opt_reset(cd.opt_ctx, /*optimizer =*/ false);
|
|
383
|
-
ggml_opt_result_reset(cd.result);
|
|
384
|
-
|
|
385
|
-
for (int64_t idata = 0; idata < ndata; ++idata) {
|
|
386
|
-
loss_history[idata] = NAN;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if (high_level) {
|
|
390
|
-
ggml_opt_dataset_t dataset = cd.dataset_unsupervised;
|
|
391
|
-
if (shuffle) {
|
|
392
|
-
ggml_opt_dataset_shuffle(cd.opt_ctx, dataset, -1);
|
|
393
|
-
}
|
|
394
|
-
ggml_opt_epoch(cd.opt_ctx, dataset, cd.result, nullptr, ndata, nullptr, nullptr);
|
|
395
|
-
} else {
|
|
396
|
-
for (int idata = 0; idata < ndata; ++idata) {
|
|
397
|
-
const float idataf = idata;
|
|
398
|
-
ggml_opt_alloc(cd.opt_ctx, /*backward =*/ true);
|
|
399
|
-
ggml_backend_tensor_set(cd.inputs, &idataf, 0, ggml_nbytes(cd.inputs));
|
|
400
|
-
ggml_opt_eval(cd.opt_ctx, cd.result);
|
|
401
|
-
ggml_backend_tensor_get(loss, loss_history.data() + idata, 0, sizeof(float));
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
{
|
|
406
|
-
float weights;
|
|
407
|
-
ggml_backend_tensor_get(cd.weights, &weights, 0, sizeof(float));
|
|
408
|
-
const bool subtest_ok = weights == -ndata/2;
|
|
409
|
-
helper_after_test_forward_backward(__func__, high_level, shuffle, "weights_after_forward_backward", subtest_ok, ntest, npass);
|
|
410
|
-
}
|
|
411
|
-
{
|
|
412
|
-
int64_t ndata;
|
|
413
|
-
ggml_opt_result_ndata(cd.result, &ndata);
|
|
414
|
-
bool subtest_ok = ndata == 6;
|
|
415
|
-
|
|
416
|
-
double loss;
|
|
417
|
-
double loss_unc;
|
|
418
|
-
ggml_opt_result_loss(cd.result, &loss, &loss_unc);
|
|
419
|
-
subtest_ok = subtest_ok && loss == 18.0 && (shuffle || loss_unc == 0.0);
|
|
420
|
-
|
|
421
|
-
double accuracy;
|
|
422
|
-
double accuracy_unc;
|
|
423
|
-
ggml_opt_result_accuracy(cd.result, &accuracy, &accuracy_unc);
|
|
424
|
-
subtest_ok = subtest_ok && std::isnan(accuracy) && std::isnan(accuracy_unc);
|
|
425
|
-
|
|
426
|
-
helper_after_test_forward_backward(__func__, high_level, shuffle, "result_after_forward_backward", subtest_ok, ntest, npass);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
helper_free_ctx_data(cd);
|
|
430
|
-
|
|
431
|
-
return std::make_pair(npass, ntest);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
static std::pair<int, int> test_epoch_vs_fit(ggml_backend_sched_t backend_sched, ggml_backend_t backend) {
|
|
435
|
-
int ntest = 0;
|
|
436
|
-
int npass = 0;
|
|
437
|
-
|
|
438
|
-
float weights_epoch;
|
|
439
|
-
float weights_fit;
|
|
440
|
-
|
|
441
|
-
{
|
|
442
|
-
struct helper_ctx_data cd = helper_get_ctx_data(backend_sched, backend, /*init_opt_ctx =*/ true);
|
|
443
|
-
ggml_opt_dataset_t dataset = cd.dataset_unsupervised;
|
|
444
|
-
|
|
445
|
-
ggml_opt_dataset_shuffle(cd.opt_ctx, dataset, -1);
|
|
446
|
-
ggml_opt_epoch(cd.opt_ctx, dataset, cd.result, nullptr, ndata, nullptr, nullptr);
|
|
447
|
-
|
|
448
|
-
ggml_backend_tensor_get(cd.weights, &weights_epoch, 0, ggml_nbytes(cd.weights));
|
|
449
|
-
helper_free_ctx_data(cd);
|
|
450
|
-
}
|
|
451
|
-
{
|
|
452
|
-
struct helper_ctx_data cd = helper_get_ctx_data(backend_sched, backend, /*init_opt_ctx =*/ false);
|
|
453
|
-
ggml_opt_dataset_t dataset = cd.dataset_unsupervised;
|
|
454
|
-
|
|
455
|
-
ggml_opt_fit(backend_sched, cd.ctx_compute, cd.inputs, cd.outputs, dataset,
|
|
456
|
-
GGML_OPT_LOSS_TYPE_SUM, ggml_opt_get_default_optimizer_params, 1, 1, 0.0f, true);
|
|
457
|
-
|
|
458
|
-
ggml_backend_tensor_get(cd.weights, &weights_fit, 0, ggml_nbytes(cd.weights));
|
|
459
|
-
helper_free_ctx_data(cd);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
const bool subtest_ok = weights_epoch == weights_fit;
|
|
463
|
-
|
|
464
|
-
printf(" %s(): ", __func__);
|
|
465
|
-
if (subtest_ok) {
|
|
466
|
-
printf("\033[1;32mOK\033[0m\n");
|
|
467
|
-
npass++;
|
|
468
|
-
} else {
|
|
469
|
-
printf("\033[1;31mFAIL\033[0m\n");
|
|
470
|
-
}
|
|
471
|
-
ntest++;
|
|
472
|
-
|
|
473
|
-
return std::make_pair(npass, ntest);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
static void helper_after_test_idata_split(
|
|
477
|
-
const char * func, const bool high_level, const int epoch,
|
|
478
|
-
const std::string subtest, const bool subtest_ok, int & ntest, int & npass) {
|
|
479
|
-
std::string options = ", epoch=";
|
|
480
|
-
options += std::to_string(epoch);
|
|
481
|
-
helper_after_test(func, high_level, options, subtest, subtest_ok, ntest, npass);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
static std::pair<int, int> test_idata_split(ggml_backend_sched_t backend_sched, ggml_backend_t backend, const bool high_level) {
|
|
485
|
-
int ntest = 0;
|
|
486
|
-
int npass = 0;
|
|
487
|
-
|
|
488
|
-
struct helper_ctx_data cd = helper_get_ctx_data(backend_sched, backend, /*init_opt_ctx =*/ true, /*optimizer_defaults =*/ false);
|
|
489
|
-
struct ggml_tensor * loss = ggml_opt_loss(cd.opt_ctx);
|
|
490
|
-
const int idata_split = ndata * 2/3;
|
|
491
|
-
|
|
492
|
-
std::vector<float> loss_history(ndata);
|
|
493
|
-
for (int64_t idata = 0; idata < ndata; ++idata) {
|
|
494
|
-
loss_history[idata] = NAN;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
for (int epoch = 1; epoch <= 4; ++epoch) {
|
|
498
|
-
if (high_level) {
|
|
499
|
-
ggml_opt_epoch(cd.opt_ctx, cd.dataset_unsupervised, cd.result, cd.result2, idata_split, nullptr, nullptr);
|
|
500
|
-
} else {
|
|
501
|
-
int idata = 0;
|
|
502
|
-
for (; idata < idata_split; ++idata) {
|
|
503
|
-
const float idataf = idata;
|
|
504
|
-
ggml_opt_alloc(cd.opt_ctx, /*backward =*/ true);
|
|
505
|
-
ggml_backend_tensor_set(cd.inputs, &idataf, 0, ggml_nbytes(cd.inputs));
|
|
506
|
-
ggml_opt_eval(cd.opt_ctx, cd.result);
|
|
507
|
-
ggml_backend_tensor_get(loss, loss_history.data() + idata, 0, sizeof(float));
|
|
508
|
-
}
|
|
509
|
-
for (; idata < ndata; ++idata) {
|
|
510
|
-
const float idataf = idata;
|
|
511
|
-
ggml_opt_alloc(cd.opt_ctx, /*backward =*/ false);
|
|
512
|
-
ggml_backend_tensor_set(cd.inputs, &idataf, 0, ggml_nbytes(cd.inputs));
|
|
513
|
-
ggml_opt_eval(cd.opt_ctx, cd.result2);
|
|
514
|
-
ggml_backend_tensor_get(loss, loss_history.data() + idata, 0, sizeof(float));
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
{
|
|
519
|
-
float weights;
|
|
520
|
-
ggml_backend_tensor_get(cd.weights, &weights, 0, sizeof(float));
|
|
521
|
-
const bool subtest_ok = weights == ndata/2 - epoch*idata_split;
|
|
522
|
-
helper_after_test_idata_split(__func__, high_level, epoch, "weights", subtest_ok, ntest, npass);
|
|
523
|
-
}
|
|
524
|
-
{
|
|
525
|
-
int64_t ndata_result;
|
|
526
|
-
ggml_opt_result_ndata(cd.result, &ndata_result);
|
|
527
|
-
bool subtest_ok = ndata_result == idata_split;
|
|
528
|
-
|
|
529
|
-
double loss;
|
|
530
|
-
double loss_unc;
|
|
531
|
-
ggml_opt_result_loss(cd.result, &loss, &loss_unc);
|
|
532
|
-
subtest_ok = subtest_ok && loss == 28.0 - epoch*16.0 && loss_unc == 0.0;
|
|
533
|
-
|
|
534
|
-
double accuracy;
|
|
535
|
-
double accuracy_unc;
|
|
536
|
-
ggml_opt_result_accuracy(cd.result, &accuracy, &accuracy_unc);
|
|
537
|
-
subtest_ok = subtest_ok && std::isnan(accuracy) && std::isnan(accuracy_unc);
|
|
538
|
-
|
|
539
|
-
helper_after_test_idata_split(__func__, high_level, epoch, "results_backward", subtest_ok, ntest, npass);
|
|
540
|
-
}
|
|
541
|
-
{
|
|
542
|
-
int64_t ndata_result;
|
|
543
|
-
ggml_opt_result_ndata(cd.result2, &ndata_result);
|
|
544
|
-
bool subtest_ok = ndata_result == ndata - idata_split;
|
|
545
|
-
|
|
546
|
-
double loss;
|
|
547
|
-
double loss_unc;
|
|
548
|
-
ggml_opt_result_loss(cd.result2, &loss, &loss_unc);
|
|
549
|
-
subtest_ok = subtest_ok && loss == 15.0 - epoch*8 && almost_equal(loss_unc, sqrt(0.5), 1e-10);
|
|
550
|
-
|
|
551
|
-
double accuracy;
|
|
552
|
-
double accuracy_unc;
|
|
553
|
-
ggml_opt_result_accuracy(cd.result2, &accuracy, &accuracy_unc);
|
|
554
|
-
subtest_ok = subtest_ok && std::isnan(accuracy) && std::isnan(accuracy_unc);
|
|
555
|
-
|
|
556
|
-
helper_after_test_idata_split(__func__, high_level, epoch, "results_forward", subtest_ok, ntest, npass);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
ggml_opt_result_reset(cd.result);
|
|
560
|
-
ggml_opt_result_reset(cd.result2);
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
helper_free_ctx_data(cd);
|
|
564
|
-
|
|
565
|
-
return std::make_pair(npass, ntest);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
static void helper_after_test_gradient_accumulation(
|
|
569
|
-
const char * func, const int nbatch_physical, const enum ggml_opt_loss_type loss_type, const int epoch,
|
|
570
|
-
const std::string subtest, const bool subtest_ok, int & ntest, int & npass) {
|
|
571
|
-
std::string options = ", nbatch_physical=";
|
|
572
|
-
options += std::to_string(nbatch_physical);
|
|
573
|
-
options += ", loss_type=";
|
|
574
|
-
options += loss_type == GGML_OPT_LOSS_TYPE_MEAN ? "mean" : "sum";
|
|
575
|
-
options += ", epoch=";
|
|
576
|
-
options += std::to_string(epoch);
|
|
577
|
-
helper_after_test(func, false, options, subtest, subtest_ok, ntest, npass);
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
static std::pair<int, int> test_gradient_accumulation(
|
|
581
|
-
ggml_backend_sched_t backend_sched, ggml_backend_t backend, const int32_t nbatch_physical, const enum ggml_opt_loss_type loss_type) {
|
|
582
|
-
int ntest = 0;
|
|
583
|
-
int npass = 0;
|
|
584
|
-
|
|
585
|
-
struct helper_ctx_data cd = helper_get_ctx_data(
|
|
586
|
-
backend_sched, backend, /*init_opt_ctx =*/ true, /*optimizer_defaults =*/ false, /*nbatch_logical =*/ 6, nbatch_physical, loss_type);
|
|
587
|
-
|
|
588
|
-
std::vector<float> grad_history(ndata);
|
|
589
|
-
for (int64_t idata = 0; idata < ndata; ++idata) {
|
|
590
|
-
grad_history[idata] = NAN;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
for (int epoch = 1; epoch <= 4; ++epoch) {
|
|
594
|
-
if (nbatch_physical == 1) {
|
|
595
|
-
for (int idata = 0; idata < ndata; ++idata) {
|
|
596
|
-
const float idataf = idata;
|
|
597
|
-
ggml_opt_alloc(cd.opt_ctx, /*backward =*/ true);
|
|
598
|
-
ggml_backend_tensor_set(cd.inputs, &idataf, 0, 1*sizeof(float));
|
|
599
|
-
ggml_opt_eval(cd.opt_ctx, cd.result);
|
|
600
|
-
ggml_backend_tensor_get(ggml_opt_grad_acc(cd.opt_ctx, cd.weights), grad_history.data() + idata, 0, 1*sizeof(float));
|
|
601
|
-
}
|
|
602
|
-
} else if (nbatch_physical == 2) {
|
|
603
|
-
for (int idata = 0; idata < ndata; idata += 2) {
|
|
604
|
-
const float idataf[2] = {float(idata + 0), float(idata + 1)};
|
|
605
|
-
ggml_opt_alloc(cd.opt_ctx, /*backward =*/ true);
|
|
606
|
-
ggml_backend_tensor_set(cd.inputs, idataf, 0, 2*sizeof(float));
|
|
607
|
-
ggml_opt_eval(cd.opt_ctx, cd.result);
|
|
608
|
-
|
|
609
|
-
grad_history[idata + 0] = 0.0f;
|
|
610
|
-
ggml_backend_tensor_get(ggml_opt_grad_acc(cd.opt_ctx, cd.weights), grad_history.data() + idata + 1, 0, 1*sizeof(float));
|
|
611
|
-
}
|
|
612
|
-
} else {
|
|
613
|
-
GGML_ASSERT(false);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
{
|
|
617
|
-
GGML_ASSERT(ndata == 6);
|
|
618
|
-
constexpr double atol = 1e-6;
|
|
619
|
-
bool subtest_ok = true;
|
|
620
|
-
if (loss_type == GGML_OPT_LOSS_TYPE_SUM) {
|
|
621
|
-
if (nbatch_physical == 1) {
|
|
622
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[0], 1.0, atol);
|
|
623
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[2], 3.0, atol);
|
|
624
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[4], 5.0, atol);
|
|
625
|
-
} else {
|
|
626
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[0], 0.0, atol);
|
|
627
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[2], 0.0, atol);
|
|
628
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[4], 0.0, atol);
|
|
629
|
-
}
|
|
630
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[1], 2.0, atol);
|
|
631
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[3], 4.0, atol);
|
|
632
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[5], 6.0, atol);
|
|
633
|
-
} else if (loss_type == GGML_OPT_LOSS_TYPE_MEAN) {
|
|
634
|
-
if (nbatch_physical == 1) {
|
|
635
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[0], 1.0/ndata, atol);
|
|
636
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[2], 3.0/ndata, atol);
|
|
637
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[4], 5.0/ndata, atol);
|
|
638
|
-
} else {
|
|
639
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[0], 0.0/ndata, atol);
|
|
640
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[2], 0.0/ndata, atol);
|
|
641
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[4], 0.0/ndata, atol);
|
|
642
|
-
}
|
|
643
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[1], 2.0/ndata, atol);
|
|
644
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[3], 4.0/ndata, atol);
|
|
645
|
-
subtest_ok = subtest_ok && almost_equal(grad_history[5], 6.0/ndata, atol);
|
|
646
|
-
} else {
|
|
647
|
-
GGML_ASSERT(false);
|
|
648
|
-
}
|
|
649
|
-
helper_after_test_gradient_accumulation(__func__, nbatch_physical, loss_type, epoch, "grads", subtest_ok, ntest, npass);
|
|
650
|
-
}
|
|
651
|
-
{
|
|
652
|
-
float weights;
|
|
653
|
-
ggml_backend_tensor_get(cd.weights, &weights, 0, sizeof(float));
|
|
654
|
-
const bool subtest_ok = weights == (ndata/2) - epoch;
|
|
655
|
-
helper_after_test_gradient_accumulation(__func__, nbatch_physical, loss_type, epoch, "weights", subtest_ok, ntest, npass);
|
|
656
|
-
}
|
|
657
|
-
{
|
|
658
|
-
int64_t ndata_result;
|
|
659
|
-
ggml_opt_result_ndata(cd.result, &ndata_result);
|
|
660
|
-
bool subtest_ok = ndata_result == ndata/nbatch_physical;
|
|
661
|
-
|
|
662
|
-
double loss;
|
|
663
|
-
ggml_opt_result_loss(cd.result, &loss, /*loss_unc =*/ nullptr);
|
|
664
|
-
if (loss_type == GGML_OPT_LOSS_TYPE_SUM) {
|
|
665
|
-
subtest_ok = subtest_ok && loss == (39.0 - epoch*6.0);
|
|
666
|
-
} else if (loss_type == GGML_OPT_LOSS_TYPE_MEAN) {
|
|
667
|
-
subtest_ok = subtest_ok && almost_equal(loss, (39.0 - epoch*6.0) / ndata, 1e-6);
|
|
668
|
-
} else {
|
|
669
|
-
GGML_ASSERT(false);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
double accuracy;
|
|
673
|
-
double accuracy_unc;
|
|
674
|
-
ggml_opt_result_accuracy(cd.result, &accuracy, &accuracy_unc);
|
|
675
|
-
subtest_ok = subtest_ok && std::isnan(accuracy) && std::isnan(accuracy_unc);
|
|
676
|
-
|
|
677
|
-
helper_after_test_gradient_accumulation(__func__, nbatch_physical, loss_type, epoch, "results", subtest_ok, ntest, npass);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
ggml_opt_result_reset(cd.result);
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
helper_free_ctx_data(cd);
|
|
684
|
-
|
|
685
|
-
return std::make_pair(npass, ntest);
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
static ggml_opt_optimizer_params helper_get_regression_opt_pars(void * userdata) {
|
|
689
|
-
ggml_opt_optimizer_params result = ggml_opt_get_default_optimizer_params(userdata);
|
|
690
|
-
result.adamw.alpha = 0.1f;
|
|
691
|
-
return result;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
static std::pair<int, int> test_regression(ggml_backend_sched_t backend_sched, ggml_backend_t backend) {
|
|
695
|
-
int ntest = 0;
|
|
696
|
-
int npass = 0;
|
|
697
|
-
|
|
698
|
-
// Test for simple regression with f(x) = a*x + b
|
|
699
|
-
|
|
700
|
-
constexpr int64_t ndata_regression = 201;
|
|
701
|
-
constexpr float a_true = 1.2f;
|
|
702
|
-
constexpr float b_true = 3.4f;
|
|
703
|
-
|
|
704
|
-
std::mt19937 gen(12345);
|
|
705
|
-
std::normal_distribution<float> nd{0.0f, 0.1f};
|
|
706
|
-
|
|
707
|
-
ggml_opt_dataset_t dataset = ggml_opt_dataset_init(
|
|
708
|
-
GGML_TYPE_F32, GGML_TYPE_F32, 1, 1, ndata_regression, ndata_regression);
|
|
709
|
-
|
|
710
|
-
float * data = ggml_get_data_f32(ggml_opt_dataset_data( dataset));
|
|
711
|
-
float * labels = ggml_get_data_f32(ggml_opt_dataset_labels(dataset));
|
|
712
|
-
|
|
713
|
-
constexpr float x_min = -100.0f;
|
|
714
|
-
constexpr float x_max = 100.0f;
|
|
715
|
-
|
|
716
|
-
for (int64_t idata = 0; idata < ndata_regression; ++idata) {
|
|
717
|
-
const float x = x_min + (x_max - x_min) * idata/(ndata_regression-1);
|
|
718
|
-
const float y = a_true*x + b_true + nd(gen);
|
|
719
|
-
|
|
720
|
-
data[idata] = x;
|
|
721
|
-
labels[idata] = y;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
struct ggml_context * ctx_static;
|
|
725
|
-
struct ggml_context * ctx_compute;
|
|
726
|
-
{
|
|
727
|
-
struct ggml_init_params params = {
|
|
728
|
-
/*.mem_size =*/ 3*ggml_tensor_overhead(),
|
|
729
|
-
/*.mem_buffer =*/ nullptr,
|
|
730
|
-
/*.no_alloc =*/ true,
|
|
731
|
-
};
|
|
732
|
-
ctx_static = ggml_init(params);
|
|
733
|
-
}
|
|
734
|
-
{
|
|
735
|
-
struct ggml_init_params params = {
|
|
736
|
-
/*.mem_size =*/ GGML_DEFAULT_GRAPH_SIZE*ggml_tensor_overhead() + 3*ggml_graph_overhead(),
|
|
737
|
-
/*.mem_buffer =*/ nullptr,
|
|
738
|
-
/*.no_alloc =*/ true,
|
|
739
|
-
};
|
|
740
|
-
ctx_compute = ggml_init(params);
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
// The first dimension is the dimension of the datapoints, the second dimension is the number of datapoints.
|
|
744
|
-
struct ggml_tensor * x = ggml_new_tensor_2d(ctx_static, GGML_TYPE_F32, 1, ndata_regression);
|
|
745
|
-
ggml_set_name(x, "x");
|
|
746
|
-
|
|
747
|
-
struct ggml_tensor * a = ggml_new_tensor_1d(ctx_static, GGML_TYPE_F32, 1);
|
|
748
|
-
ggml_set_name(a, "a");
|
|
749
|
-
ggml_set_param(a);
|
|
750
|
-
|
|
751
|
-
struct ggml_tensor * b = ggml_new_tensor_1d(ctx_static, GGML_TYPE_F32, 1);
|
|
752
|
-
ggml_set_name(b, "b");
|
|
753
|
-
ggml_set_param(b);
|
|
754
|
-
|
|
755
|
-
struct ggml_tensor * f = ggml_add(ctx_compute, ggml_mul(ctx_compute, x, a), b);
|
|
756
|
-
ggml_set_name(f, "f");
|
|
757
|
-
|
|
758
|
-
ggml_backend_buffer_t buf = ggml_backend_alloc_ctx_tensors(ctx_static, backend);
|
|
759
|
-
const float a0 = 1.0f;
|
|
760
|
-
const float b0 = 3.0f;
|
|
761
|
-
ggml_backend_tensor_set(a, &a0, 0, sizeof(float));
|
|
762
|
-
ggml_backend_tensor_set(b, &b0, 0, sizeof(float));
|
|
763
|
-
|
|
764
|
-
ggml_opt_fit(backend_sched, ctx_compute, x, f, dataset, GGML_OPT_LOSS_TYPE_MEAN_SQUARED_ERROR,
|
|
765
|
-
helper_get_regression_opt_pars, 100, ndata_regression, 0.0f, true);
|
|
766
|
-
|
|
767
|
-
{
|
|
768
|
-
float a_fit;
|
|
769
|
-
ggml_backend_tensor_get(a, &a_fit, 0, sizeof(float));
|
|
770
|
-
float b_fit;
|
|
771
|
-
ggml_backend_tensor_get(b, &b_fit, 0, sizeof(float));
|
|
772
|
-
const bool subtest_ok = almost_equal(a_fit, a_true, 1e-2) && almost_equal(b_fit, b_true, 1e-2);
|
|
773
|
-
printf(" %s(subtest=weights): ", __func__);
|
|
774
|
-
if (subtest_ok) {
|
|
775
|
-
printf("\033[1;32mOK\033[0m\n");
|
|
776
|
-
npass++;
|
|
777
|
-
} else {
|
|
778
|
-
printf("\033[1;31mFAIL\033[0m\n");
|
|
779
|
-
}
|
|
780
|
-
ntest++;
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
ggml_backend_buffer_free(buf);
|
|
784
|
-
ggml_free(ctx_static);
|
|
785
|
-
ggml_opt_dataset_free(dataset);
|
|
786
|
-
|
|
787
|
-
return std::make_pair(npass, ntest);
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
static std::pair<int, int> test_backend(ggml_backend_sched_t backend_sched, ggml_backend_t backend) {
|
|
791
|
-
int npass = 0;
|
|
792
|
-
int ntest = 0;
|
|
793
|
-
|
|
794
|
-
for (bool shuffle : {false, true}) {
|
|
795
|
-
std::pair<int, int> partial = test_dataset(backend_sched, backend, shuffle);
|
|
796
|
-
npass += partial.first;
|
|
797
|
-
ntest += partial.second;
|
|
798
|
-
}
|
|
799
|
-
{
|
|
800
|
-
std::pair<int, int> partial = test_grad(backend_sched, backend);
|
|
801
|
-
npass += partial.first;
|
|
802
|
-
ntest += partial.second;
|
|
803
|
-
}
|
|
804
|
-
for (bool high_level : {false, true}){
|
|
805
|
-
for (bool shuffle : {false, true}) {
|
|
806
|
-
if (!high_level && shuffle) {
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
std::pair<int, int> partial = test_forward_backward(backend_sched, backend, high_level, shuffle);
|
|
811
|
-
npass += partial.first;
|
|
812
|
-
ntest += partial.second;
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
{
|
|
816
|
-
std::pair<int, int> partial = test_epoch_vs_fit(backend_sched, backend);
|
|
817
|
-
npass += partial.first;
|
|
818
|
-
ntest += partial.second;
|
|
819
|
-
}
|
|
820
|
-
for (bool high_level : {false, true}){
|
|
821
|
-
std::pair<int, int> partial = test_idata_split(backend_sched, backend, high_level);
|
|
822
|
-
npass += partial.first;
|
|
823
|
-
ntest += partial.second;
|
|
824
|
-
}
|
|
825
|
-
for (int32_t nbatch_physical : {2, 1}) {
|
|
826
|
-
for (enum ggml_opt_loss_type loss_type : {GGML_OPT_LOSS_TYPE_SUM, GGML_OPT_LOSS_TYPE_MEAN}) {
|
|
827
|
-
std::pair<int, int> partial = test_gradient_accumulation(backend_sched, backend, nbatch_physical, loss_type);
|
|
828
|
-
npass += partial.first;
|
|
829
|
-
ntest += partial.second;
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
{
|
|
833
|
-
std::pair<int, int> partial = test_regression(backend_sched, backend);
|
|
834
|
-
npass += partial.first;
|
|
835
|
-
ntest += partial.second;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
return std::make_pair(npass, ntest);
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
int main(void) {
|
|
842
|
-
const size_t dev_count = ggml_backend_dev_count();
|
|
843
|
-
printf("Testing %zu devices\n\n", dev_count);
|
|
844
|
-
size_t n_ok = 0;
|
|
845
|
-
|
|
846
|
-
std::vector<ggml_backend_dev_t> devs;
|
|
847
|
-
std::vector<ggml_backend_t> backends;
|
|
848
|
-
|
|
849
|
-
for (size_t i = 0; i < dev_count; ++i) {
|
|
850
|
-
devs.push_back(ggml_backend_dev_get(i));
|
|
851
|
-
|
|
852
|
-
ggml_backend_t backend = ggml_backend_dev_init(devs[i], NULL);
|
|
853
|
-
GGML_ASSERT(backend != NULL);
|
|
854
|
-
|
|
855
|
-
if (ggml_backend_is_cpu(backend)) {
|
|
856
|
-
ggml_backend_cpu_set_n_threads(backend, std::thread::hardware_concurrency() / 2);
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
backends.push_back(backend);
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
for (size_t i = 0; i < dev_count; ++i) {
|
|
863
|
-
// Put the backend to be tested in front so that it's prioritized:
|
|
864
|
-
std::vector<ggml_backend_t> backends_modded = {backends[i]};
|
|
865
|
-
backends_modded.insert(backends_modded.end(), backends.begin(), backends.end());
|
|
866
|
-
|
|
867
|
-
ggml_backend_sched_t backend_sched = ggml_backend_sched_new(
|
|
868
|
-
backends_modded.data(), nullptr, backends_modded.size(), GGML_DEFAULT_GRAPH_SIZE, false, true);
|
|
869
|
-
|
|
870
|
-
printf("Backend %zu/%zu: %s\n", i + 1, dev_count, ggml_backend_dev_name(devs[i]));
|
|
871
|
-
printf(" Device description: %s\n", ggml_backend_dev_description(devs[i]));
|
|
872
|
-
size_t free, total; // NOLINT
|
|
873
|
-
ggml_backend_dev_memory(devs[i], &free, &total);
|
|
874
|
-
printf(" Device memory: %zu MB (%zu MB free)\n", total / 1024 / 1024, free / 1024 / 1024);
|
|
875
|
-
printf("\n");
|
|
876
|
-
|
|
877
|
-
std::pair<int, int> result = test_backend(backend_sched, backends[i]);
|
|
878
|
-
|
|
879
|
-
printf(" %d/%d tests passed\n", result.first, result.second);
|
|
880
|
-
printf(" Backend %s: ", ggml_backend_name(backends[i]));
|
|
881
|
-
if (result.first == result.second) {
|
|
882
|
-
printf("\033[1;32mOK\033[0m\n");
|
|
883
|
-
n_ok++;
|
|
884
|
-
} else {
|
|
885
|
-
printf("\033[1;31mFAIL\033[0m\n");
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
printf("\n");
|
|
889
|
-
|
|
890
|
-
ggml_backend_sched_free(backend_sched);
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
for (ggml_backend_t backend : backends) {
|
|
894
|
-
ggml_backend_free(backend);
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
printf("%zu/%zu backends passed\n", n_ok, dev_count);
|
|
898
|
-
if (n_ok != dev_count) {
|
|
899
|
-
printf("\033[1;31mFAIL\033[0m\n");
|
|
900
|
-
return 1;
|
|
901
|
-
}
|
|
902
|
-
printf("\033[1;32mOK\033[0m\n");
|
|
903
|
-
return 0;
|
|
904
|
-
}
|