cactus-react-native 0.2.11 → 1.0.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/Cactus.podspec +34 -0
- package/LICENSE +38 -0
- package/README.md +550 -69
- package/android/CMakeLists.txt +40 -0
- package/android/build.gradle +68 -44
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/cactus/CactusPackage.kt +22 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusCrypto.kt +38 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusDeviceInfo.kt +24 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusFileSystem.kt +227 -0
- package/android/src/main/jniLibs/arm64-v8a/{libcactus_v8.so → libcactus.a} +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.so +0 -0
- package/cpp/HybridCactus.cpp +135 -0
- package/cpp/HybridCactus.hpp +42 -0
- package/cpp/HybridCactusUtil.cpp +47 -0
- package/cpp/HybridCactusUtil.hpp +26 -0
- package/cpp/cactus_ffi.h +55 -0
- package/cpp/cactus_util.h +25 -0
- package/ios/HybridCactusCrypto.swift +37 -0
- package/ios/HybridCactusDeviceInfo.swift +32 -0
- package/ios/HybridCactusFileSystem.swift +234 -0
- package/ios/cactus.xcframework/{info.plist → Info.plist} +2 -37
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +8 -229
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +28 -229
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +545 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ffi_utils.h +400 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +338 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +275 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel_utils.h +343 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus.h +11 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +55 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +545 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/ffi_utils.h +400 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +338 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +275 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel_utils.h +343 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/{tvos-arm64_x86_64-simulator → ios-arm64-simulator}/cactus.framework/_CodeSignature/CodeResources +1 -1
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus_util.xcframework/Info.plist +39 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/cactus_util.h +25 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/ios_utils.h +10 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/logging.h +25 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Info.plist +0 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/cactus_util +0 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/cactus_util.h +25 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/ios_utils.h +10 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/logging.h +25 -0
- package/ios/{cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework → cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework}/Info.plist +0 -0
- package/ios/{cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework → cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework}/_CodeSignature/CodeResources +36 -2
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/cactus_util +0 -0
- package/lib/module/api/Database.js +60 -0
- package/lib/module/api/Database.js.map +1 -0
- package/lib/module/classes/CactusLM.js +151 -0
- package/lib/module/classes/CactusLM.js.map +1 -0
- package/lib/module/config/CactusConfig.js +6 -0
- package/lib/module/config/CactusConfig.js.map +1 -0
- package/lib/module/constants/packageVersion.js +4 -0
- package/lib/module/constants/packageVersion.js.map +1 -0
- package/lib/module/hooks/useCactusLM.js +238 -0
- package/lib/module/hooks/useCactusLM.js.map +1 -0
- package/lib/module/index.js +9 -409
- package/lib/module/index.js.map +1 -1
- package/lib/module/native/Cactus.js +50 -0
- package/lib/module/native/Cactus.js.map +1 -0
- package/lib/module/native/CactusCrypto.js +10 -0
- package/lib/module/native/CactusCrypto.js.map +1 -0
- package/lib/module/native/CactusDeviceInfo.js +13 -0
- package/lib/module/native/CactusDeviceInfo.js.map +1 -0
- package/lib/module/native/CactusFileSystem.js +35 -0
- package/lib/module/native/CactusFileSystem.js.map +1 -0
- package/lib/module/native/CactusUtil.js +23 -0
- package/lib/module/native/CactusUtil.js.map +1 -0
- package/lib/module/native/index.js +8 -0
- package/lib/module/native/index.js.map +1 -0
- package/lib/module/specs/Cactus.nitro.js +4 -0
- package/lib/module/specs/Cactus.nitro.js.map +1 -0
- package/lib/module/specs/CactusCrypto.nitro.js +4 -0
- package/lib/module/specs/CactusCrypto.nitro.js.map +1 -0
- package/lib/module/specs/CactusDeviceInfo.nitro.js +4 -0
- package/lib/module/specs/CactusDeviceInfo.nitro.js.map +1 -0
- package/lib/module/specs/CactusFileSystem.nitro.js +4 -0
- package/lib/module/specs/CactusFileSystem.nitro.js.map +1 -0
- package/lib/module/specs/CactusUtil.nitro.js +4 -0
- package/lib/module/specs/CactusUtil.nitro.js.map +1 -0
- package/lib/module/telemetry/Telemetry.js +100 -0
- package/lib/module/telemetry/Telemetry.js.map +1 -0
- package/lib/module/types/CactusLM.js +2 -0
- package/lib/module/types/CactusLM.js.map +1 -0
- package/lib/module/types/CactusModel.js +2 -0
- package/lib/module/types/CactusModel.js.map +1 -0
- package/lib/module/utils/error.js +4 -0
- package/lib/module/utils/error.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/api/Database.d.ts +11 -0
- package/lib/typescript/src/api/Database.d.ts.map +1 -0
- package/lib/typescript/src/classes/CactusLM.d.ts +26 -0
- package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -0
- package/lib/typescript/src/config/CactusConfig.d.ts +5 -0
- package/lib/typescript/src/config/CactusConfig.d.ts.map +1 -0
- package/lib/typescript/src/constants/packageVersion.d.ts +2 -0
- package/lib/typescript/src/constants/packageVersion.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts +20 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/native/Cactus.d.ts +11 -0
- package/lib/typescript/src/native/Cactus.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusCrypto.d.ts +5 -0
- package/lib/typescript/src/native/CactusCrypto.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusDeviceInfo.d.ts +7 -0
- package/lib/typescript/src/native/CactusDeviceInfo.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusFileSystem.d.ts +13 -0
- package/lib/typescript/src/native/CactusFileSystem.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusUtil.d.ts +6 -0
- package/lib/typescript/src/native/CactusUtil.d.ts.map +1 -0
- package/lib/typescript/src/native/index.d.ts +6 -0
- package/lib/typescript/src/native/index.d.ts.map +1 -0
- package/lib/typescript/src/specs/Cactus.nitro.d.ts +13 -0
- package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts +8 -0
- package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts +16 -0
- package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts +16 -0
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts +10 -0
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts.map +1 -0
- package/lib/typescript/src/telemetry/Telemetry.d.ts +30 -0
- package/lib/typescript/src/telemetry/Telemetry.d.ts.map +1 -0
- package/lib/typescript/src/types/CactusLM.d.ts +67 -0
- package/lib/typescript/src/types/CactusLM.d.ts.map +1 -0
- package/lib/typescript/src/types/CactusModel.d.ts +12 -0
- package/lib/typescript/src/types/CactusModel.d.ts.map +1 -0
- package/lib/typescript/src/utils/error.d.ts +2 -0
- package/lib/typescript/src/utils/error.d.ts.map +1 -0
- package/nitro.json +31 -0
- package/nitrogen/generated/android/c++/JDeviceInfo.hpp +74 -0
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +74 -0
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.cpp +65 -0
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.hpp +65 -0
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.cpp +85 -0
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.cpp +192 -0
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.hpp +73 -0
- package/nitrogen/generated/android/cactus+autolinking.cmake +87 -0
- package/nitrogen/generated/android/cactus+autolinking.gradle +27 -0
- package/nitrogen/generated/android/cactusOnLoad.cpp +86 -0
- package/nitrogen/generated/android/cactusOnLoad.hpp +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/DeviceInfo.kt +50 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/Func_void_double.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusCryptoSpec.kt +58 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusDeviceInfoSpec.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusFileSystemSpec.kt +95 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/cactusOnLoad.kt +35 -0
- package/nitrogen/generated/ios/Cactus+autolinking.rb +60 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +122 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +373 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +60 -0
- package/nitrogen/generated/ios/CactusAutolinking.mm +69 -0
- package/nitrogen/generated/ios/CactusAutolinking.swift +55 -0
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.hpp +77 -0
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.hpp +88 -0
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.hpp +143 -0
- package/nitrogen/generated/ios/swift/DeviceInfo.swift +98 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_DeviceInfo.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec_cxx.swift +139 -0
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec.swift +58 -0
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec_cxx.swift +164 -0
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec.swift +65 -0
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec_cxx.swift +303 -0
- package/nitrogen/generated/shared/c++/DeviceInfo.hpp +92 -0
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.hpp +63 -0
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.hpp +66 -0
- package/package.json +84 -143
- package/src/api/Database.ts +83 -0
- package/src/classes/CactusLM.ts +205 -0
- package/src/config/CactusConfig.ts +4 -0
- package/src/constants/packageVersion.ts +1 -0
- package/src/hooks/useCactusLM.ts +285 -0
- package/src/index.tsx +23 -0
- package/src/native/Cactus.ts +83 -0
- package/src/native/CactusCrypto.ts +11 -0
- package/src/native/CactusDeviceInfo.ts +18 -0
- package/src/native/CactusFileSystem.ts +47 -0
- package/src/native/CactusUtil.ts +27 -0
- package/src/native/index.ts +5 -0
- package/src/specs/Cactus.nitro.ts +20 -0
- package/src/specs/CactusCrypto.nitro.ts +6 -0
- package/src/specs/CactusDeviceInfo.nitro.ts +15 -0
- package/src/specs/CactusFileSystem.nitro.ts +21 -0
- package/src/specs/CactusUtil.nitro.ts +8 -0
- package/src/telemetry/Telemetry.ts +159 -0
- package/src/types/CactusLM.ts +73 -0
- package/src/types/CactusModel.ts +14 -0
- package/src/utils/error.ts +2 -0
- package/LICENSE.txt +0 -20
- package/android/src/main/CMakeLists.txt +0 -140
- package/android/src/main/java/com/cactus/Cactus.java +0 -1190
- package/android/src/main/java/com/cactus/CactusPackage.java +0 -48
- package/android/src/main/java/com/cactus/LlamaContext.java +0 -748
- package/android/src/main/jni-utils.h +0 -100
- package/android/src/main/jni.cpp +0 -1605
- package/android/src/main/jniLibs/arm64-v8a/libcactus.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod_i8mm.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_i8mm.so +0 -0
- package/android/src/newarch/java/com/cactus/CactusModule.java +0 -204
- package/android/src/oldarch/java/com/cactus/CactusModule.java +0 -205
- package/cactus-react-native.podspec +0 -42
- package/ios/CMakeLists.txt +0 -131
- package/ios/Cactus.h +0 -6
- package/ios/Cactus.mm +0 -681
- package/ios/CactusContext.h +0 -81
- package/ios/CactusContext.mm +0 -1032
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/unicode.h +0 -66
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/ggml-llama.metallib +0 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +0 -232
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +0 -256
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/unicode.h +0 -66
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus.h +0 -232
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus_ffi.h +0 -256
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/unicode.h +0 -66
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/ggml-llama.metallib +0 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +0 -232
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +0 -256
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/unicode.h +0 -66
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
- package/lib/commonjs/NativeCactus.js +0 -9
- package/lib/commonjs/NativeCactus.js.map +0 -1
- package/lib/commonjs/agent.js +0 -73
- package/lib/commonjs/agent.js.map +0 -1
- package/lib/commonjs/chat.js +0 -73
- package/lib/commonjs/chat.js.map +0 -1
- package/lib/commonjs/index.js +0 -523
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/lm.js +0 -272
- package/lib/commonjs/lm.js.map +0 -1
- package/lib/commonjs/package.json +0 -1
- package/lib/commonjs/projectId.js +0 -9
- package/lib/commonjs/projectId.js.map +0 -1
- package/lib/commonjs/remote.js +0 -100
- package/lib/commonjs/remote.js.map +0 -1
- package/lib/commonjs/telemetry.js +0 -102
- package/lib/commonjs/telemetry.js.map +0 -1
- package/lib/commonjs/tools.js +0 -72
- package/lib/commonjs/tools.js.map +0 -1
- package/lib/commonjs/tts.js +0 -141
- package/lib/commonjs/tts.js.map +0 -1
- package/lib/commonjs/vlm.js +0 -221
- package/lib/commonjs/vlm.js.map +0 -1
- package/lib/module/NativeCactus.js +0 -5
- package/lib/module/NativeCactus.js.map +0 -1
- package/lib/module/agent.js +0 -68
- package/lib/module/agent.js.map +0 -1
- package/lib/module/chat.js +0 -67
- package/lib/module/chat.js.map +0 -1
- package/lib/module/lm.js +0 -267
- package/lib/module/lm.js.map +0 -1
- package/lib/module/projectId.js +0 -5
- package/lib/module/projectId.js.map +0 -1
- package/lib/module/remote.js +0 -91
- package/lib/module/remote.js.map +0 -1
- package/lib/module/telemetry.js +0 -97
- package/lib/module/telemetry.js.map +0 -1
- package/lib/module/tools.js +0 -66
- package/lib/module/tools.js.map +0 -1
- package/lib/module/tts.js +0 -135
- package/lib/module/tts.js.map +0 -1
- package/lib/module/vlm.js +0 -216
- package/lib/module/vlm.js.map +0 -1
- package/lib/typescript/NativeCactus.d.ts +0 -252
- package/lib/typescript/NativeCactus.d.ts.map +0 -1
- package/lib/typescript/agent.d.ts +0 -31
- package/lib/typescript/agent.d.ts.map +0 -1
- package/lib/typescript/chat.d.ts +0 -23
- package/lib/typescript/chat.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -114
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/lm.d.ts +0 -36
- package/lib/typescript/lm.d.ts.map +0 -1
- package/lib/typescript/projectId.d.ts +0 -2
- package/lib/typescript/projectId.d.ts.map +0 -1
- package/lib/typescript/remote.d.ts +0 -8
- package/lib/typescript/remote.d.ts.map +0 -1
- package/lib/typescript/telemetry.d.ts +0 -25
- package/lib/typescript/telemetry.d.ts.map +0 -1
- package/lib/typescript/tools.d.ts +0 -36
- package/lib/typescript/tools.d.ts.map +0 -1
- package/lib/typescript/tts.d.ts +0 -54
- package/lib/typescript/tts.d.ts.map +0 -1
- package/lib/typescript/vlm.d.ts +0 -33
- package/lib/typescript/vlm.d.ts.map +0 -1
- package/scripts/postInstall.js +0 -33
- package/src/NativeCactus.ts +0 -317
- package/src/agent.ts +0 -112
- package/src/chat.ts +0 -91
- package/src/index.ts +0 -663
- package/src/lm.ts +0 -324
- package/src/projectId.ts +0 -1
- package/src/remote.ts +0 -113
- package/src/telemetry.ts +0 -137
- package/src/tools.ts +0 -94
- package/src/tts.ts +0 -236
- package/src/vlm.ts +0 -276
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <vector>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <unordered_map>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
|
|
9
|
+
#include "../graph/graph.h"
|
|
10
|
+
extern "C" {
|
|
11
|
+
#include "../../libs/stb/stb_image.h"
|
|
12
|
+
#include "../../libs/stb/stb_image_resize2.h"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class CactusGraph;
|
|
16
|
+
|
|
17
|
+
namespace cactus {
|
|
18
|
+
namespace engine {
|
|
19
|
+
|
|
20
|
+
class Siglip2Preprocessor;
|
|
21
|
+
|
|
22
|
+
struct Config {
|
|
23
|
+
uint32_t vocab_size = 151936;
|
|
24
|
+
uint32_t bos_token_id = 151643;
|
|
25
|
+
uint32_t eos_token_id = 151645;
|
|
26
|
+
uint32_t num_layers = 28;
|
|
27
|
+
uint32_t hidden_dim = 1024;
|
|
28
|
+
uint32_t ffn_intermediate_dim = 3072;
|
|
29
|
+
uint32_t attention_heads = 16;
|
|
30
|
+
uint32_t attention_kv_heads = 8;
|
|
31
|
+
uint32_t attention_head_dim = 128;
|
|
32
|
+
float layer_norm_eps = 1e-6f;
|
|
33
|
+
float rope_theta = 1000000.0f;
|
|
34
|
+
uint32_t num_experts = 0;
|
|
35
|
+
uint32_t num_shared_experts = 0;
|
|
36
|
+
uint32_t num_top_experts = 0;
|
|
37
|
+
uint32_t moe_every_n_layers = 0;
|
|
38
|
+
bool tie_word_embeddings = true;
|
|
39
|
+
|
|
40
|
+
uint32_t vision_hidden_dim = 0;
|
|
41
|
+
uint32_t vision_num_layers = 0;
|
|
42
|
+
uint32_t vision_attention_heads = 0;
|
|
43
|
+
uint32_t vision_image_size = 0;
|
|
44
|
+
uint32_t vision_patch_size = 0;
|
|
45
|
+
uint32_t vision_num_channels = 3;
|
|
46
|
+
uint32_t vision_embed_dim = 0;
|
|
47
|
+
uint32_t visual_tokens_per_img = 0;
|
|
48
|
+
bool use_pixel_shuffle = false;
|
|
49
|
+
uint32_t pixel_shuffle_factor = 1;
|
|
50
|
+
bool use_image_tokens = false;
|
|
51
|
+
bool use_layout_tags = false;
|
|
52
|
+
uint32_t image_seq_len = 64;
|
|
53
|
+
|
|
54
|
+
uint32_t global_image_size = 2048;
|
|
55
|
+
uint32_t max_tile_size = 512;
|
|
56
|
+
float rescale_factor = 0.00392156862745098f;
|
|
57
|
+
float image_mean = 0.5f;
|
|
58
|
+
float image_std = 0.5f;
|
|
59
|
+
|
|
60
|
+
uint32_t downsample_factor = 2;
|
|
61
|
+
uint32_t min_tiles = 2;
|
|
62
|
+
uint32_t max_tiles = 10;
|
|
63
|
+
bool use_thumbnail = true;
|
|
64
|
+
uint32_t min_image_tokens = 64;
|
|
65
|
+
uint32_t max_image_tokens = 256;
|
|
66
|
+
uint32_t max_num_patches = 1024;
|
|
67
|
+
uint32_t tile_size = 512;
|
|
68
|
+
float max_pixels_tolerance = 2.0f;
|
|
69
|
+
bool do_image_splitting = true;
|
|
70
|
+
|
|
71
|
+
enum class ModelType {QWEN = 0, GEMMA = 1, SMOL = 2, NOMIC = 3, LFM2 = 5, SIGLIP2 = 6};
|
|
72
|
+
ModelType model_type = ModelType::QWEN;
|
|
73
|
+
|
|
74
|
+
enum class ModelVariant {DEFAULT = 0, VLM = 1, EXTRACT = 2, RAG = 3};
|
|
75
|
+
ModelVariant model_variant = ModelVariant::DEFAULT;
|
|
76
|
+
|
|
77
|
+
enum class Activation {GELU = 0, SILU = 1};
|
|
78
|
+
Activation activation = Activation::SILU;
|
|
79
|
+
|
|
80
|
+
enum class Backend {CPU = 0, NPU = 1};
|
|
81
|
+
Backend default_backend = Backend::CPU;
|
|
82
|
+
|
|
83
|
+
enum class Precision {INT8 = 0, FP16 = 1, FP32 = 2};
|
|
84
|
+
Precision precision = Precision::FP32;
|
|
85
|
+
|
|
86
|
+
float default_temperature = 0.6f;
|
|
87
|
+
float default_top_p = 0.95f;
|
|
88
|
+
size_t default_top_k = 20;
|
|
89
|
+
|
|
90
|
+
std::vector<std::string> layer_types;
|
|
91
|
+
size_t conv_L_cache = 0;
|
|
92
|
+
|
|
93
|
+
bool from_json(const std::string& json_path);
|
|
94
|
+
std::string to_json() const;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
struct MergeRule {
|
|
100
|
+
std::string first;
|
|
101
|
+
std::string second;
|
|
102
|
+
std::string merged;
|
|
103
|
+
uint32_t priority;
|
|
104
|
+
|
|
105
|
+
MergeRule(const std::string& f, const std::string& s, const std::string& m, uint32_t p)
|
|
106
|
+
: first(f), second(s), merged(m), priority(p) {}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
struct ChatMessage {
|
|
111
|
+
std::string role;
|
|
112
|
+
std::string content;
|
|
113
|
+
std::vector<std::string> images;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
class Tokenizer {
|
|
117
|
+
public:
|
|
118
|
+
virtual ~Tokenizer() = default;
|
|
119
|
+
|
|
120
|
+
virtual std::vector<uint32_t> encode(const std::string& text) const = 0;
|
|
121
|
+
virtual std::string decode(const std::vector<uint32_t>& tokens) const = 0;
|
|
122
|
+
|
|
123
|
+
virtual std::vector<uint32_t> apply_chat_template(const std::vector<ChatMessage>& messages, bool add_generation_prompt = true) const;
|
|
124
|
+
virtual std::string format_chat_prompt(const std::vector<ChatMessage>& messages, bool add_generation_prompt = true, const std::string& tools_json = "") const;
|
|
125
|
+
|
|
126
|
+
virtual uint32_t get_vocab_size() const = 0;
|
|
127
|
+
virtual uint32_t get_unk_token() const = 0;
|
|
128
|
+
virtual uint32_t get_bos_token() const = 0;
|
|
129
|
+
virtual uint32_t get_eos_token() const = 0;
|
|
130
|
+
virtual bool has_chat_template() const { return has_chat_template_; }
|
|
131
|
+
|
|
132
|
+
virtual bool load_vocabulary_with_config(const std::string& vocab_file, const std::string& merges_file, const std::string& config_file) = 0;
|
|
133
|
+
|
|
134
|
+
uint32_t get_image_token_id() const { return image_token_id_; }
|
|
135
|
+
uint32_t get_fake_token_id() const { return fake_token_id_; }
|
|
136
|
+
uint32_t get_global_img_token_id() const { return global_img_token_id_; }
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
void set_corpus_dir(const std::string& dir) { corpus_dir_ = dir; }
|
|
140
|
+
|
|
141
|
+
protected:
|
|
142
|
+
enum class ModelType { UNKNOWN, QWEN, GEMMA, LFM2, SMOL, BERT };
|
|
143
|
+
ModelType model_type_ = ModelType::UNKNOWN;
|
|
144
|
+
enum class ModelVariant { DEFAULT, VLM, EXTRACT, RAG};
|
|
145
|
+
ModelVariant model_variant_ = ModelVariant::DEFAULT;
|
|
146
|
+
bool has_chat_template_ = false;
|
|
147
|
+
std::string chat_template_;
|
|
148
|
+
|
|
149
|
+
uint32_t image_token_id_ = 396;
|
|
150
|
+
uint32_t fake_token_id_ = 49189;
|
|
151
|
+
uint32_t global_img_token_id_ = 49152;
|
|
152
|
+
std::string corpus_dir_;
|
|
153
|
+
|
|
154
|
+
void detect_model_type(const std::string& config_path);
|
|
155
|
+
std::string format_qwen_style(const std::vector<ChatMessage>& messages, bool add_generation_prompt, const std::string& tools_json) const;
|
|
156
|
+
std::string format_gemma_style(const std::vector<ChatMessage>& messages, bool add_generation_prompt, const std::string& tools_json) const;
|
|
157
|
+
std::string format_lfm2_style(const std::vector<ChatMessage>& messages, bool add_generation_prompt, const std::string& tools_json) const;
|
|
158
|
+
std::string format_lfm2_vl_style(const std::vector<ChatMessage>& messages, bool add_generation_prompt, const std::string& tools_json) const;
|
|
159
|
+
std::string format_smol_style(const std::vector<ChatMessage>& messages, bool add_generation_prompt, const std::string& tools_json) const;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
class BPETokenizer : public Tokenizer {
|
|
163
|
+
public:
|
|
164
|
+
BPETokenizer();
|
|
165
|
+
~BPETokenizer();
|
|
166
|
+
|
|
167
|
+
bool load_vocabulary_mmap(const std::string& vocab_file, const std::string& merges_file);
|
|
168
|
+
bool load_vocabulary_with_config(const std::string& vocab_file, const std::string& merges_file, const std::string& config_file) override;
|
|
169
|
+
|
|
170
|
+
std::vector<uint32_t> encode(const std::string& text) const override;
|
|
171
|
+
std::string decode(const std::vector<uint32_t>& tokens) const override;
|
|
172
|
+
|
|
173
|
+
uint32_t get_vocab_size() const override { return vocab_size_; }
|
|
174
|
+
uint32_t get_unk_token() const override { return unk_token_id_; }
|
|
175
|
+
uint32_t get_bos_token() const override { return bos_token_id_; }
|
|
176
|
+
uint32_t get_eos_token() const override { return eos_token_id_; }
|
|
177
|
+
|
|
178
|
+
private:
|
|
179
|
+
std::unordered_map<std::string, uint32_t> token_to_id_;
|
|
180
|
+
std::vector<std::string> id_to_token_;
|
|
181
|
+
std::vector<MergeRule> merge_rules_;
|
|
182
|
+
std::unordered_map<std::string, uint32_t> merge_map_;
|
|
183
|
+
|
|
184
|
+
uint32_t vocab_size_;
|
|
185
|
+
uint32_t unk_token_id_;
|
|
186
|
+
uint32_t bos_token_id_;
|
|
187
|
+
uint32_t eos_token_id_;
|
|
188
|
+
|
|
189
|
+
void* vocab_mmap_ptr_;
|
|
190
|
+
size_t vocab_mmap_size_;
|
|
191
|
+
|
|
192
|
+
void* merges_mmap_ptr_;
|
|
193
|
+
size_t merges_mmap_size_;
|
|
194
|
+
|
|
195
|
+
std::vector<std::string> apply_bpe(const std::vector<std::string>& tokens) const;
|
|
196
|
+
std::pair<int, uint32_t> find_best_merge_fast(const std::vector<std::string>& tokens) const;
|
|
197
|
+
|
|
198
|
+
std::string bytes_to_unicode(const std::string& text) const;
|
|
199
|
+
std::string unicode_to_bytes(const std::string& text) const;
|
|
200
|
+
std::vector<std::string> byte_level_split(const std::string& text) const;
|
|
201
|
+
|
|
202
|
+
void cleanup_mmap();
|
|
203
|
+
|
|
204
|
+
private:
|
|
205
|
+
mutable std::unordered_map<uint8_t, std::string> byte_to_unicode_;
|
|
206
|
+
mutable std::unordered_map<std::string, uint8_t> unicode_to_byte_;
|
|
207
|
+
void init_byte_mappings() const;
|
|
208
|
+
|
|
209
|
+
std::unordered_map<std::string, uint32_t> special_tokens_;
|
|
210
|
+
std::vector<std::string> split_with_special_tokens(const std::string& text) const;
|
|
211
|
+
void load_special_tokens(const std::string& config_file);
|
|
212
|
+
|
|
213
|
+
void load_chat_template(const std::string& template_file);
|
|
214
|
+
|
|
215
|
+
std::unordered_map<std::string, uint32_t> tool_tokens_;
|
|
216
|
+
bool has_tool_support_;
|
|
217
|
+
void load_tokenizer_config(const std::string& config_file);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
class SPTokenizer : public Tokenizer {
|
|
221
|
+
public:
|
|
222
|
+
SPTokenizer();
|
|
223
|
+
~SPTokenizer();
|
|
224
|
+
|
|
225
|
+
bool load_vocabulary_with_config(const std::string& vocab_file, const std::string& merges_file, const std::string& config_file) override;
|
|
226
|
+
|
|
227
|
+
std::vector<uint32_t> encode(const std::string& text) const override;
|
|
228
|
+
std::string decode(const std::vector<uint32_t>& tokens) const override;
|
|
229
|
+
|
|
230
|
+
uint32_t get_vocab_size() const override { return vocab_size_; }
|
|
231
|
+
uint32_t get_unk_token() const override { return unk_token_id_; }
|
|
232
|
+
uint32_t get_bos_token() const override { return bos_token_id_; }
|
|
233
|
+
uint32_t get_eos_token() const override { return eos_token_id_; }
|
|
234
|
+
|
|
235
|
+
private:
|
|
236
|
+
struct TrieNode {
|
|
237
|
+
std::unordered_map<char32_t, std::unique_ptr<TrieNode>> children;
|
|
238
|
+
int32_t token_id = -1;
|
|
239
|
+
float score = 0.0f;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
std::unique_ptr<TrieNode> trie_root_;
|
|
243
|
+
std::unordered_map<std::string, uint32_t> token_to_id_;
|
|
244
|
+
std::vector<std::string> id_to_token_;
|
|
245
|
+
std::vector<float> token_scores_;
|
|
246
|
+
|
|
247
|
+
uint32_t vocab_size_;
|
|
248
|
+
uint32_t unk_token_id_;
|
|
249
|
+
uint32_t bos_token_id_;
|
|
250
|
+
uint32_t eos_token_id_;
|
|
251
|
+
uint32_t pad_token_id_;
|
|
252
|
+
|
|
253
|
+
void* vocab_mmap_ptr_;
|
|
254
|
+
size_t vocab_mmap_size_;
|
|
255
|
+
|
|
256
|
+
void build_trie();
|
|
257
|
+
std::vector<std::pair<std::string, uint32_t>> tokenize_with_trie(const std::string& text) const;
|
|
258
|
+
std::string preprocess_text(const std::string& text) const;
|
|
259
|
+
std::string postprocess_text(const std::string& text) const;
|
|
260
|
+
std::vector<std::string> split_by_unicode_spaces(const std::string& text) const;
|
|
261
|
+
|
|
262
|
+
void cleanup_mmap();
|
|
263
|
+
|
|
264
|
+
std::unordered_map<std::string, uint32_t> special_tokens_;
|
|
265
|
+
std::vector<std::string> split_with_special_tokens(const std::string& text) const;
|
|
266
|
+
void load_special_tokens(const std::string& config_file);
|
|
267
|
+
|
|
268
|
+
void load_chat_template(const std::string& template_file);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
class ConvCache {
|
|
272
|
+
public:
|
|
273
|
+
struct CircularView {
|
|
274
|
+
const void* ptr1;
|
|
275
|
+
size_t len1;
|
|
276
|
+
const void* ptr2;
|
|
277
|
+
size_t len2;
|
|
278
|
+
size_t total_len;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
void init(size_t layers, size_t hidden_dim, size_t window_len, Precision model_precision);
|
|
282
|
+
CircularView get_window(size_t layer) const;
|
|
283
|
+
void update(CactusGraph* gb, size_t layer, const size_t latest_token);
|
|
284
|
+
void reset();
|
|
285
|
+
|
|
286
|
+
bool is_empty() const { return num_layers == 0; }
|
|
287
|
+
|
|
288
|
+
size_t num_layers = 0;
|
|
289
|
+
size_t hidden_size = 0;
|
|
290
|
+
size_t window_size = 0;
|
|
291
|
+
Precision precision = Precision::FP32;
|
|
292
|
+
size_t element_size = 4;
|
|
293
|
+
|
|
294
|
+
private:
|
|
295
|
+
struct LayerState {
|
|
296
|
+
std::vector<uint8_t> data;
|
|
297
|
+
size_t head = 0;
|
|
298
|
+
size_t count = 0;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
std::vector<LayerState> layer_states;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
struct KVCache {
|
|
305
|
+
static constexpr size_t DEFAULT_WINDOW_SIZE = 512;
|
|
306
|
+
static constexpr size_t DEFAULT_SINK_SIZE = 4;
|
|
307
|
+
|
|
308
|
+
struct LayerCache {
|
|
309
|
+
std::vector<uint8_t> keys;
|
|
310
|
+
std::vector<uint8_t> values;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
std::vector<LayerCache> layer_caches;
|
|
314
|
+
|
|
315
|
+
size_t window_size = DEFAULT_WINDOW_SIZE;
|
|
316
|
+
size_t sink_size = DEFAULT_SINK_SIZE;
|
|
317
|
+
size_t current_seq_len = 0;
|
|
318
|
+
size_t total_seq_len = 0;
|
|
319
|
+
size_t max_seq_len = 2048;
|
|
320
|
+
size_t num_kv_heads = 0;
|
|
321
|
+
size_t head_dim = 0;
|
|
322
|
+
size_t num_layers = 0;
|
|
323
|
+
Precision precision;
|
|
324
|
+
size_t element_size = 4;
|
|
325
|
+
|
|
326
|
+
void set_window_size(size_t window, size_t sink = DEFAULT_SINK_SIZE);
|
|
327
|
+
size_t get_effective_seq_len() const { return current_seq_len; }
|
|
328
|
+
size_t get_total_seq_len() const { return total_seq_len; }
|
|
329
|
+
|
|
330
|
+
void init(size_t num_layers, size_t max_seq, size_t num_kv_heads, size_t head_dim, Precision model_precision);
|
|
331
|
+
void reset();
|
|
332
|
+
void update_from_graph(CactusGraph* gb, const std::vector<size_t>& k_nodes,
|
|
333
|
+
const std::vector<size_t>& v_nodes, size_t seq_len,
|
|
334
|
+
size_t num_layers, size_t kv_heads, size_t head_dim);
|
|
335
|
+
bool is_empty() const { return current_seq_len == 0; }
|
|
336
|
+
void* get_key_ptr(size_t layer);
|
|
337
|
+
void* get_value_ptr(size_t layer);
|
|
338
|
+
|
|
339
|
+
struct CircularView {
|
|
340
|
+
const void* ptr1;
|
|
341
|
+
const void* ptr2;
|
|
342
|
+
size_t len1;
|
|
343
|
+
size_t len2;
|
|
344
|
+
size_t total_len;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
CircularView get_key_view(size_t layer);
|
|
348
|
+
CircularView get_value_view(size_t layer);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
class Model {
|
|
352
|
+
public:
|
|
353
|
+
struct DebugNode {
|
|
354
|
+
uint32_t layer_idx;
|
|
355
|
+
std::string name;
|
|
356
|
+
size_t node_id;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
Model();
|
|
360
|
+
explicit Model(const Config& config);
|
|
361
|
+
virtual ~Model();
|
|
362
|
+
|
|
363
|
+
const Config& get_config() const { return config_; }
|
|
364
|
+
Tokenizer* get_tokenizer() const { return tokenizer_.get(); }
|
|
365
|
+
const std::vector<DebugNode>& get_debug_nodes() const;
|
|
366
|
+
|
|
367
|
+
virtual bool init(const std::string& model_folder, size_t context_size, const std::string& system_prompt = "", bool do_warmup = true);
|
|
368
|
+
virtual bool init(CactusGraph* external_graph, const std::string& model_folder, size_t context_size,
|
|
369
|
+
const std::string& system_prompt = "", bool do_warmup = true);
|
|
370
|
+
virtual uint32_t generate(const std::vector<uint32_t>& tokens, float temperature = -1.0f, float top_p = -1.0f,
|
|
371
|
+
size_t top_k = 0, const std::string& profile_file = "");
|
|
372
|
+
|
|
373
|
+
virtual uint32_t generate_with_images(const std::vector<uint32_t>& tokens, const std::vector<std::string>& image_paths,
|
|
374
|
+
float temperature = -1.0f, float top_p = -1.0f,
|
|
375
|
+
size_t top_k = 0, const std::string& profile_file = "");
|
|
376
|
+
|
|
377
|
+
std::vector<float> get_embeddings(const std::vector<uint32_t>& tokens, bool pooled = true, const std::string& profile_file = "");
|
|
378
|
+
|
|
379
|
+
virtual void reset_cache() { kv_cache_.reset(); }
|
|
380
|
+
void set_cache_window(size_t window_size, size_t sink_size = 4) { kv_cache_.set_window_size(window_size, sink_size); }
|
|
381
|
+
|
|
382
|
+
void* graph_handle_;
|
|
383
|
+
|
|
384
|
+
protected:
|
|
385
|
+
virtual size_t forward(const std::vector<uint32_t>& tokens, bool use_cache = false) = 0;
|
|
386
|
+
virtual void load_weights_to_graph(CactusGraph* gb) = 0;
|
|
387
|
+
virtual size_t build_attention(CactusGraph* gb, size_t normalized_input, uint32_t layer_idx,
|
|
388
|
+
ComputeBackend backend, bool use_cache = false, size_t position_offset = 0) = 0;
|
|
389
|
+
virtual size_t build_mlp(CactusGraph* gb, size_t normalized_h, uint32_t layer_idx,
|
|
390
|
+
ComputeBackend backend) const = 0;
|
|
391
|
+
virtual size_t build_transformer_block(CactusGraph* gb, size_t hidden, uint32_t layer_idx,
|
|
392
|
+
ComputeBackend backend, bool use_cache = false, size_t position_offset = 0) = 0;
|
|
393
|
+
void update_kv_cache(CactusGraph* gb, size_t seq_len);
|
|
394
|
+
virtual void post_init() {}
|
|
395
|
+
virtual void post_execute_updates(CactusGraph*, size_t) {}
|
|
396
|
+
Config config_;
|
|
397
|
+
std::unique_ptr<Tokenizer> tokenizer_;
|
|
398
|
+
|
|
399
|
+
bool initialized_;
|
|
400
|
+
float attention_scale_;
|
|
401
|
+
|
|
402
|
+
protected:
|
|
403
|
+
KVCache kv_cache_;
|
|
404
|
+
std::vector<size_t> cache_k_output_nodes_;
|
|
405
|
+
std::vector<size_t> cache_v_output_nodes_;
|
|
406
|
+
|
|
407
|
+
std::string embedding_file_path_;
|
|
408
|
+
size_t embedding_node_id_;
|
|
409
|
+
std::string model_folder_path_;
|
|
410
|
+
size_t output_weight_node_id_;
|
|
411
|
+
|
|
412
|
+
mutable std::vector<DebugNode> debug_nodes_;
|
|
413
|
+
|
|
414
|
+
void capture_debug_node(uint32_t layer_idx, const std::string& name, size_t node_id) const;
|
|
415
|
+
void clear_debug_nodes();
|
|
416
|
+
|
|
417
|
+
bool init_internal(CactusGraph* gb, const std::string& model_folder, size_t context_size,
|
|
418
|
+
const std::string& system_prompt, bool do_warmup);
|
|
419
|
+
bool owns_graph_;
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
std::unique_ptr<Model> create_model(const std::string& model_folder);
|
|
423
|
+
|
|
424
|
+
class Siglip2Preprocessor {
|
|
425
|
+
public:
|
|
426
|
+
struct Config {
|
|
427
|
+
int patch_size = 16;
|
|
428
|
+
int downsample_factor = 2;
|
|
429
|
+
int min_tiles = 2;
|
|
430
|
+
int max_tiles = 10;
|
|
431
|
+
bool use_thumbnail = true;
|
|
432
|
+
int min_image_tokens = 64;
|
|
433
|
+
int max_image_tokens = 256;
|
|
434
|
+
int max_num_patches = 1024;
|
|
435
|
+
int tile_size = 512;
|
|
436
|
+
float max_pixels_tolerance = 2.0f;
|
|
437
|
+
bool do_resize = true;
|
|
438
|
+
bool do_rescale = true;
|
|
439
|
+
bool do_normalize = true;
|
|
440
|
+
bool do_convert_rgb = true;
|
|
441
|
+
bool do_image_splitting = true;
|
|
442
|
+
float rescale_factor = 1.0f / 255.0f;
|
|
443
|
+
float image_mean[3] = {0.5f, 0.5f, 0.5f};
|
|
444
|
+
float image_std[3] = {0.5f, 0.5f, 0.5f};
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
struct PreprocessedImage {
|
|
448
|
+
std::vector<float> pixel_values;
|
|
449
|
+
std::vector<int> pixel_attention_mask;
|
|
450
|
+
std::vector<std::pair<int,int>> spatial_shapes;
|
|
451
|
+
std::vector<size_t> pixel_values_shape;
|
|
452
|
+
std::vector<size_t> pixel_attention_mask_shape;
|
|
453
|
+
std::vector<size_t> spatial_shapes_shape;
|
|
454
|
+
int num_patches_height;
|
|
455
|
+
int num_patches_width;
|
|
456
|
+
int actual_num_patches;
|
|
457
|
+
int num_tiles;
|
|
458
|
+
int patch_dim;
|
|
459
|
+
int max_patches_per_tile;
|
|
460
|
+
|
|
461
|
+
int image_rows;
|
|
462
|
+
int image_cols;
|
|
463
|
+
int image_height;
|
|
464
|
+
int image_width;
|
|
465
|
+
int tokens_per_tile;
|
|
466
|
+
int thumbnail_tokens;
|
|
467
|
+
|
|
468
|
+
~PreprocessedImage();
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
struct SpatialShapeResult {
|
|
472
|
+
std::vector<std::pair<int, int>> shapes;
|
|
473
|
+
int grid_rows;
|
|
474
|
+
int grid_cols;
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
explicit Siglip2Preprocessor(const Config& config);
|
|
478
|
+
Siglip2Preprocessor();
|
|
479
|
+
~Siglip2Preprocessor();
|
|
480
|
+
|
|
481
|
+
PreprocessedImage preprocess_from_file(const std::string& image_path);
|
|
482
|
+
PreprocessedImage preprocess_from_memory(const unsigned char* img_data, int width, int height, int channels);
|
|
483
|
+
SpatialShapeResult compute_spatial_shapes(int height, int width);
|
|
484
|
+
|
|
485
|
+
private:
|
|
486
|
+
Config config_;
|
|
487
|
+
|
|
488
|
+
std::vector<unsigned char> convert_to_rgb(const unsigned char* img_data, int width, int height, int channels);
|
|
489
|
+
std::pair<int, int> smart_resize(int height, int width);
|
|
490
|
+
bool is_image_too_large(int height, int width);
|
|
491
|
+
std::pair<int, int> get_grid_layout(int height, int width);
|
|
492
|
+
std::pair<int, int> find_closest_aspect_ratio(float aspect_ratio, int width, int height);
|
|
493
|
+
std::vector<float> resize_image(const unsigned char* img_data, int src_width, int src_height,
|
|
494
|
+
int dst_width, int dst_height, int channels);
|
|
495
|
+
std::vector<float> normalize_image(const float* img_data, int width, int height, int channels);
|
|
496
|
+
std::vector<std::vector<float>> convert_image_to_patches(
|
|
497
|
+
const std::vector<float>& image, int width, int height, int channels, int patch_size);
|
|
498
|
+
PreprocessedImage pad_patches(const std::vector<std::vector<float>>& tile_patches,
|
|
499
|
+
const std::vector<std::pair<int,int>>& spatial_shapes,
|
|
500
|
+
int patch_dim,
|
|
501
|
+
int max_patches_per_tile);
|
|
502
|
+
int round_by_factor(int number, int factor);
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
class AudioProcessor {
|
|
506
|
+
public:
|
|
507
|
+
struct SpectrogramConfig {
|
|
508
|
+
size_t n_fft = 400;
|
|
509
|
+
size_t hop_length = 160;
|
|
510
|
+
size_t frame_length = 400;
|
|
511
|
+
float power = 2.0f;
|
|
512
|
+
bool center = true;
|
|
513
|
+
const char* pad_mode = "reflect";
|
|
514
|
+
bool onesided = true;
|
|
515
|
+
float dither = 0.0f;
|
|
516
|
+
float mel_floor = 1e-10f;
|
|
517
|
+
const char* log_mel = nullptr;
|
|
518
|
+
float reference = 1.0f;
|
|
519
|
+
float min_value = 1e-10f;
|
|
520
|
+
bool remove_dc_offset = false;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
AudioProcessor();
|
|
524
|
+
~AudioProcessor();
|
|
525
|
+
|
|
526
|
+
void init_mel_filters(size_t num_frequency_bins, size_t num_mel_filters,
|
|
527
|
+
float min_freq, float max_freq, size_t sampling_rate);
|
|
528
|
+
|
|
529
|
+
std::vector<float> compute_spectrogram(
|
|
530
|
+
const std::vector<float>& waveform,
|
|
531
|
+
const SpectrogramConfig& config);
|
|
532
|
+
|
|
533
|
+
const std::vector<float>& get_mel_filters() const { return mel_filters_; }
|
|
534
|
+
|
|
535
|
+
size_t get_num_mel_filters() const { return num_mel_filters_; }
|
|
536
|
+
size_t get_num_frequency_bins() const { return num_frequency_bins_; }
|
|
537
|
+
|
|
538
|
+
private:
|
|
539
|
+
std::vector<float> mel_filters_;
|
|
540
|
+
size_t num_frequency_bins_;
|
|
541
|
+
size_t num_mel_filters_;
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
}
|
|
545
|
+
}
|