@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,1092 +0,0 @@
|
|
|
1
|
-
#define _USE_MATH_DEFINES // For M_PI on MSVC
|
|
2
|
-
|
|
3
|
-
#include "arg.h"
|
|
4
|
-
#include "common.h"
|
|
5
|
-
#include "sampling.h"
|
|
6
|
-
#include "log.h"
|
|
7
|
-
#include "llama.h"
|
|
8
|
-
#include "json.hpp"
|
|
9
|
-
|
|
10
|
-
#include <algorithm>
|
|
11
|
-
#include <cmath>
|
|
12
|
-
#include <cstdio>
|
|
13
|
-
#include <fstream>
|
|
14
|
-
#include <map>
|
|
15
|
-
#include <regex>
|
|
16
|
-
#include <string>
|
|
17
|
-
#include <thread>
|
|
18
|
-
#include <vector>
|
|
19
|
-
|
|
20
|
-
using json = nlohmann::ordered_json;
|
|
21
|
-
|
|
22
|
-
enum outetts_version {
|
|
23
|
-
OUTETTS_V0_2,
|
|
24
|
-
OUTETTS_V0_3,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
// Terminal utils
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
#define SQR(X) ((X) * (X))
|
|
32
|
-
#define UNCUBE(x) x < 48 ? 0 : x < 115 ? 1 : (x - 35) / 40
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Quantizes 24-bit RGB to xterm256 code range [16,256).
|
|
36
|
-
*/
|
|
37
|
-
static int rgb2xterm256(int r, int g, int b) {
|
|
38
|
-
unsigned char cube[] = {0, 0137, 0207, 0257, 0327, 0377};
|
|
39
|
-
int av, ir, ig, ib, il, qr, qg, qb, ql;
|
|
40
|
-
av = r * .299 + g * .587 + b * .114 + .5;
|
|
41
|
-
ql = (il = av > 238 ? 23 : (av - 3) / 10) * 10 + 8;
|
|
42
|
-
qr = cube[(ir = UNCUBE(r))];
|
|
43
|
-
qg = cube[(ig = UNCUBE(g))];
|
|
44
|
-
qb = cube[(ib = UNCUBE(b))];
|
|
45
|
-
if (SQR(qr - r) + SQR(qg - g) + SQR(qb - b) <=
|
|
46
|
-
SQR(ql - r) + SQR(ql - g) + SQR(ql - b))
|
|
47
|
-
return ir * 36 + ig * 6 + ib + 020;
|
|
48
|
-
return il + 0350;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static std::string set_xterm256_foreground(int r, int g, int b) {
|
|
52
|
-
int x = rgb2xterm256(r, g, b);
|
|
53
|
-
std::ostringstream oss;
|
|
54
|
-
oss << "\033[38;5;" << x << "m";
|
|
55
|
-
return oss.str();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const std::vector<std::string> k_colors = {
|
|
59
|
-
set_xterm256_foreground(220, 5, 12),
|
|
60
|
-
set_xterm256_foreground(232, 96, 28),
|
|
61
|
-
set_xterm256_foreground(241, 147, 45),
|
|
62
|
-
set_xterm256_foreground(246, 193, 65),
|
|
63
|
-
set_xterm256_foreground(247, 240, 86),
|
|
64
|
-
set_xterm256_foreground(144, 201, 135),
|
|
65
|
-
set_xterm256_foreground( 78, 178, 101),
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
static void print_usage(int, char ** argv) {
|
|
69
|
-
LOG("\nexample usage:\n");
|
|
70
|
-
LOG("\n %s -m model.gguf -p \"Hello!\"\n", argv[0]);
|
|
71
|
-
LOG("\n");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
struct wav_header {
|
|
75
|
-
char riff[4] = {'R', 'I', 'F', 'F'};
|
|
76
|
-
uint32_t chunk_size;
|
|
77
|
-
char wave[4] = {'W', 'A', 'V', 'E'};
|
|
78
|
-
char fmt[4] = {'f', 'm', 't', ' '};
|
|
79
|
-
uint32_t fmt_chunk_size = 16;
|
|
80
|
-
uint16_t audio_format = 1; // PCM
|
|
81
|
-
uint16_t num_channels = 1; // Mono
|
|
82
|
-
uint32_t sample_rate;
|
|
83
|
-
uint32_t byte_rate;
|
|
84
|
-
uint16_t block_align;
|
|
85
|
-
uint16_t bits_per_sample = 16;
|
|
86
|
-
char data[4] = {'d', 'a', 't', 'a'};
|
|
87
|
-
uint32_t data_size;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
static bool save_wav16(const std::string & fname, const std::vector<float> & data, int sample_rate) {
|
|
91
|
-
std::ofstream file(fname, std::ios::binary);
|
|
92
|
-
if (!file) {
|
|
93
|
-
LOG_ERR("%s: Failed to open file '%s' for writing.\n", __func__, fname.c_str());
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
wav_header header;
|
|
98
|
-
header.sample_rate = sample_rate;
|
|
99
|
-
header.byte_rate = header.sample_rate * header.num_channels * (header.bits_per_sample / 8);
|
|
100
|
-
header.block_align = header.num_channels * (header.bits_per_sample / 8);
|
|
101
|
-
header.data_size = data.size() * (header.bits_per_sample / 8);
|
|
102
|
-
header.chunk_size = 36 + header.data_size;
|
|
103
|
-
|
|
104
|
-
file.write(reinterpret_cast<const char*>(&header), sizeof(header));
|
|
105
|
-
|
|
106
|
-
for (const auto & sample : data) {
|
|
107
|
-
int16_t pcm_sample = static_cast<int16_t>(std::clamp(sample * 32767.0, -32768.0, 32767.0));
|
|
108
|
-
file.write(reinterpret_cast<const char*>(&pcm_sample), sizeof(pcm_sample));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return file.good();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
static void fill_hann_window(int length, bool periodic, float * output) {
|
|
115
|
-
int offset = -1;
|
|
116
|
-
if (periodic) {
|
|
117
|
-
offset = 0;
|
|
118
|
-
}
|
|
119
|
-
for (int i = 0; i < length; i++) {
|
|
120
|
-
output[i] = 0.5 * (1.0 - cosf((2.0 * M_PI * i) / (length + offset)));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// very poor-man fft
|
|
125
|
-
static void twiddle(float * real, float * imag, int k, int N) {
|
|
126
|
-
float angle = 2 * M_PI * k / N;
|
|
127
|
-
*real = cos(angle);
|
|
128
|
-
*imag = sin(angle);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
static void irfft(int n, const float * inp_cplx, float * out_real) {
|
|
132
|
-
int N = n / 2 + 1;
|
|
133
|
-
|
|
134
|
-
std::vector<float> real_input(N);
|
|
135
|
-
std::vector<float> imag_input(N);
|
|
136
|
-
for (int i = 0; i < N; ++i) {
|
|
137
|
-
real_input[i] = inp_cplx[2 * i];
|
|
138
|
-
imag_input[i] = inp_cplx[2 * i + 1];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
std::vector<float> real_output(n);
|
|
142
|
-
std::vector<float> imag_output(n);
|
|
143
|
-
|
|
144
|
-
for (int k = 0; k < n; ++k) {
|
|
145
|
-
real_output[k] = 0.0f;
|
|
146
|
-
imag_output[k] = 0.0f;
|
|
147
|
-
for (int m = 0; m < N; ++m) {
|
|
148
|
-
float twiddle_real;
|
|
149
|
-
float twiddle_imag;
|
|
150
|
-
|
|
151
|
-
twiddle(&twiddle_real, &twiddle_imag, k * m, n);
|
|
152
|
-
|
|
153
|
-
real_output[k] += real_input[m] * twiddle_real - imag_input[m] * twiddle_imag;
|
|
154
|
-
imag_output[k] += real_input[m] * twiddle_imag + imag_input[m] * twiddle_real;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
for (int i = 0; i < n; ++i) {
|
|
159
|
-
out_real[i] = real_output[i] / N;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
//
|
|
164
|
-
// y = torch.nn.functional.fold(
|
|
165
|
-
// data, output_size=(1, output_size), kernel_size=(1, self.win_length), stride=(1, self.hop_length),
|
|
166
|
-
// )[:, 0, 0, pad:-pad]
|
|
167
|
-
//
|
|
168
|
-
// data.shape = torch.Size([1, 1280, 261])
|
|
169
|
-
// output_size = 84480
|
|
170
|
-
// win_length = 1280
|
|
171
|
-
// hop_length = 320
|
|
172
|
-
// pad = 480
|
|
173
|
-
//
|
|
174
|
-
static void fold(const std::vector<float> & data, int64_t n_out, int64_t n_win, int64_t n_hop, int64_t n_pad, std::vector<float> & output) {
|
|
175
|
-
int64_t output_height = n_out;
|
|
176
|
-
int64_t kernel_w = n_win;
|
|
177
|
-
int64_t stride_w = n_hop;
|
|
178
|
-
int64_t width = n_out;
|
|
179
|
-
|
|
180
|
-
output.resize(width, 0.0f);
|
|
181
|
-
|
|
182
|
-
int64_t col_idx = 0;
|
|
183
|
-
for (int64_t w_col = 0; w_col < width; ++w_col) {
|
|
184
|
-
int64_t start = w_col * stride_w - n_pad;
|
|
185
|
-
int64_t end = start + kernel_w;
|
|
186
|
-
|
|
187
|
-
for (int64_t w_im = start; w_im < end; ++w_im) {
|
|
188
|
-
if (w_im >= 0 && w_im < output_height && col_idx < (int64_t) data.size()) {
|
|
189
|
-
output[w_im] += data[col_idx];
|
|
190
|
-
}
|
|
191
|
-
col_idx++;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
output.resize(n_out - 2 * n_pad);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// TODO: not optimized at all
|
|
199
|
-
static std::vector<float> embd_to_audio(
|
|
200
|
-
const float * embd,
|
|
201
|
-
const int n_codes,
|
|
202
|
-
const int n_embd,
|
|
203
|
-
const int n_thread) {
|
|
204
|
-
const int n_fft = 1280;
|
|
205
|
-
const int n_hop = 320;
|
|
206
|
-
const int n_win = 1280;
|
|
207
|
-
const int n_pad = (n_win - n_hop)/2;
|
|
208
|
-
const int n_out = (n_codes - 1)*n_hop + n_win;
|
|
209
|
-
|
|
210
|
-
std::vector<float> hann(n_fft);
|
|
211
|
-
|
|
212
|
-
fill_hann_window(hann.size(), true, hann.data());
|
|
213
|
-
|
|
214
|
-
int n_spec = n_embd*n_codes;
|
|
215
|
-
|
|
216
|
-
std::vector<float> E (n_spec);
|
|
217
|
-
std::vector<float> S (n_spec);
|
|
218
|
-
std::vector<float> ST(n_spec);
|
|
219
|
-
|
|
220
|
-
for (int l = 0; l < n_codes; ++l) {
|
|
221
|
-
for (int k = 0; k < n_embd; ++k) {
|
|
222
|
-
E[k*n_codes + l] = embd[l*n_embd + k];
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
for (int k = 0; k < n_embd/2; ++k) {
|
|
227
|
-
for (int l = 0; l < n_codes; ++l) {
|
|
228
|
-
float mag = E[(k )*n_codes + l];
|
|
229
|
-
float phi = E[(k + n_embd/2)*n_codes + l];
|
|
230
|
-
|
|
231
|
-
mag = exp(mag);
|
|
232
|
-
|
|
233
|
-
if (mag > 1e2) {
|
|
234
|
-
mag = 1e2;
|
|
235
|
-
}
|
|
236
|
-
S[2*(k*n_codes + l) + 0] = mag*cosf(phi);
|
|
237
|
-
S[2*(k*n_codes + l) + 1] = mag*sinf(phi);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
for (int l = 0; l < n_codes; ++l) {
|
|
242
|
-
for (int k = 0; k < n_embd/2; ++k) {
|
|
243
|
-
ST[l*n_embd + 2*k + 0] = S[2*(k*n_codes + l) + 0];
|
|
244
|
-
ST[l*n_embd + 2*k + 1] = S[2*(k*n_codes + l) + 1];
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
std::vector<float> res (n_codes*n_fft);
|
|
249
|
-
std::vector<float> hann2(n_codes*n_fft);
|
|
250
|
-
|
|
251
|
-
std::vector<std::thread> workers(n_thread);
|
|
252
|
-
for (int i = 0; i < n_thread; ++i) {
|
|
253
|
-
workers[i] = std::thread([&, i]() {
|
|
254
|
-
for (int l = i; l < n_codes; l += n_thread) {
|
|
255
|
-
irfft(n_fft, ST.data() + l*n_embd, res.data() + l*n_fft);
|
|
256
|
-
for (int j = 0; j < n_fft; ++j) {
|
|
257
|
-
res [l*n_fft + j] *= hann[j];
|
|
258
|
-
hann2[l*n_fft + j] = hann[j] * hann[j];
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
for (int i = 0; i < n_thread; ++i) {
|
|
264
|
-
workers[i].join();
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
std::vector<float> audio;
|
|
268
|
-
std::vector<float> env;
|
|
269
|
-
|
|
270
|
-
fold(res, n_out, n_win, n_hop, n_pad, audio);
|
|
271
|
-
fold(hann2, n_out, n_win, n_hop, n_pad, env); // TODO: can be done once
|
|
272
|
-
|
|
273
|
-
for (size_t i = 0; i < audio.size(); ++i) {
|
|
274
|
-
audio[i] /= env[i];
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return audio;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
static const std::map<int, std::string> ones = {
|
|
281
|
-
{0, "zero"}, {1, "one"}, {2, "two"}, {3, "three"}, {4, "four"},
|
|
282
|
-
{5, "five"}, {6, "six"}, {7, "seven"}, {8, "eight"}, {9, "nine"},
|
|
283
|
-
{10, "ten"}, {11, "eleven"}, {12, "twelve"}, {13, "thirteen"}, {14, "fourteen"},
|
|
284
|
-
{15, "fifteen"}, {16, "sixteen"}, {17, "seventeen"}, {18, "eighteen"}, {19, "nineteen"}
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
static const std::map<int, std::string> tens = {
|
|
288
|
-
{2, "twenty"}, {3, "thirty"}, {4, "forty"}, {5, "fifty"},
|
|
289
|
-
{6, "sixty"}, {7, "seventy"}, {8, "eighty"}, {9, "ninety"}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
// Convert a number less than 1000 to words
|
|
293
|
-
static std::string convert_less_than_thousand(int num) {
|
|
294
|
-
std::string result;
|
|
295
|
-
|
|
296
|
-
if (num >= 100) {
|
|
297
|
-
result += ones.at(num / 100) + " hundred ";
|
|
298
|
-
num %= 100;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (num >= 20) {
|
|
302
|
-
result += tens.at(num / 10);
|
|
303
|
-
if (num % 10 > 0) {
|
|
304
|
-
result += "-" + ones.at(num % 10);
|
|
305
|
-
}
|
|
306
|
-
} else if (num > 0) {
|
|
307
|
-
result += ones.at(num);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return result;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
static std::string number_to_words(const std::string & number_str) {
|
|
314
|
-
try {
|
|
315
|
-
size_t decimal_pos = number_str.find('.');
|
|
316
|
-
std::string integer_part = number_str.substr(0, decimal_pos);
|
|
317
|
-
|
|
318
|
-
int int_number = std::stoi(integer_part);
|
|
319
|
-
std::string result;
|
|
320
|
-
|
|
321
|
-
if (int_number == 0) {
|
|
322
|
-
result = "zero";
|
|
323
|
-
} else {
|
|
324
|
-
if (int_number >= 1000000000) {
|
|
325
|
-
int billions = int_number / 1000000000;
|
|
326
|
-
result += convert_less_than_thousand(billions) + " billion ";
|
|
327
|
-
int_number %= 1000000000;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (int_number >= 1000000) {
|
|
331
|
-
int millions = int_number / 1000000;
|
|
332
|
-
result += convert_less_than_thousand(millions) + " million ";
|
|
333
|
-
int_number %= 1000000;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
if (int_number >= 1000) {
|
|
337
|
-
int thousands = int_number / 1000;
|
|
338
|
-
result += convert_less_than_thousand(thousands) + " thousand ";
|
|
339
|
-
int_number %= 1000;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (int_number > 0) {
|
|
343
|
-
result += convert_less_than_thousand(int_number);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// Handle decimal part
|
|
348
|
-
if (decimal_pos != std::string::npos) {
|
|
349
|
-
result += " point";
|
|
350
|
-
std::string decimal_part = number_str.substr(decimal_pos + 1);
|
|
351
|
-
for (char digit : decimal_part) {
|
|
352
|
-
result += " " + ones.at(digit - '0');
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
return result;
|
|
357
|
-
} catch (const std::exception& e) {
|
|
358
|
-
// Skip if fails
|
|
359
|
-
return " ";
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
static std::string replace_numbers_with_words(const std::string & input_text) {
|
|
364
|
-
std::regex number_pattern(R"(\d+(\.\d+)?)");
|
|
365
|
-
std::string result;
|
|
366
|
-
auto it = std::sregex_iterator(input_text.begin(), input_text.end(), number_pattern);
|
|
367
|
-
auto end = std::sregex_iterator();
|
|
368
|
-
|
|
369
|
-
size_t last_pos = 0;
|
|
370
|
-
for (std::sregex_iterator i = it; i != end; ++i) {
|
|
371
|
-
const std::smatch& match = *i;
|
|
372
|
-
result.append(input_text, last_pos, match.position() - last_pos);
|
|
373
|
-
result.append(number_to_words(match.str()));
|
|
374
|
-
last_pos = match.position() + match.length();
|
|
375
|
-
}
|
|
376
|
-
result.append(input_text, last_pos);
|
|
377
|
-
|
|
378
|
-
return result;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// Based on: https://github.com/edwko/OuteTTS/blob/a613e79c489d8256dd657ea9168d78de75895d82/outetts/version/v1/prompt_processor.py#L39
|
|
382
|
-
static std::string process_text(const std::string & text, const outetts_version tts_version = OUTETTS_V0_2) {
|
|
383
|
-
|
|
384
|
-
// For now I skipped text romanization as I am unsure how to handle
|
|
385
|
-
// uroman and MeCab implementations in C++
|
|
386
|
-
// maybe something like https://github.com/anyascii/anyascii/ could work.
|
|
387
|
-
// currently only English would be supported in this function
|
|
388
|
-
|
|
389
|
-
std::string processed_text = replace_numbers_with_words(text);
|
|
390
|
-
|
|
391
|
-
std::transform(processed_text.begin(), processed_text.end(),
|
|
392
|
-
processed_text.begin(), ::tolower);
|
|
393
|
-
|
|
394
|
-
std::regex special_chars(R"([-_/,\.\\])");
|
|
395
|
-
processed_text = std::regex_replace(processed_text, special_chars, " ");
|
|
396
|
-
|
|
397
|
-
std::regex non_alpha(R"([^a-z\s])");
|
|
398
|
-
processed_text = std::regex_replace(processed_text, non_alpha, "");
|
|
399
|
-
|
|
400
|
-
std::regex multiple_spaces(R"(\s+)");
|
|
401
|
-
processed_text = std::regex_replace(processed_text, multiple_spaces, " ");
|
|
402
|
-
|
|
403
|
-
processed_text = std::regex_replace(processed_text, std::regex(R"(^\s+|\s+$)"), "");
|
|
404
|
-
|
|
405
|
-
/*
|
|
406
|
-
Replace spaces with the separator token same as in line 365
|
|
407
|
-
|
|
408
|
-
for (auto & c : prompt_user) {
|
|
409
|
-
if (c == ' ') {
|
|
410
|
-
prompt_clean += "<|text_sep|>";
|
|
411
|
-
*/
|
|
412
|
-
std::string separator = (tts_version == OUTETTS_V0_3) ? "<|space|>" : "<|text_sep|>";
|
|
413
|
-
processed_text = std::regex_replace(processed_text, std::regex(R"(\s)"), separator);
|
|
414
|
-
|
|
415
|
-
return processed_text;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
static void prompt_add(llama_tokens & prompt, llama_token token) {
|
|
419
|
-
prompt.push_back(token);
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
static void prompt_add(llama_tokens & prompt, const llama_tokens & tokens) {
|
|
423
|
-
prompt.insert(prompt.end(), tokens.begin(), tokens.end());
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
static void prompt_add(llama_tokens & prompt, const llama_vocab * vocab, const std::string & txt, bool add_special, bool parse_special) {
|
|
427
|
-
auto tmp = common_tokenize(vocab, txt, add_special, parse_special);
|
|
428
|
-
prompt_add(prompt, tmp);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
static void prompt_init(llama_tokens & prompt, const llama_vocab * vocab) {
|
|
432
|
-
prompt.clear();
|
|
433
|
-
|
|
434
|
-
prompt_add(prompt, vocab, "<|im_start|>\n", true, true);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
static std::vector<llama_token> prepare_guide_tokens(const llama_vocab * vocab, const std::string & str, const outetts_version tts_version = OUTETTS_V0_2) {
|
|
438
|
-
const std::string& delimiter = (tts_version == OUTETTS_V0_3 ? "<|space|>" : "<|text_sep|>");
|
|
439
|
-
|
|
440
|
-
std::vector<llama_token> result;
|
|
441
|
-
size_t start = 0;
|
|
442
|
-
size_t end = str.find(delimiter);
|
|
443
|
-
|
|
444
|
-
//first token is always a newline, as it was not previously added
|
|
445
|
-
result.push_back(common_tokenize(vocab, "\n", false, true)[0]);
|
|
446
|
-
|
|
447
|
-
while (end != std::string::npos) {
|
|
448
|
-
std::string current_word = str.substr(start, end - start);
|
|
449
|
-
auto tmp = common_tokenize(vocab, current_word, false, true);
|
|
450
|
-
result.push_back(tmp[0]);
|
|
451
|
-
start = end + delimiter.length();
|
|
452
|
-
end = str.find(delimiter, start);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// Add the last part
|
|
456
|
-
std::string current_word = str.substr(start);
|
|
457
|
-
auto tmp = common_tokenize(vocab, current_word, false, true);
|
|
458
|
-
if (tmp.size() > 0) {
|
|
459
|
-
result.push_back(tmp[0]);
|
|
460
|
-
}
|
|
461
|
-
return result;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
static json speaker_from_file(const std::string & speaker_file) {
|
|
465
|
-
std::ifstream file(speaker_file);
|
|
466
|
-
if (!file) {
|
|
467
|
-
LOG_ERR("%s: Failed to open file '%s' for reading\n", __func__, speaker_file.c_str());
|
|
468
|
-
return json();
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
json speaker = json::parse(file);
|
|
472
|
-
return speaker;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
static outetts_version get_tts_version(llama_model *model, json speaker = json::object()) {
|
|
476
|
-
if (speaker.contains("version")) {
|
|
477
|
-
std::string version = speaker["version"].get<std::string>();
|
|
478
|
-
if (version == "0.2") {
|
|
479
|
-
return OUTETTS_V0_2;
|
|
480
|
-
} else if (version == "0.3") {
|
|
481
|
-
return OUTETTS_V0_3;
|
|
482
|
-
} else {
|
|
483
|
-
LOG_ERR("%s: Unsupported speaker version '%s'\n", __func__, version.c_str());
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// Also could get version from model itself
|
|
488
|
-
const char *chat_template = llama_model_chat_template(model, nullptr);
|
|
489
|
-
if (chat_template && std::string(chat_template) == "outetts-0.3") {
|
|
490
|
-
return OUTETTS_V0_3;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// Use 0.2 as the default version
|
|
494
|
-
return OUTETTS_V0_2;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
static std::string audio_text_from_speaker(json speaker, const outetts_version tts_version = OUTETTS_V0_2) {
|
|
498
|
-
std::string audio_text = "<|text_start|>";
|
|
499
|
-
|
|
500
|
-
if (tts_version == OUTETTS_V0_2 || tts_version == OUTETTS_V0_3) {
|
|
501
|
-
std::string separator = (tts_version == OUTETTS_V0_3) ? "<|space|>" : "<|text_sep|>";
|
|
502
|
-
for (const auto &word : speaker["words"]) {
|
|
503
|
-
audio_text += word["word"].get<std::string>() + separator;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
return audio_text;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
static std::string audio_data_from_speaker(json speaker, const outetts_version tts_version = OUTETTS_V0_2) {
|
|
511
|
-
std::string audio_data = "<|audio_start|>\n";
|
|
512
|
-
|
|
513
|
-
if (tts_version == OUTETTS_V0_2 || tts_version == OUTETTS_V0_3) {
|
|
514
|
-
std::string code_start = (tts_version == OUTETTS_V0_3) ? "" : "<|code_start|>";
|
|
515
|
-
std::string code_end = (tts_version == OUTETTS_V0_3) ? "<|space|>" : "<|code_end|>";
|
|
516
|
-
for (const auto &word : speaker["words"]) {
|
|
517
|
-
std::string word_text = word["word"].get<std::string>();
|
|
518
|
-
double duration = word["duration"].get<double>();
|
|
519
|
-
std::vector<int> codes = word["codes"].get<std::vector<int>>();
|
|
520
|
-
|
|
521
|
-
// Create the audio output entry
|
|
522
|
-
std::ostringstream word_entry;
|
|
523
|
-
word_entry << word_text << "<|t_" << std::fixed << std::setprecision(2)
|
|
524
|
-
<< duration << "|>" + code_start;
|
|
525
|
-
for (const auto &Code : codes) {
|
|
526
|
-
word_entry << "<|" << Code << "|>";
|
|
527
|
-
}
|
|
528
|
-
word_entry << code_end << "\n";
|
|
529
|
-
audio_data += word_entry.str();
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
return audio_data;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
int main(int argc, char ** argv) {
|
|
537
|
-
common_params params;
|
|
538
|
-
|
|
539
|
-
params.out_file = "output.wav";
|
|
540
|
-
params.prompt = "";
|
|
541
|
-
|
|
542
|
-
params.n_predict = 4096;
|
|
543
|
-
params.n_batch = 8192;
|
|
544
|
-
params.n_ctx = 8192;
|
|
545
|
-
|
|
546
|
-
params.sampling.top_k = 4;
|
|
547
|
-
params.sampling.samplers = { COMMON_SAMPLER_TYPE_TOP_K, };
|
|
548
|
-
|
|
549
|
-
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_TTS, print_usage)) {
|
|
550
|
-
return 1;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
const int n_parallel = params.n_parallel;
|
|
554
|
-
const int n_predict = params.n_predict;
|
|
555
|
-
|
|
556
|
-
common_init();
|
|
557
|
-
|
|
558
|
-
// init LLM
|
|
559
|
-
|
|
560
|
-
llama_backend_init();
|
|
561
|
-
llama_numa_init(params.numa);
|
|
562
|
-
|
|
563
|
-
llama_model * model_ttc = NULL; // text-to-codes
|
|
564
|
-
llama_model * model_cts = NULL; // codes-to-speech
|
|
565
|
-
|
|
566
|
-
llama_context * ctx_ttc = NULL;
|
|
567
|
-
llama_context * ctx_cts = NULL;
|
|
568
|
-
|
|
569
|
-
common_init_result llama_init_ttc = common_init_from_params(params);
|
|
570
|
-
|
|
571
|
-
model_ttc = llama_init_ttc.model.get();
|
|
572
|
-
ctx_ttc = llama_init_ttc.context.get();
|
|
573
|
-
|
|
574
|
-
if (model_ttc == nullptr || ctx_ttc == nullptr) {
|
|
575
|
-
return ENOENT;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
const llama_vocab * vocab = llama_model_get_vocab(model_ttc);
|
|
579
|
-
|
|
580
|
-
params.model = params.vocoder.model;
|
|
581
|
-
params.embedding = true;
|
|
582
|
-
params.ctx_shift = false; // silence warning
|
|
583
|
-
params.n_ubatch = params.n_batch;
|
|
584
|
-
|
|
585
|
-
common_init_result llama_init_cts = common_init_from_params(params);
|
|
586
|
-
|
|
587
|
-
model_cts = llama_init_cts.model.get();
|
|
588
|
-
ctx_cts = llama_init_cts.context.get();
|
|
589
|
-
|
|
590
|
-
if (model_cts == nullptr || ctx_cts == nullptr) {
|
|
591
|
-
return ENOENT;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
std::vector<common_sampler *> smpl(n_parallel);
|
|
595
|
-
for (int i = 0; i < n_parallel; ++i) {
|
|
596
|
-
params.sampling.no_perf = (i != 0);
|
|
597
|
-
params.sampling.seed = params.sampling.seed + 1;
|
|
598
|
-
|
|
599
|
-
smpl[i] = common_sampler_init(model_ttc, params.sampling);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
LOG_INF("sampler seed: %u\n", common_sampler_get_seed(smpl[0]));
|
|
603
|
-
LOG_INF("sampler params: \n%s\n", params.sampling.print().c_str());
|
|
604
|
-
LOG_INF("sampler chain: %s\n", common_sampler_print(smpl[0]).c_str());
|
|
605
|
-
|
|
606
|
-
LOG_INF("%s: loading done\n", __func__);
|
|
607
|
-
|
|
608
|
-
const auto t_main_start = ggml_time_us();
|
|
609
|
-
|
|
610
|
-
std::vector<llama_token> codes;
|
|
611
|
-
std::vector<llama_token> guide_tokens;
|
|
612
|
-
|
|
613
|
-
// the default speaker profile is from: https://github.com/edwko/OuteTTS/blob/main/outetts/version/v1/default_speakers/en_male_1.json
|
|
614
|
-
std::string audio_text = "<|text_start|>the<|text_sep|>overall<|text_sep|>package<|text_sep|>from<|text_sep|>just<|text_sep|>two<|text_sep|>people<|text_sep|>is<|text_sep|>pretty<|text_sep|>remarkable<|text_sep|>sure<|text_sep|>i<|text_sep|>have<|text_sep|>some<|text_sep|>critiques<|text_sep|>about<|text_sep|>some<|text_sep|>of<|text_sep|>the<|text_sep|>gameplay<|text_sep|>aspects<|text_sep|>but<|text_sep|>its<|text_sep|>still<|text_sep|>really<|text_sep|>enjoyable<|text_sep|>and<|text_sep|>it<|text_sep|>looks<|text_sep|>lovely<|text_sep|>";
|
|
615
|
-
std::string audio_data = R"(<|audio_start|>
|
|
616
|
-
the<|t_0.08|><|code_start|><|257|><|740|><|636|><|913|><|788|><|1703|><|code_end|>
|
|
617
|
-
overall<|t_0.36|><|code_start|><|127|><|201|><|191|><|774|><|700|><|532|><|1056|><|557|><|798|><|298|><|1741|><|747|><|1662|><|1617|><|1702|><|1527|><|368|><|1588|><|1049|><|1008|><|1625|><|747|><|1576|><|728|><|1019|><|1696|><|1765|><|code_end|>
|
|
618
|
-
package<|t_0.56|><|code_start|><|935|><|584|><|1319|><|627|><|1016|><|1491|><|1344|><|1117|><|1526|><|1040|><|239|><|1435|><|951|><|498|><|723|><|1180|><|535|><|789|><|1649|><|1637|><|78|><|465|><|1668|><|901|><|595|><|1675|><|117|><|1009|><|1667|><|320|><|840|><|79|><|507|><|1762|><|1508|><|1228|><|1768|><|802|><|1450|><|1457|><|232|><|639|><|code_end|>
|
|
619
|
-
from<|t_0.19|><|code_start|><|604|><|782|><|1682|><|872|><|1532|><|1600|><|1036|><|1761|><|647|><|1554|><|1371|><|653|><|1595|><|950|><|code_end|>
|
|
620
|
-
just<|t_0.25|><|code_start|><|1782|><|1670|><|317|><|786|><|1748|><|631|><|599|><|1155|><|1364|><|1524|><|36|><|1591|><|889|><|1535|><|541|><|440|><|1532|><|50|><|870|><|code_end|>
|
|
621
|
-
two<|t_0.24|><|code_start|><|1681|><|1510|><|673|><|799|><|805|><|1342|><|330|><|519|><|62|><|640|><|1138|><|565|><|1552|><|1497|><|1552|><|572|><|1715|><|1732|><|code_end|>
|
|
622
|
-
people<|t_0.39|><|code_start|><|593|><|274|><|136|><|740|><|691|><|633|><|1484|><|1061|><|1138|><|1485|><|344|><|428|><|397|><|1562|><|645|><|917|><|1035|><|1449|><|1669|><|487|><|442|><|1484|><|1329|><|1832|><|1704|><|600|><|761|><|653|><|269|><|code_end|>
|
|
623
|
-
is<|t_0.16|><|code_start|><|566|><|583|><|1755|><|646|><|1337|><|709|><|802|><|1008|><|485|><|1583|><|652|><|10|><|code_end|>
|
|
624
|
-
pretty<|t_0.32|><|code_start|><|1818|><|1747|><|692|><|733|><|1010|><|534|><|406|><|1697|><|1053|><|1521|><|1355|><|1274|><|816|><|1398|><|211|><|1218|><|817|><|1472|><|1703|><|686|><|13|><|822|><|445|><|1068|><|code_end|>
|
|
625
|
-
remarkable<|t_0.68|><|code_start|><|230|><|1048|><|1705|><|355|><|706|><|1149|><|1535|><|1787|><|1356|><|1396|><|835|><|1583|><|486|><|1249|><|286|><|937|><|1076|><|1150|><|614|><|42|><|1058|><|705|><|681|><|798|><|934|><|490|><|514|><|1399|><|572|><|1446|><|1703|><|1346|><|1040|><|1426|><|1304|><|664|><|171|><|1530|><|625|><|64|><|1708|><|1830|><|1030|><|443|><|1509|><|1063|><|1605|><|1785|><|721|><|1440|><|923|><|code_end|>
|
|
626
|
-
sure<|t_0.36|><|code_start|><|792|><|1780|><|923|><|1640|><|265|><|261|><|1525|><|567|><|1491|><|1250|><|1730|><|362|><|919|><|1766|><|543|><|1|><|333|><|113|><|970|><|252|><|1606|><|133|><|302|><|1810|><|1046|><|1190|><|1675|><|code_end|>
|
|
627
|
-
i<|t_0.08|><|code_start|><|123|><|439|><|1074|><|705|><|1799|><|637|><|code_end|>
|
|
628
|
-
have<|t_0.16|><|code_start|><|1509|><|599|><|518|><|1170|><|552|><|1029|><|1267|><|864|><|419|><|143|><|1061|><|0|><|code_end|>
|
|
629
|
-
some<|t_0.16|><|code_start|><|619|><|400|><|1270|><|62|><|1370|><|1832|><|917|><|1661|><|167|><|269|><|1366|><|1508|><|code_end|>
|
|
630
|
-
critiques<|t_0.60|><|code_start|><|559|><|584|><|1163|><|1129|><|1313|><|1728|><|721|><|1146|><|1093|><|577|><|928|><|27|><|630|><|1080|><|1346|><|1337|><|320|><|1382|><|1175|><|1682|><|1556|><|990|><|1683|><|860|><|1721|><|110|><|786|><|376|><|1085|><|756|><|1523|><|234|><|1334|><|1506|><|1578|><|659|><|612|><|1108|><|1466|><|1647|><|308|><|1470|><|746|><|556|><|1061|><|code_end|>
|
|
631
|
-
about<|t_0.29|><|code_start|><|26|><|1649|><|545|><|1367|><|1263|><|1728|><|450|><|859|><|1434|><|497|><|1220|><|1285|><|179|><|755|><|1154|><|779|><|179|><|1229|><|1213|><|922|><|1774|><|1408|><|code_end|>
|
|
632
|
-
some<|t_0.23|><|code_start|><|986|><|28|><|1649|><|778|><|858|><|1519|><|1|><|18|><|26|><|1042|><|1174|><|1309|><|1499|><|1712|><|1692|><|1516|><|1574|><|code_end|>
|
|
633
|
-
of<|t_0.07|><|code_start|><|197|><|716|><|1039|><|1662|><|64|><|code_end|>
|
|
634
|
-
the<|t_0.08|><|code_start|><|1811|><|1568|><|569|><|886|><|1025|><|1374|><|code_end|>
|
|
635
|
-
gameplay<|t_0.48|><|code_start|><|1269|><|1092|><|933|><|1362|><|1762|><|1700|><|1675|><|215|><|781|><|1086|><|461|><|838|><|1022|><|759|><|649|><|1416|><|1004|><|551|><|909|><|787|><|343|><|830|><|1391|><|1040|><|1622|><|1779|><|1360|><|1231|><|1187|><|1317|><|76|><|997|><|989|><|978|><|737|><|189|><|code_end|>
|
|
636
|
-
aspects<|t_0.56|><|code_start|><|1423|><|797|><|1316|><|1222|><|147|><|719|><|1347|><|386|><|1390|><|1558|><|154|><|440|><|634|><|592|><|1097|><|1718|><|712|><|763|><|1118|><|1721|><|1311|><|868|><|580|><|362|><|1435|><|868|><|247|><|221|><|886|><|1145|><|1274|><|1284|><|457|><|1043|><|1459|><|1818|><|62|><|599|><|1035|><|62|><|1649|><|778|><|code_end|>
|
|
637
|
-
but<|t_0.20|><|code_start|><|780|><|1825|><|1681|><|1007|><|861|><|710|><|702|><|939|><|1669|><|1491|><|613|><|1739|><|823|><|1469|><|648|><|code_end|>
|
|
638
|
-
its<|t_0.09|><|code_start|><|92|><|688|><|1623|><|962|><|1670|><|527|><|599|><|code_end|>
|
|
639
|
-
still<|t_0.27|><|code_start|><|636|><|10|><|1217|><|344|><|713|><|957|><|823|><|154|><|1649|><|1286|><|508|><|214|><|1760|><|1250|><|456|><|1352|><|1368|><|921|><|615|><|5|><|code_end|>
|
|
640
|
-
really<|t_0.36|><|code_start|><|55|><|420|><|1008|><|1659|><|27|><|644|><|1266|><|617|><|761|><|1712|><|109|><|1465|><|1587|><|503|><|1541|><|619|><|197|><|1019|><|817|><|269|><|377|><|362|><|1381|><|507|><|1488|><|4|><|1695|><|code_end|>
|
|
641
|
-
enjoyable<|t_0.49|><|code_start|><|678|><|501|><|864|><|319|><|288|><|1472|><|1341|><|686|><|562|><|1463|><|619|><|1563|><|471|><|911|><|730|><|1811|><|1006|><|520|><|861|><|1274|><|125|><|1431|><|638|><|621|><|153|><|876|><|1770|><|437|><|987|><|1653|><|1109|><|898|><|1285|><|80|><|593|><|1709|><|843|><|code_end|>
|
|
642
|
-
and<|t_0.15|><|code_start|><|1285|><|987|><|303|><|1037|><|730|><|1164|><|502|><|120|><|1737|><|1655|><|1318|><|code_end|>
|
|
643
|
-
it<|t_0.09|><|code_start|><|848|><|1366|><|395|><|1601|><|1513|><|593|><|1302|><|code_end|>
|
|
644
|
-
looks<|t_0.27|><|code_start|><|1281|><|1266|><|1755|><|572|><|248|><|1751|><|1257|><|695|><|1380|><|457|><|659|><|585|><|1315|><|1105|><|1776|><|736|><|24|><|736|><|654|><|1027|><|code_end|>
|
|
645
|
-
lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|1481|><|1721|><|1123|><|438|><|1246|><|1251|><|795|><|659|><|1381|><|1658|><|217|><|1772|><|562|><|952|><|107|><|1129|><|1112|><|467|><|550|><|1079|><|840|><|1615|><|1469|><|1380|><|168|><|917|><|836|><|1827|><|437|><|583|><|67|><|595|><|1087|><|1646|><|1493|><|1677|><|code_end|>)";
|
|
646
|
-
|
|
647
|
-
// audio data for 0.3 version
|
|
648
|
-
outetts_version tts_version = get_tts_version(model_ttc);
|
|
649
|
-
if (tts_version == OUTETTS_V0_3) {
|
|
650
|
-
audio_text = std::regex_replace(audio_text, std::regex(R"(<\|text_sep\|>)"), "<|space|>");
|
|
651
|
-
audio_data = std::regex_replace(audio_data, std::regex(R"(<\|code_start\|>)"), "");
|
|
652
|
-
audio_data = std::regex_replace(audio_data, std::regex(R"(<\|code_end\|>)"), "<|space|>");
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
// load speaker if given
|
|
656
|
-
if (!params.vocoder.speaker_file.empty()) {
|
|
657
|
-
LOG_INF("%s: loading speaker ..\n", __func__);
|
|
658
|
-
json speaker = speaker_from_file(params.vocoder.speaker_file);
|
|
659
|
-
if (speaker.empty()) {
|
|
660
|
-
LOG_ERR("%s: Failed to load speaker file '%s'\n", __func__, params.vocoder.speaker_file.c_str());
|
|
661
|
-
return 1;
|
|
662
|
-
}
|
|
663
|
-
audio_text = audio_text_from_speaker(speaker, tts_version);
|
|
664
|
-
audio_data = audio_data_from_speaker(speaker, tts_version);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
// process prompt and generate voice codes
|
|
668
|
-
{
|
|
669
|
-
LOG_INF("%s: constructing prompt ..\n", __func__);
|
|
670
|
-
|
|
671
|
-
std::vector<llama_token> prompt_inp;
|
|
672
|
-
|
|
673
|
-
prompt_init(prompt_inp, vocab);
|
|
674
|
-
|
|
675
|
-
prompt_add(prompt_inp, vocab, audio_text, false, true);
|
|
676
|
-
|
|
677
|
-
// convert the input text into the necessary format expected by OuteTTS
|
|
678
|
-
{
|
|
679
|
-
std::string prompt_clean = process_text(params.prompt, tts_version);
|
|
680
|
-
if (params.vocoder.use_guide_tokens) {
|
|
681
|
-
guide_tokens = prepare_guide_tokens(vocab, prompt_clean, tts_version);
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
LOG_INF("%s: prompt: '%s'\n", __func__, prompt_clean.c_str());
|
|
685
|
-
|
|
686
|
-
prompt_add(prompt_inp, vocab, prompt_clean, false, true);
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
prompt_add(prompt_inp, vocab, "<|text_end|>\n", false, true);
|
|
690
|
-
|
|
691
|
-
if (!params.vocoder.speaker_file.empty()) {
|
|
692
|
-
prompt_add(prompt_inp, vocab, audio_data, false, true);
|
|
693
|
-
} else {
|
|
694
|
-
// disabled to save time on tokenizing each time
|
|
695
|
-
#if 1
|
|
696
|
-
const std::string voice_data = audio_data;
|
|
697
|
-
|
|
698
|
-
auto tmp = common_tokenize(vocab, voice_data, false, true);
|
|
699
|
-
|
|
700
|
-
std::ostringstream tokens_oss;
|
|
701
|
-
for (size_t i = 0; i < tmp.size(); ++i) {
|
|
702
|
-
tokens_oss << tmp[i] << ", ";
|
|
703
|
-
}
|
|
704
|
-
LOG_INF("\n\n%s: llama tokens: %s\n\n", __func__, tokens_oss.str().c_str());
|
|
705
|
-
|
|
706
|
-
prompt_add(prompt_inp, tmp);
|
|
707
|
-
#else
|
|
708
|
-
prompt_add(prompt_inp, llama_tokens {
|
|
709
|
-
151667, 198, 1782, 155780, 151669, 151929, 152412, 152308, 152585,
|
|
710
|
-
152460, 153375, 151670, 198, 74455, 155808, 151669, 151799,
|
|
711
|
-
151873, 151863, 152446, 152372, 152204, 152728, 152229, 152470,
|
|
712
|
-
151970, 153413, 152419, 153334, 153289, 153374, 153199, 152040,
|
|
713
|
-
153260, 152721, 152680, 153297, 152419, 153248, 152400, 152691,
|
|
714
|
-
153368, 153437, 151670, 198, 1722, 155828, 151669, 152607,
|
|
715
|
-
152256, 152991, 152299, 152688, 153163, 153016, 152789, 153198,
|
|
716
|
-
152712, 151911, 153107, 152623, 152170, 152395, 152852, 152207,
|
|
717
|
-
152461, 153321, 153309, 151750, 152137, 153340, 152573, 152267,
|
|
718
|
-
153347, 151789, 152681, 153339, 151992, 152512, 151751, 152179,
|
|
719
|
-
153434, 153180, 152900, 153440, 152474, 153122, 153129, 151904,
|
|
720
|
-
152311, 151670, 198, 1499, 155791, 151669, 152276, 152454,
|
|
721
|
-
153354, 152544, 153204, 153272, 152708, 153433, 152319, 153226,
|
|
722
|
-
153043, 152325, 153267, 152622, 151670, 198, 4250, 155797,
|
|
723
|
-
151669, 153454, 153342, 151989, 152458, 153420, 152303, 152271,
|
|
724
|
-
152827, 153036, 153196, 151708, 153263, 152561, 153207, 152213,
|
|
725
|
-
152112, 153204, 151722, 152542, 151670, 198, 19789, 155796,
|
|
726
|
-
151669, 153353, 153182, 152345, 152471, 152477, 153014, 152002,
|
|
727
|
-
152191, 151734, 152312, 152810, 152237, 153224, 153169, 153224,
|
|
728
|
-
152244, 153387, 153404, 151670, 198, 16069, 155811, 151669,
|
|
729
|
-
152265, 151946, 151808, 152412, 152363, 152305, 153156, 152733,
|
|
730
|
-
152810, 153157, 152016, 152100, 152069, 153234, 152317, 152589,
|
|
731
|
-
152707, 153121, 153341, 152159, 152114, 153156, 153001, 153504,
|
|
732
|
-
153376, 152272, 152433, 152325, 151941, 151670, 198, 285,
|
|
733
|
-
155788, 151669, 152238, 152255, 153427, 152318, 153009, 152381,
|
|
734
|
-
152474, 152680, 152157, 153255, 152324, 151682, 151670, 198,
|
|
735
|
-
32955, 155804, 151669, 153490, 153419, 152364, 152405, 152682,
|
|
736
|
-
152206, 152078, 153369, 152725, 153193, 153027, 152946, 152488,
|
|
737
|
-
153070, 151883, 152890, 152489, 153144, 153375, 152358, 151685,
|
|
738
|
-
152494, 152117, 152740, 151670, 198, 37448, 480, 155840, 151669,
|
|
739
|
-
151902, 152720, 153377, 152027, 152378, 152821, 153207, 153459,
|
|
740
|
-
153028, 153068, 152507, 153255, 152158, 152921, 151958, 152609,
|
|
741
|
-
152748, 152822, 152286, 151714, 152730, 152377, 152353, 152470,
|
|
742
|
-
152606, 152162, 152186, 153071, 152244, 153118, 153375, 153018,
|
|
743
|
-
152712, 153098, 152976, 152336, 151843, 153202, 152297, 151736,
|
|
744
|
-
153380, 153502, 152702, 152115, 153181, 152735, 153277, 153457,
|
|
745
|
-
152393, 153112, 152595, 151670, 198, 19098, 155808, 151669,
|
|
746
|
-
152464, 153452, 152595, 153312, 151937, 151933, 153197, 152239,
|
|
747
|
-
153163, 152922, 153402, 152034, 152591, 153438, 152215, 151673,
|
|
748
|
-
152005, 151785, 152642, 151924, 153278, 151805, 151974, 153482,
|
|
749
|
-
152718, 152862, 153347, 151670, 198, 72, 155780, 151669, 151795,
|
|
750
|
-
152111, 152746, 152377, 153471, 152309, 151670, 198, 19016,
|
|
751
|
-
155788, 151669, 153181, 152271, 152190, 152842, 152224, 152701,
|
|
752
|
-
152939, 152536, 152091, 151815, 152733, 151672, 151670, 198,
|
|
753
|
-
14689, 155788, 151669, 152291, 152072, 152942, 151734, 153042,
|
|
754
|
-
153504, 152589, 153333, 151839, 151941, 153038, 153180, 151670,
|
|
755
|
-
198, 36996, 8303, 155832, 151669, 152231, 152256, 152835,
|
|
756
|
-
152801, 152985, 153400, 152393, 152818, 152765, 152249, 152600,
|
|
757
|
-
151699, 152302, 152752, 153018, 153009, 151992, 153054, 152847,
|
|
758
|
-
153354, 153228, 152662, 153355, 152532, 153393, 151782, 152458,
|
|
759
|
-
152048, 152757, 152428, 153195, 151906, 153006, 153178, 153250,
|
|
760
|
-
152331, 152284, 152780, 153138, 153319, 151980, 153142, 152418,
|
|
761
|
-
152228, 152733, 151670, 198, 9096, 155801, 151669, 151698,
|
|
762
|
-
153321, 152217, 153039, 152935, 153400, 152122, 152531, 153106,
|
|
763
|
-
152169, 152892, 152957, 151851, 152427, 152826, 152451, 151851,
|
|
764
|
-
152901, 152885, 152594, 153446, 153080, 151670, 198, 14689,
|
|
765
|
-
155795, 151669, 152658, 151700, 153321, 152450, 152530, 153191,
|
|
766
|
-
151673, 151690, 151698, 152714, 152846, 152981, 153171, 153384,
|
|
767
|
-
153364, 153188, 153246, 151670, 198, 1055, 155779, 151669,
|
|
768
|
-
151869, 152388, 152711, 153334, 151736, 151670, 198, 1782,
|
|
769
|
-
155780, 151669, 153483, 153240, 152241, 152558, 152697, 153046,
|
|
770
|
-
151670, 198, 5804, 1363, 155820, 151669, 152941, 152764, 152605,
|
|
771
|
-
153034, 153434, 153372, 153347, 151887, 152453, 152758, 152133,
|
|
772
|
-
152510, 152694, 152431, 152321, 153088, 152676, 152223, 152581,
|
|
773
|
-
152459, 152015, 152502, 153063, 152712, 153294, 153451, 153032,
|
|
774
|
-
152903, 152859, 152989, 151748, 152669, 152661, 152650, 152409,
|
|
775
|
-
151861, 151670, 198, 300, 7973, 155828, 151669, 153095, 152469,
|
|
776
|
-
152988, 152894, 151819, 152391, 153019, 152058, 153062, 153230,
|
|
777
|
-
151826, 152112, 152306, 152264, 152769, 153390, 152384, 152435,
|
|
778
|
-
152790, 153393, 152983, 152540, 152252, 152034, 153107, 152540,
|
|
779
|
-
151919, 151893, 152558, 152817, 152946, 152956, 152129, 152715,
|
|
780
|
-
153131, 153490, 151734, 152271, 152707, 151734, 153321, 152450,
|
|
781
|
-
151670, 198, 8088, 155792, 151669, 152452, 153497, 153353,
|
|
782
|
-
152679, 152533, 152382, 152374, 152611, 153341, 153163, 152285,
|
|
783
|
-
153411, 152495, 153141, 152320, 151670, 198, 1199, 155781,
|
|
784
|
-
151669, 151764, 152360, 153295, 152634, 153342, 152199, 152271,
|
|
785
|
-
151670, 198, 43366, 155799, 151669, 152308, 151682, 152889,
|
|
786
|
-
152016, 152385, 152629, 152495, 151826, 153321, 152958, 152180,
|
|
787
|
-
151886, 153432, 152922, 152128, 153024, 153040, 152593, 152287,
|
|
788
|
-
151677, 151670, 198, 53660, 155808, 151669, 151727, 152092,
|
|
789
|
-
152680, 153331, 151699, 152316, 152938, 152289, 152433, 153384,
|
|
790
|
-
151781, 153137, 153259, 152175, 153213, 152291, 151869, 152691,
|
|
791
|
-
152489, 151941, 152049, 152034, 153053, 152179, 153160, 151676,
|
|
792
|
-
153367, 151670, 198, 268, 4123, 480, 155821, 151669, 152350,
|
|
793
|
-
152173, 152536, 151991, 151960, 153144, 153013, 152358, 152234,
|
|
794
|
-
153135, 152291, 153235, 152143, 152583, 152402, 153483, 152678,
|
|
795
|
-
152192, 152533, 152946, 151797, 153103, 152310, 152293, 151825,
|
|
796
|
-
152548, 153442, 152109, 152659, 153325, 152781, 152570, 152957,
|
|
797
|
-
151752, 152265, 153381, 152515, 151670, 198, 437, 155787,
|
|
798
|
-
151669, 152957, 152659, 151975, 152709, 152402, 152836, 152174,
|
|
799
|
-
151792, 153409, 153327, 152990, 151670, 198, 275, 155781,
|
|
800
|
-
151669, 152520, 153038, 152067, 153273, 153185, 152265, 152974,
|
|
801
|
-
151670, 198, 94273, 155799, 151669, 152953, 152938, 153427,
|
|
802
|
-
152244, 151920, 153423, 152929, 152367, 153052, 152129, 152331,
|
|
803
|
-
152257, 152987, 152777, 153448, 152408, 151696, 152408, 152326,
|
|
804
|
-
152699, 151670, 198, 385, 16239, 155828, 151669, 152306, 152268,
|
|
805
|
-
153438, 153228, 152978, 152957, 153153, 153393, 152795, 152110,
|
|
806
|
-
152918, 152923, 152467, 152331, 153053, 153330, 151889, 153444,
|
|
807
|
-
152234, 152624, 151779, 152801, 152784, 152139, 152222, 152751,
|
|
808
|
-
152512, 153287, 153141, 153052, 151840, 152589, 152508, 153499,
|
|
809
|
-
152109, 152255, 151739, 152267, 152759, 153318, 153165, 153349,
|
|
810
|
-
151670,});
|
|
811
|
-
#endif
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
// print the prompt token-by-token
|
|
815
|
-
|
|
816
|
-
LOG("\n");
|
|
817
|
-
|
|
818
|
-
for (auto id : prompt_inp) {
|
|
819
|
-
LOG("%s", common_token_to_piece(ctx_ttc, id).c_str());
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
LOG_INF("%s: prompt size: %d\n", __func__, (int) prompt_inp.size());
|
|
823
|
-
|
|
824
|
-
LOG("\n");
|
|
825
|
-
|
|
826
|
-
// create a llama_batch
|
|
827
|
-
// we use this object to submit token data for decoding
|
|
828
|
-
llama_batch batch = llama_batch_init(std::max(prompt_inp.size(), (size_t) n_parallel), 0, n_parallel);
|
|
829
|
-
|
|
830
|
-
std::vector<llama_seq_id> seq_ids(n_parallel, 0);
|
|
831
|
-
for (int32_t i = 0; i < n_parallel; ++i) {
|
|
832
|
-
seq_ids[i] = i;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
// evaluate the initial prompt
|
|
836
|
-
for (size_t i = 0; i < prompt_inp.size(); ++i) {
|
|
837
|
-
common_batch_add(batch, prompt_inp[i], i, seq_ids, false);
|
|
838
|
-
}
|
|
839
|
-
GGML_ASSERT(batch.n_tokens == (int) prompt_inp.size());
|
|
840
|
-
|
|
841
|
-
// llama_decode will output logits only for the last token of the prompt
|
|
842
|
-
batch.logits[batch.n_tokens - 1] = true;
|
|
843
|
-
|
|
844
|
-
if (llama_decode(ctx_ttc, batch) != 0) {
|
|
845
|
-
LOG_ERR("%s: llama_decode() failed\n", __func__);
|
|
846
|
-
return 1;
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
if (n_parallel > 1) {
|
|
850
|
-
LOG_INF("\n\n%s: generating %d sequences ...\n", __func__, n_parallel);
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
llama_synchronize(ctx_ttc);
|
|
854
|
-
|
|
855
|
-
LOG_INF("%s: time for prompt: %.3f ms\n\n", __func__, (ggml_time_us() - t_main_start) / 1000.0f);
|
|
856
|
-
|
|
857
|
-
const auto t_dec_start = ggml_time_us();
|
|
858
|
-
|
|
859
|
-
// main loop
|
|
860
|
-
|
|
861
|
-
// remember the batch index of the last token for each parallel sequence
|
|
862
|
-
// we need this to determine which logits to sample from
|
|
863
|
-
std::vector<int32_t> i_batch(n_parallel, batch.n_tokens - 1);
|
|
864
|
-
|
|
865
|
-
int n_past = batch.n_tokens;
|
|
866
|
-
int n_decode = 0;
|
|
867
|
-
|
|
868
|
-
bool next_token_uses_guide_token = true;
|
|
869
|
-
|
|
870
|
-
while (n_decode <= n_predict) {
|
|
871
|
-
// prepare the next batch
|
|
872
|
-
common_batch_clear(batch);
|
|
873
|
-
|
|
874
|
-
// sample the next token for each parallel sequence / stream
|
|
875
|
-
for (int32_t i = 0; i < n_parallel; ++i) {
|
|
876
|
-
if (i_batch[i] < 0) {
|
|
877
|
-
// the stream has already finished
|
|
878
|
-
continue;
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
llama_token new_token_id = common_sampler_sample(smpl[i], ctx_ttc, i_batch[i]);
|
|
882
|
-
|
|
883
|
-
//guide tokens help prevent hallucinations by forcing the TTS to use the correct word
|
|
884
|
-
if (!guide_tokens.empty() && next_token_uses_guide_token && !llama_vocab_is_control(vocab, new_token_id) && !llama_vocab_is_eog(vocab, new_token_id)) {
|
|
885
|
-
llama_token guide_token = guide_tokens[0];
|
|
886
|
-
guide_tokens.erase(guide_tokens.begin());
|
|
887
|
-
new_token_id = guide_token; //ensure correct word fragment is used
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
//this is the token id that always precedes a new word
|
|
891
|
-
next_token_uses_guide_token = (new_token_id == 198);
|
|
892
|
-
|
|
893
|
-
common_sampler_accept(smpl[i], new_token_id, true);
|
|
894
|
-
|
|
895
|
-
codes.push_back(new_token_id);
|
|
896
|
-
|
|
897
|
-
const auto * cands = common_sampler_get_candidates(smpl[i]);
|
|
898
|
-
|
|
899
|
-
// is it an end of generation? -> mark the stream as finished
|
|
900
|
-
if (llama_vocab_is_eog(vocab, new_token_id) || n_decode == n_predict) {
|
|
901
|
-
std::string reason;
|
|
902
|
-
if (llama_vocab_is_eog(vocab, new_token_id)) {
|
|
903
|
-
reason = "eos";
|
|
904
|
-
} else {
|
|
905
|
-
reason = "n_predict";
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
i_batch[i] = -1;
|
|
909
|
-
|
|
910
|
-
LOG("\n");
|
|
911
|
-
if (n_parallel > 1) {
|
|
912
|
-
LOG_CNT("\n");
|
|
913
|
-
LOG_INF("%s: stream %d finished at n_past = %d, reason = '%s'\n", __func__, i, n_past, reason.c_str());
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
continue;
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
{
|
|
920
|
-
const float p = cands->data[cands->selected].p;
|
|
921
|
-
|
|
922
|
-
const int col = std::max(0, std::min((int) k_colors.size() - 1, (int) ((3*p)*float(k_colors.size()))));
|
|
923
|
-
|
|
924
|
-
LOG_CNT("%s%d%s", k_colors[col].c_str(), i, "\033[0m");
|
|
925
|
-
//LOG_CNT("%d", i);
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
i_batch[i] = batch.n_tokens;
|
|
929
|
-
|
|
930
|
-
// push this new token for next evaluation
|
|
931
|
-
common_batch_add(batch, new_token_id, n_past, { i }, true);
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
// all streams are finished
|
|
935
|
-
if (batch.n_tokens == 0) {
|
|
936
|
-
break;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
n_decode += 1;
|
|
940
|
-
n_past += 1;
|
|
941
|
-
|
|
942
|
-
// evaluate the current batch with the transformer model
|
|
943
|
-
if (llama_decode(ctx_ttc, batch)) {
|
|
944
|
-
LOG_ERR("%s : failed to eval, return code %d\n", __func__, 1);
|
|
945
|
-
return 1;
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
llama_batch_free(batch);
|
|
950
|
-
|
|
951
|
-
LOG("\n");
|
|
952
|
-
LOG_INF("%s: time for decoder: %.3f ms\n", __func__, (ggml_time_us() - t_dec_start) / 1000.0f);
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
common_perf_print(ctx_ttc, smpl[0]);
|
|
956
|
-
|
|
957
|
-
//std::vector<llama_token> codes = {198, 88225, 155856, 151669, 152205,
|
|
958
|
-
// 153064, 152537, 153421, 153209, 152524, 151689, 152993, 152438, 152695,
|
|
959
|
-
// 153091, 152945, 152829, 152534, 152934, 153020, 151997, 152263, 153010,
|
|
960
|
-
// 153146, 152399, 153208, 152496, 151793, 152848, 152263, 152571, 153286,
|
|
961
|
-
// 152227, 153300, 152934, 152263, 153208, 152263, 152965, 152430, 152296,
|
|
962
|
-
// 153146, 152920, 152376, 152556, 153363, 151775, 152044, 152972, 152690,
|
|
963
|
-
// 153379, 152368, 152233, 153422, 152490, 151996, 152022, 151694, 152061,
|
|
964
|
-
// 153238, 152539, 153356, 152640, 153021, 153123, 151962, 153094, 151670,
|
|
965
|
-
// 198, 20339, 13189, 155824, 151669, 152070, 152007, 152910, 151683,
|
|
966
|
-
// 152000, 152373, 152760, 152046, 151735, 152334, 152394, 153073, 152908,
|
|
967
|
-
// 151856, 151953, 153247, 153293, 151903, 153480, 153168, 152478, 153359,
|
|
968
|
-
// 153429, 151905, 151678, 152567, 152411, 152165, 152556, 153075, 153424,
|
|
969
|
-
// 151993, 152999, 153078, 152151, 152088, 153389, 152484, 151874, 151670,
|
|
970
|
-
// 198, 285, 155784, 151669, 152226, 152126, 152638, 153215, 151729,
|
|
971
|
-
// 152959, 153479, 153059, 151838, 151670, 198, 1782, 155783, 151669,
|
|
972
|
-
// 153288, 153055, 153314, 152497, 152962, 152741, 152076, 153253, 151670,
|
|
973
|
-
// 198, 471, 16488, 155825, 151669, 152060, 152916, 151893, 153469, 152501,
|
|
974
|
-
// 152080, 152743, 151932, 153161, 152096, 152761, 152698, 153401, 153242,
|
|
975
|
-
// 153336, 152441, 152838, 153467, 152706, 153496, 153310, 152422, 153360,
|
|
976
|
-
// 153115, 152763, 151998, 152373, 153450, 152554, 151968, 153323, 152055,
|
|
977
|
-
// 152468, 153111, 153358, 152813, 152010, 151770, 152823, 152960, 151670,
|
|
978
|
-
// 198, 22627, 155823, 151669, 152814, 152366, 153484, 152931, 153441,
|
|
979
|
-
// 152164, 152877, 152915, 153463, 151692, 152911, 152747, 152776, 151831,
|
|
980
|
-
// 153449, 151882, 152975, 152031, 152513, 153150, 152448, 152667, 153133,
|
|
981
|
-
// 153189, 152619, 153466, 152054, 152106, 153119, 152277, 152439, 153109,
|
|
982
|
-
// 152997, 152141, 153154, 153256, 153311, 151922, 151670, 198, 1055,
|
|
983
|
-
// 155781, 151669, 152633, 151850, 153060, 153270, 152560, 153348, 152729,
|
|
984
|
-
// 151670, 198, 25312, 155803, 151669, 152521, 153403, 152561, 153337,
|
|
985
|
-
// 153383, 152199, 153493, 153326, 151830, 152254, 152248, 152349, 152153,
|
|
986
|
-
// 153007, 151823, 153037, 152575, 152457, 152406, 152592, 153116, 153365,
|
|
987
|
-
// 153456, 151670, 198, 88225, 155817, 151669, 153271, 151925, 152218,
|
|
988
|
-
// 152418, 152253, 153140, 151903, 153151, 152626, 152338, 152647, 153464,
|
|
989
|
-
// 152785, 152768, 151711, 152037, 152033, 151804, 152216, 151701, 151855,
|
|
990
|
-
// 152348, 152995, 152955, 152905, 152342, 152340, 153391, 153453, 152418,
|
|
991
|
-
// 153415, 151990, 153083, 152884, 151670, 198, 151668, 198, 151645};
|
|
992
|
-
|
|
993
|
-
{
|
|
994
|
-
const std::string inp_txt = common_detokenize(ctx_ttc, codes, true);
|
|
995
|
-
|
|
996
|
-
LOG("\n");
|
|
997
|
-
LOG_INF("codes: '%s'\n", inp_txt.c_str());
|
|
998
|
-
LOG_INF("%s: codes size: %d\n", __func__, (int) codes.size());
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
// remove all non-audio tokens (i.e. < 151672 || > 155772)
|
|
1002
|
-
codes.erase(std::remove_if(codes.begin(), codes.end(), [](llama_token t) { return t < 151672 || t > 155772; }), codes.end());
|
|
1003
|
-
|
|
1004
|
-
{
|
|
1005
|
-
const std::string inp_txt = common_detokenize(ctx_ttc, codes, true);
|
|
1006
|
-
LOG_INF("codes audio: '%s'\n", inp_txt.c_str());
|
|
1007
|
-
LOG_INF("%s: codes audio size: %d\n", __func__, (int) codes.size());
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
for (auto & token : codes) {
|
|
1011
|
-
token -= 151672;
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
const auto t_voc_start = ggml_time_us();
|
|
1015
|
-
|
|
1016
|
-
const int n_codes = codes.size();
|
|
1017
|
-
|
|
1018
|
-
llama_batch batch = llama_batch_init(n_codes, 0, 1);
|
|
1019
|
-
|
|
1020
|
-
for (size_t i = 0; i < codes.size(); ++i) {
|
|
1021
|
-
common_batch_add(batch, codes[i], i, { 0 }, true); // TODO: all logits?
|
|
1022
|
-
}
|
|
1023
|
-
GGML_ASSERT(batch.n_tokens == n_codes);
|
|
1024
|
-
|
|
1025
|
-
if (llama_encode(ctx_cts, batch) != 0) {
|
|
1026
|
-
LOG_ERR("%s: llama_encode() failed\n", __func__);
|
|
1027
|
-
return 1;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
llama_synchronize(ctx_cts);
|
|
1031
|
-
|
|
1032
|
-
LOG_INF("%s: time for vocoder: %.3f ms\n", __func__, (ggml_time_us() - t_voc_start) / 1000.0f);
|
|
1033
|
-
|
|
1034
|
-
const auto t_spec_start = ggml_time_us();
|
|
1035
|
-
|
|
1036
|
-
#if 1
|
|
1037
|
-
// spectral operations
|
|
1038
|
-
const int n_embd = llama_model_n_embd(model_cts);
|
|
1039
|
-
const float * embd = llama_get_embeddings(ctx_cts);
|
|
1040
|
-
|
|
1041
|
-
auto audio = embd_to_audio(embd, n_codes, n_embd, params.cpuparams.n_threads);
|
|
1042
|
-
|
|
1043
|
-
#else
|
|
1044
|
-
// read the spectrogram from a file for debugging purposes
|
|
1045
|
-
std::vector<float> audio;
|
|
1046
|
-
{
|
|
1047
|
-
std::ifstream fin("out.bin", std::ios::binary);
|
|
1048
|
-
if (!fin) {
|
|
1049
|
-
LOG_ERR("%s: failed to open file '%s'\n", __func__, "out.bin");
|
|
1050
|
-
return 1;
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
std::vector<float> embd;
|
|
1054
|
-
|
|
1055
|
-
int n_codes;
|
|
1056
|
-
int n_embd;
|
|
1057
|
-
|
|
1058
|
-
fin.read(reinterpret_cast<char *>(&n_codes), sizeof(int));
|
|
1059
|
-
fin.read(reinterpret_cast<char *>(&n_embd), sizeof(int));
|
|
1060
|
-
|
|
1061
|
-
embd.resize(n_codes * n_embd);
|
|
1062
|
-
fin.read(reinterpret_cast<char *>(embd.data()), n_codes * n_embd * sizeof(float));
|
|
1063
|
-
fin.close();
|
|
1064
|
-
|
|
1065
|
-
LOG_INF("%s: n_codes: %d, n_embd: %d\n", __func__, n_codes, n_embd);
|
|
1066
|
-
|
|
1067
|
-
audio = embd_to_audio(embd.data(), n_codes, n_embd, params.cpuparams.n_threads);
|
|
1068
|
-
}
|
|
1069
|
-
#endif
|
|
1070
|
-
|
|
1071
|
-
const int n_sr = 24000; // sampling rate
|
|
1072
|
-
|
|
1073
|
-
// zero out first 0.25 seconds
|
|
1074
|
-
for (int i = 0; i < 24000/4; ++i) {
|
|
1075
|
-
audio[i] = 0.0f;
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
LOG_INF("%s: time for spectral ops: %.3f ms\n", __func__, (ggml_time_us() - t_spec_start) / 1000.0f);
|
|
1079
|
-
LOG_INF("%s: total time: %.3f ms\n", __func__, (ggml_time_us() - t_main_start) / 1000.0f);
|
|
1080
|
-
|
|
1081
|
-
int retval = 0;
|
|
1082
|
-
|
|
1083
|
-
if (save_wav16(params.out_file, audio, n_sr)) {
|
|
1084
|
-
LOG_INF("%s: audio written to file '%s'\n", __func__, params.out_file.c_str());
|
|
1085
|
-
} else {
|
|
1086
|
-
retval = ENOENT;
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
llama_backend_free();
|
|
1090
|
-
|
|
1091
|
-
return retval;
|
|
1092
|
-
}
|