react-native-executorch 0.5.6 → 0.5.7

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.
Files changed (139) hide show
  1. package/android/libs/classes.jar +0 -0
  2. package/android/src/main/cpp/CMakeLists.txt +23 -14
  3. package/common/rnexecutorch/RnExecutorchInstaller.cpp +4 -21
  4. package/common/rnexecutorch/host_objects/ModelHostObject.h +67 -51
  5. package/common/rnexecutorch/models/llm/LLM.cpp +24 -1
  6. package/common/rnexecutorch/models/llm/LLM.h +4 -1
  7. package/common/rnexecutorch/threads/GlobalThreadPool.h +79 -0
  8. package/common/rnexecutorch/threads/HighPerformanceThreadPool.h +364 -0
  9. package/common/rnexecutorch/threads/utils/ThreadUtils.h +29 -0
  10. package/common/runner/runner.cpp +9 -3
  11. package/common/runner/runner.h +4 -3
  12. package/common/runner/text_token_generator.h +28 -10
  13. package/lib/module/controllers/LLMController.js +21 -2
  14. package/lib/module/controllers/LLMController.js.map +1 -1
  15. package/lib/module/hooks/natural_language_processing/useLLM.js +6 -2
  16. package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
  17. package/lib/module/modules/natural_language_processing/LLMModule.js +4 -2
  18. package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
  19. package/lib/module/types/llm.js.map +1 -1
  20. package/lib/typescript/controllers/LLMController.d.ts +4 -2
  21. package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
  22. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
  23. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +3 -2
  24. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
  25. package/lib/typescript/types/llm.d.ts +7 -1
  26. package/lib/typescript/types/llm.d.ts.map +1 -1
  27. package/package.json +3 -1
  28. package/react-native-executorch.podspec +12 -31
  29. package/src/controllers/LLMController.ts +29 -5
  30. package/src/hooks/natural_language_processing/useLLM.ts +15 -1
  31. package/src/modules/natural_language_processing/LLMModule.ts +10 -2
  32. package/src/types/llm.ts +8 -0
  33. package/third-party/android/libs/cpuinfo/arm64-v8a/libcpuinfo.so +0 -0
  34. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  35. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  36. package/third-party/android/libs/pthreadpool/arm64-v8a/libpthreadpool.so +0 -0
  37. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libsentencepiece.a +0 -0
  38. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_c.a +0 -0
  39. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_cpp.a +0 -0
  40. package/third-party/android/libs/tokenizers-cpp/x86_64/libsentencepiece.a +0 -0
  41. package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_c.a +0 -0
  42. package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_cpp.a +0 -0
  43. package/third-party/include/c10/macros/Export.h +2 -86
  44. package/third-party/include/c10/macros/Macros.h +28 -5
  45. package/third-party/include/c10/util/BFloat16-inl.h +1 -4
  46. package/third-party/include/c10/util/BFloat16.h +5 -8
  47. package/third-party/include/c10/util/Half.h +5 -0
  48. package/third-party/include/c10/util/bit_cast.h +1 -1
  49. package/third-party/include/c10/util/complex.h +639 -0
  50. package/third-party/include/c10/util/complex_math.h +399 -0
  51. package/third-party/include/c10/util/complex_utils.h +41 -0
  52. package/third-party/include/c10/util/irange.h +2 -2
  53. package/third-party/include/c10/util/overflows.h +95 -0
  54. package/third-party/include/executorch/ExecuTorchError.h +75 -0
  55. package/third-party/include/executorch/ExecuTorchModule.h +115 -11
  56. package/third-party/include/executorch/ExecuTorchTensor.h +731 -51
  57. package/third-party/include/executorch/ExecuTorchValue.h +61 -9
  58. package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +181 -0
  59. package/third-party/include/executorch/extension/kernel_util/meta_programming.h +108 -0
  60. package/third-party/include/executorch/extension/kernel_util/type_list.h +137 -0
  61. package/third-party/include/executorch/extension/module/bundled_module.h +131 -0
  62. package/third-party/include/executorch/extension/module/module.h +46 -20
  63. package/third-party/include/executorch/extension/threadpool/cpuinfo_utils.h +1 -3
  64. package/third-party/include/executorch/extension/threadpool/threadpool.h +1 -3
  65. package/third-party/include/executorch/extension/threadpool/threadpool_guard.h +35 -0
  66. package/third-party/include/executorch/runtime/backend/backend_execution_context.h +3 -3
  67. package/third-party/include/executorch/runtime/backend/backend_init_context.h +12 -6
  68. package/third-party/include/executorch/runtime/backend/backend_option_context.h +34 -0
  69. package/third-party/include/executorch/runtime/backend/interface.h +70 -9
  70. package/third-party/include/executorch/runtime/backend/options.h +206 -0
  71. package/third-party/include/executorch/runtime/core/evalue.h +19 -25
  72. package/third-party/include/executorch/runtime/core/event_tracer.h +32 -17
  73. package/third-party/include/executorch/runtime/core/event_tracer_hooks.h +23 -14
  74. package/third-party/include/executorch/runtime/core/exec_aten/exec_aten.h +32 -9
  75. package/third-party/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +3 -2
  76. package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +43 -75
  77. package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_util.h +88 -87
  78. package/third-party/include/executorch/runtime/core/function_ref.h +100 -0
  79. package/third-party/include/executorch/runtime/core/named_data_map.h +14 -14
  80. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +2 -86
  81. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +28 -5
  82. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -4
  83. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +5 -8
  84. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +5 -0
  85. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -1
  86. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +639 -0
  87. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_math.h +399 -0
  88. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_utils.h +41 -0
  89. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +2 -2
  90. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/overflows.h +95 -0
  91. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +88 -0
  92. package/third-party/include/executorch/runtime/core/portable_type/complex.h +6 -29
  93. package/third-party/include/executorch/runtime/core/portable_type/tensor_impl.h +20 -0
  94. package/third-party/include/executorch/runtime/core/span.h +4 -0
  95. package/third-party/include/executorch/runtime/core/tag.h +19 -0
  96. package/third-party/include/executorch/runtime/core/tensor_layout.h +2 -2
  97. package/third-party/include/executorch/runtime/executor/method.h +15 -3
  98. package/third-party/include/executorch/runtime/executor/method_meta.h +34 -5
  99. package/third-party/include/executorch/runtime/executor/program.h +3 -4
  100. package/third-party/include/executorch/runtime/executor/pte_data_map.h +9 -8
  101. package/third-party/include/executorch/runtime/executor/tensor_parser.h +14 -13
  102. package/third-party/include/executorch/runtime/kernel/kernel_runtime_context.h +5 -5
  103. package/third-party/include/executorch/runtime/kernel/operator_registry.h +21 -19
  104. package/third-party/include/executorch/runtime/platform/compiler.h +8 -0
  105. package/third-party/include/executorch/runtime/platform/platform.h +126 -0
  106. package/third-party/include/headeronly/macros/Export.h +88 -0
  107. package/third-party/include/tokenizers-cpp/tokenizers_c.h +61 -0
  108. package/third-party/include/torch/headeronly/macros/Export.h +88 -0
  109. package/third-party/ios/ExecutorchLib.xcframework/Info.plist +43 -0
  110. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  111. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
  112. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  113. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
  114. package/third-party/ios/libs/cpuinfo/libcpuinfo.a +0 -0
  115. package/third-party/ios/libs/pthreadpool/physical-arm64-release/libpthreadpool.a +0 -0
  116. package/third-party/ios/libs/pthreadpool/simulator-arm64-debug/libpthreadpool.a +0 -0
  117. package/ios/libs/executorch/libbackend_coreml_ios.a +0 -0
  118. package/ios/libs/executorch/libbackend_coreml_simulator.a +0 -0
  119. package/ios/libs/executorch/libbackend_mps_ios.a +0 -0
  120. package/ios/libs/executorch/libbackend_mps_simulator.a +0 -0
  121. package/ios/libs/executorch/libbackend_xnnpack_ios.a +0 -0
  122. package/ios/libs/executorch/libbackend_xnnpack_simulator.a +0 -0
  123. package/ios/libs/executorch/libexecutorch_ios.a +0 -0
  124. package/ios/libs/executorch/libexecutorch_simulator.a +0 -0
  125. package/ios/libs/executorch/libkernels_custom_ios.a +0 -0
  126. package/ios/libs/executorch/libkernels_custom_simulator.a +0 -0
  127. package/ios/libs/executorch/libkernels_optimized_ios.a +0 -0
  128. package/ios/libs/executorch/libkernels_optimized_simulator.a +0 -0
  129. package/ios/libs/executorch/libkernels_portable_ios.a +0 -0
  130. package/ios/libs/executorch/libkernels_portable_simulator.a +0 -0
  131. package/ios/libs/executorch/libkernels_quantized_ios.a +0 -0
  132. package/ios/libs/executorch/libkernels_quantized_simulator.a +0 -0
  133. package/third-party/ios/ios.toolchain.cmake +0 -1122
  134. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libsentencepiece.a +0 -0
  135. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_c.a +0 -0
  136. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_cpp.a +0 -0
  137. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libsentencepiece.a +0 -0
  138. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_c.a +0 -0
  139. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_cpp.a +0 -0
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useEffect","useMemo","useState","LLMController","useLLM","model","preventLoad","token","setToken","response","setResponse","messageHistory","setMessageHistory","isReady","setIsReady","isGenerating","setIsGenerating","downloadProgress","setDownloadProgress","error","setError","tokenCallback","newToken","prevResponse","controllerInstance","messageHistoryCallback","isReadyCallback","isGeneratingCallback","load","modelSource","tokenizerSource","tokenizerConfigSource","onDownloadProgressCallback","e","delete","configure","chatConfig","toolsConfig","generate","messages","tools","sendMessage","message","deleteMessage","index","interrupt"],"sourceRoot":"../../../../src","sources":["hooks/natural_language_processing/useLLM.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AASjE,SAASC,aAAa,QAAQ,iCAAiC;;AAE/D;AACA;AACA;AACA,OAAO,MAAMC,MAAM,GAAGA,CAAC;EACrBC,KAAK;EACLC,WAAW,GAAG;AAQhB,CAAC,KAAc;EACb,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGN,QAAQ,CAAS,EAAE,CAAC;EAC9C,MAAM,CAACO,QAAQ,EAAEC,WAAW,CAAC,GAAGR,QAAQ,CAAS,EAAE,CAAC;EACpD,MAAM,CAACS,cAAc,EAAEC,iBAAiB,CAAC,GAAGV,QAAQ,CAAY,EAAE,CAAC;EACnE,MAAM,CAACW,OAAO,EAAEC,UAAU,CAAC,GAAGZ,QAAQ,CAAC,KAAK,CAAC;EAC7C,MAAM,CAACa,YAAY,EAAEC,eAAe,CAAC,GAAGd,QAAQ,CAAC,KAAK,CAAC;EACvD,MAAM,CAACe,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGhB,QAAQ,CAAC,CAAC,CAAC;EAC3D,MAAM,CAACiB,KAAK,EAAEC,QAAQ,CAAC,GAAGl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C,UAAU;IAAEC;EAAY,CAAC,CAAC,EAC/D,CAACb,kBAAkB,CACrB,CAAC;EAED,MAAMc,QAAQ,GAAGvC,WAAW,CAC1B,CAACwC,QAAmB,EAAEC,KAAiB,KAAK;IAC1C9B,WAAW,CAAC,EAAE,CAAC;IACf,OAAOc,kBAAkB,CAACc,QAAQ,CAACC,QAAQ,EAAEC,KAAK,CAAC;EACrD,CAAC,EACD,CAAChB,kBAAkB,CACrB,CAAC;EAED,MAAMiB,WAAW,GAAG1C,WAAW,CAC5B2C,OAAe,IAAK;IACnBhC,WAAW,CAAC,EAAE,CAAC;IACf,OAAOc,kBAAkB,CAACiB,WAAW,CAACC,OAAO,CAAC;EAChD,CAAC,EACD,CAAClB,kBAAkB,CACrB,CAAC;EAED,MAAMmB,aAAa,GAAG5C,WAAW,CAC9B6C,KAAa,IAAKpB,kBAAkB,CAACmB,aAAa,CAACC,KAAK,CAAC,EAC1D,CAACpB,kBAAkB,CACrB,CAAC;EAED,MAAMqB,SAAS,GAAG9C,WAAW,CAC3B,MAAMyB,kBAAkB,CAACqB,SAAS,CAAC,CAAC,EACpC,CAACrB,kBAAkB,CACrB,CAAC;EAED,OAAO;IACLb,cAAc;IACdF,QAAQ;IACRF,KAAK;IACLM,OAAO;IACPE,YAAY;IACZE,gBAAgB;IAChBE,KAAK;IACLgB,SAAS,EAAEA,SAAS;IACpBG,QAAQ,EAAEA,QAAQ;IAClBG,WAAW,EAAEA,WAAW;IACxBE,aAAa,EAAEA,aAAa;IAC5BE,SAAS,EAAEA;EACb,CAAC;AACH,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["useCallback","useEffect","useMemo","useState","LLMController","useLLM","model","preventLoad","token","setToken","response","setResponse","messageHistory","setMessageHistory","isReady","setIsReady","isGenerating","setIsGenerating","downloadProgress","setDownloadProgress","error","setError","tokenCallback","newToken","prevResponse","controllerInstance","messageHistoryCallback","isReadyCallback","isGeneratingCallback","load","modelSource","tokenizerSource","tokenizerConfigSource","onDownloadProgressCallback","e","delete","configure","chatConfig","toolsConfig","generationConfig","generate","messages","tools","sendMessage","message","deleteMessage","index","interrupt","getGeneratedTokenCount"],"sourceRoot":"../../../../src","sources":["hooks/natural_language_processing/useLLM.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAUjE,SAASC,aAAa,QAAQ,iCAAiC;;AAE/D;AACA;AACA;AACA,OAAO,MAAMC,MAAM,GAAGA,CAAC;EACrBC,KAAK;EACLC,WAAW,GAAG;AAQhB,CAAC,KAAc;EACb,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGN,QAAQ,CAAS,EAAE,CAAC;EAC9C,MAAM,CAACO,QAAQ,EAAEC,WAAW,CAAC,GAAGR,QAAQ,CAAS,EAAE,CAAC;EACpD,MAAM,CAACS,cAAc,EAAEC,iBAAiB,CAAC,GAAGV,QAAQ,CAAY,EAAE,CAAC;EACnE,MAAM,CAACW,OAAO,EAAEC,UAAU,CAAC,GAAGZ,QAAQ,CAAC,KAAK,CAAC;EAC7C,MAAM,CAACa,YAAY,EAAEC,eAAe,CAAC,GAAGd,QAAQ,CAAC,KAAK,CAAC;EACvD,MAAM,CAACe,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGhB,QAAQ,CAAC,CAAC,CAAC;EAC3D,MAAM,CAACiB,KAAK,EAAEC,QAAQ,CAAC,GAAGlB,QAAQ,CAAM,IAAI,CAAC;EAE7C,MAAMmB,aAAa,GAAGtB,WAAW,CAAEuB,QAAgB,IAAK;IACtDd,QAAQ,CAACc,QAAQ,CAAC;IAClBZ,WAAW,CAAEa,YAAY,IAAKA,YAAY,GAAGD,QAAQ,CAAC;EACxD,CAAC,EAAE,EAAE,CAAC;EAEN,MAAME,kBAAkB,GAAGvB,OAAO,CAChC,MACE,IAAIE,aAAa,CAAC;IAChBkB,aAAa,EAAEA,aAAa;IAC5BI,sBAAsB,EAAEb,iBAAiB;IACzCc,eAAe,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C,OAAe,IAAK;IACnBjC,WAAW,CAAC,EAAE,CAAC;IACf,OAAOc,kBAAkB,CAACkB,WAAW,CAACC,OAAO,CAAC;EAChD,CAAC,EACD,CAACnB,kBAAkB,CACrB,CAAC;EAED,MAAMoB,aAAa,GAAG7C,WAAW,CAC9B8C,KAAa,IAAKrB,kBAAkB,CAACoB,aAAa,CAACC,KAAK,CAAC,EAC1D,CAACrB,kBAAkB,CACrB,CAAC;EAED,MAAMsB,SAAS,GAAG/C,WAAW,CAC3B,MAAMyB,kBAAkB,CAACsB,SAAS,CAAC,CAAC,EACpC,CAACtB,kBAAkB,CACrB,CAAC;EAED,MAAMuB,sBAAsB,GAAGhD,WAAW,CACxC,MAAMyB,kBAAkB,CAACuB,sBAAsB,CAAC,CAAC,EACjD,CAACvB,kBAAkB,CACrB,CAAC;EAED,OAAO;IACLb,cAAc;IACdF,QAAQ;IACRF,KAAK;IACLM,OAAO;IACPE,YAAY;IACZE,gBAAgB;IAChBE,KAAK;IACL4B,sBAAsB,EAAEA,sBAAsB;IAC9CZ,SAAS,EAAEA,SAAS;IACpBI,QAAQ,EAAEA,QAAQ;IAClBG,WAAW,EAAEA,WAAW;IACxBE,aAAa,EAAEA,aAAa;IAC5BE,SAAS,EAAEA;EACb,CAAC;AACH,CAAC","ignoreList":[]}
@@ -26,11 +26,13 @@ export class LLMModule {
26
26
  }
27
27
  configure({
28
28
  chatConfig,
29
- toolsConfig
29
+ toolsConfig,
30
+ generationConfig
30
31
  }) {
31
32
  this.controller.configure({
32
33
  chatConfig,
33
- toolsConfig
34
+ toolsConfig,
35
+ generationConfig
34
36
  });
35
37
  }
36
38
  async forward(input) {
@@ -1 +1 @@
1
- {"version":3,"names":["LLMController","LLMModule","constructor","tokenCallback","responseCallback","messageHistoryCallback","controller","load","model","onDownloadProgressCallback","setTokenCallback","configure","chatConfig","toolsConfig","forward","input","response","generate","messages","tools","sendMessage","message","messageHistory","deleteMessage","index","interrupt","delete"],"sourceRoot":"../../../../src","sources":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AAa,EAAa;IACtC,IAAI,CAAClB,UAAU,CAACiB,aAAa,CAACC,KAAK,CAAC;IACpC,OAAO,IAAI,CAAClB,UAAU,CAACgB,cAAc;EACvC;EAEAG,SAASA,CAAA,EAAG;IACV,IAAI,CAACnB,UAAU,CAACmB,SAAS,CAAC,CAAC;EAC7B;EAEAC,MAAMA,CAAA,EAAG;IACP,IAAI,CAACpB,UAAU,CAACoB,MAAM,CAAC,CAAC;EAC1B;AACF","ignoreList":[]}
1
+ {"version":3,"names":["LLMController","LLMModule","constructor","tokenCallback","responseCallback","messageHistoryCallback","controller","load","model","onDownloadProgressCallback","setTokenCallback","configure","chatConfig","toolsConfig","generationConfig","forward","input","response","generate","messages","tools","sendMessage","message","messageHistory","deleteMessage","index","interrupt","delete"],"sourceRoot":"../../../../src","sources":["modules/natural_language_processing/LLMModule.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,iCAAiC;AAU/D,OAAO,MAAMC,SAAS,CAAC;EAGrBC,WAAWA,CAAC;IACVC,aAAa;IACbC,gBAAgB;IAChBC;EAKF,CAAC,GAAG,CAAC,CAAC,EAAE;IACN,IAAI,CAACC,UAAU,GAAG,IAAIN,aAAa,CAAC;MAClCG,aAAa;MACbC,gBAAgB;MAChBC;IACF,CAAC,CAAC;EACJ;EAEA,MAAME,IAAIA,CACRC,KAIC,EACDC,0BAAsD,GAAGA,CAAA,KAAM,CAAC,CAAC,EACjE;IACA,MAAM,IAAI,CAACH,UAAU,CAACC,IAAI,CAAC;MACzB,GAAGC,KAAK;MACRC;IACF,CAAC,CAAC;EACJ;EAEAC,gBAAgBA,CAAC;IACfP;EAGF,CAAC,EAAE;IACD,IAAI,CAACG,UAAU,CAACI,gBAAgB,CAACP,aAAa,CAAC;EACjD;EAEAQ,SAASA,CAAC;IACRC,UAAU;IACVC,WAAW;IACXC;EAKF,CAAC,EAAE;IACD,IAAI,CAACR,UAAU,CAACK,SAAS,CAAC;MAAEC,UAAU;MAAEC,WAAW;MAAEC;IAAiB,CAAC,CAAC;EAC1E;EAEA,MAAMC,OAAOA,CAACC,KAAa,EAAmB;IAC5C,MAAM,IAAI,CAACV,UAAU,CAACS,OAAO,CAACC,KAAK,CAAC;IACpC,OAAO,IAAI,CAACV,UAAU,CAACW,QAAQ;EACjC;EAEA,MAAMC,QAAQA,CAACC,QAAmB,EAAEC,KAAiB,EAAmB;IACtE,MAAM,IAAI,CAACd,UAAU,CAACY,QAAQ,CAACC,QAAQ,EAAEC,KAAK,CAAC;IAC/C,OAAO,IAAI,CAACd,UAAU,CAACW,QAAQ;EACjC;EAEA,MAAMI,WAAWA,CAACC,OAAe,EAAsB;IACrD,MAAM,IAAI,CAAChB,UAAU,CAACe,WAAW,CAACC,OAAO,CAAC;IAC1C,OAAO,IAAI,CAAChB,UAAU,CAACiB,cAAc;EACvC;EAEAC,aAAaA,CAACC,KAAa,EAAa;IACtC,IAAI,CAACnB,UAAU,CAACkB,aAAa,CAACC,KAAK,CAAC;IACpC,OAAO,IAAI,CAACnB,UAAU,CAACiB,cAAc;EACvC;EAEAG,SAASA,CAAA,EAAG;IACV,IAAI,CAACpB,UAAU,CAACoB,SAAS,CAAC,CAAC;EAC7B;EAEAC,MAAMA,CAAA,EAAG;IACP,IAAI,CAACrB,UAAU,CAACqB,MAAM,CAAC,CAAC;EAC1B;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["SPECIAL_TOKENS","BOS_TOKEN","EOS_TOKEN","UNK_TOKEN","SEP_TOKEN","PAD_TOKEN","CLS_TOKEN","MASK_TOKEN"],"sourceRoot":"../../../src","sources":["types/llm.ts"],"mappings":";;AAiCA;AACA;;AAeA,OAAO,MAAMA,cAAc,GAAG;EAC5BC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,UAAU,EAAE;AACd,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["SPECIAL_TOKENS","BOS_TOKEN","EOS_TOKEN","UNK_TOKEN","SEP_TOKEN","PAD_TOKEN","CLS_TOKEN","MASK_TOKEN"],"sourceRoot":"../../../src","sources":["types/llm.ts"],"mappings":";;AAoCA;AACA;;AAoBA,OAAO,MAAMA,cAAc,GAAG;EAC5BC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,UAAU,EAAE;AACd,CAAC","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import { ResourceSource } from '../types/common';
2
- import { ChatConfig, LLMTool, Message, ToolsConfig } from '../types/llm';
2
+ import { ChatConfig, GenerationConfig, LLMTool, Message, ToolsConfig } from '../types/llm';
3
3
  export declare class LLMController {
4
4
  private nativeModule;
5
5
  private chatConfig;
@@ -33,13 +33,15 @@ export declare class LLMController {
33
33
  onDownloadProgressCallback?: (downloadProgress: number) => void;
34
34
  }): Promise<void>;
35
35
  setTokenCallback(tokenCallback: (token: string) => void): void;
36
- configure({ chatConfig, toolsConfig, }: {
36
+ configure({ chatConfig, toolsConfig, generationConfig, }: {
37
37
  chatConfig?: Partial<ChatConfig>;
38
38
  toolsConfig?: ToolsConfig;
39
+ generationConfig?: GenerationConfig;
39
40
  }): void;
40
41
  delete(): void;
41
42
  forward(input: string): Promise<void>;
42
43
  interrupt(): void;
44
+ getGeneratedTokenCount(): number;
43
45
  generate(messages: Message[], tools?: LLMTool[]): Promise<void>;
44
46
  sendMessage(message: string): Promise<void>;
45
47
  deleteMessage(index: number): void;
@@ -1 +1 @@
1
- {"version":3,"file":"LLMController.d.ts","sourceRoot":"","sources":["../../../src/controllers/LLMController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAMjD,OAAO,EACL,UAAU,EACV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K,CAAC,EAAE,OAAO,EAAE;IAwB/C,WAAW,CAAC,OAAO,EAAE,MAAM;IAuCjC,aAAa,CAAC,KAAK,EAAE,MAAM;IAQlC,OAAO,CAAC,iBAAiB;CAyB1B"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLLM.d.ts","sourceRoot":"","sources":["../../../../src/hooks/natural_language_processing/useLLM.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAGL,OAAO,EAGR,MAAM,iBAAiB,CAAC;AAMzB,eAAO,MAAM,MAAM,GAAI,yBAGpB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,cAAc,CAAC;QAC5B,eAAe,EAAE,cAAc,CAAC;QAChC,qBAAqB,EAAE,cAAc,CAAC;KACvC,CAAC;IACF,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,KAAG,OA2GH,CAAC"}
1
+ {"version":3,"file":"useLLM.d.ts","sourceRoot":"","sources":["../../../../src/hooks/natural_language_processing/useLLM.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAIL,OAAO,EAGR,MAAM,iBAAiB,CAAC;AAMzB,eAAO,MAAM,MAAM,GAAI,yBAGpB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,cAAc,CAAC;QAC5B,eAAe,EAAE,cAAc,CAAC;QAChC,qBAAqB,EAAE,cAAc,CAAC;KACvC,CAAC;IACF,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,KAAG,OAwHH,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { ResourceSource } from '../../types/common';
2
- import { ChatConfig, LLMTool, Message, ToolsConfig } from '../../types/llm';
2
+ import { ChatConfig, GenerationConfig, LLMTool, Message, ToolsConfig } from '../../types/llm';
3
3
  export declare class LLMModule {
4
4
  private controller;
5
5
  constructor({ tokenCallback, responseCallback, messageHistoryCallback, }?: {
@@ -15,9 +15,10 @@ export declare class LLMModule {
15
15
  setTokenCallback({ tokenCallback, }: {
16
16
  tokenCallback: (token: string) => void;
17
17
  }): void;
18
- configure({ chatConfig, toolsConfig, }: {
18
+ configure({ chatConfig, toolsConfig, generationConfig, }: {
19
19
  chatConfig?: Partial<ChatConfig>;
20
20
  toolsConfig?: ToolsConfig;
21
+ generationConfig?: GenerationConfig;
21
22
  }): void;
22
23
  forward(input: string): Promise<string>;
23
24
  generate(messages: Message[], tools?: LLMTool[]): Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"LLMModule.d.ts","sourceRoot":"","sources":["../../../../src/modules/natural_language_processing/LLMModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE5E,qBAAa,SAAS;IACpB,OAAO,CAAC,UAAU,CAAgB;gBAEtB,EACV,aAAa,EACb,gBAAgB,EAChB,sBAAsB,GACvB,GAAE;QACD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;QACxC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;QAC9C,sBAAsB,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;KACzD;IAQA,IAAI,CACR,KAAK,EAAE;QACL,WAAW,EAAE,cAAc,CAAC;QAC5B,eAAe,EAAE,cAAc,CAAC;QAChC,qBAAqB,EAAE,cAAc,CAAC;KACvC,EACD,0BAA0B,GAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAe;IAQnE,gBAAgB,CAAC,EACf,aAAa,GACd,EAAE;QACD,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;KACxC;IAID,SAAS,CAAC,EACR,UAAU,EACV,WAAW,GACZ,EAAE;QACD,UAAU,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QACjC,WAAW,CAAC,EAAE,WAAW,CAAC;KAC3B;IAIK,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKvC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAKtD,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE;IAKvC,SAAS;IAIT,MAAM;CAGP"}
1
+ {"version":3,"file":"LLMModule.d.ts","sourceRoot":"","sources":["../../../../src/modules/natural_language_processing/LLMModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,OAAO,EACP,OAAO,EACP,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB,qBAAa,SAAS;IACpB,OAAO,CAAC,UAAU,CAAgB;gBAEtB,EACV,aAAa,EACb,gBAAgB,EAChB,sBAAsB,GACvB,GAAE;QACD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;QACxC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;QAC9C,sBAAsB,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;KACzD;IAQA,IAAI,CACR,KAAK,EAAE;QACL,WAAW,EAAE,cAAc,CAAC;QAC5B,eAAe,EAAE,cAAc,CAAC;QAChC,qBAAqB,EAAE,cAAc,CAAC;KACvC,EACD,0BAA0B,GAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAe;IAQnE,gBAAgB,CAAC,EACf,aAAa,GACd,EAAE;QACD,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;KACxC;IAID,SAAS,CAAC,EACR,UAAU,EACV,WAAW,EACX,gBAAgB,GACjB,EAAE;QACD,UAAU,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QACjC,WAAW,CAAC,EAAE,WAAW,CAAC;QAC1B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;KACrC;IAIK,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKvC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAKtD,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE;IAKvC,SAAS;IAIT,MAAM;CAGP"}
@@ -6,9 +6,11 @@ export interface LLMType {
6
6
  isGenerating: boolean;
7
7
  downloadProgress: number;
8
8
  error: string | null;
9
- configure: ({ chatConfig, toolsConfig, }: {
9
+ getGeneratedTokenCount: () => number;
10
+ configure: ({ chatConfig, toolsConfig, generationConfig, }: {
10
11
  chatConfig?: Partial<ChatConfig>;
11
12
  toolsConfig?: ToolsConfig;
13
+ generationConfig?: GenerationConfig;
12
14
  }) => void;
13
15
  generate: (messages: Message[], tools?: LLMTool[]) => Promise<void>;
14
16
  sendMessage: (message: string) => Promise<void>;
@@ -35,6 +37,10 @@ export interface ToolsConfig {
35
37
  executeToolCallback: (call: ToolCall) => Promise<string | null>;
36
38
  displayToolCalls?: boolean;
37
39
  }
40
+ export interface GenerationConfig {
41
+ outputTokenBatchSize?: number;
42
+ batchTimeInterval?: number;
43
+ }
38
44
  export declare const SPECIAL_TOKENS: {
39
45
  BOS_TOKEN: string;
40
46
  EOS_TOKEN: string;
@@ -1 +1 @@
1
- {"version":3,"file":"llm.d.ts","sourceRoot":"","sources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AAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,UAAU;IACzB,qBAAqB,EAAE,OAAO,EAAE,CAAC;IACjC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,mBAAmB,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAChE,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,gBAAgB;IAC/B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,cAAc;;;;;;;;CAQ1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-executorch",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "An easy way to run AI models in React Native with ExecuTorch",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/module/index.js",
@@ -17,6 +17,8 @@
17
17
  "*.podspec",
18
18
  "third-party/include",
19
19
  "third-party",
20
+ "!third-party/ios/ExecutorchLib",
21
+ "!third-party/ios/libs/executorch",
20
22
  "!ios/build",
21
23
  "!android/build",
22
24
  "!android/gradle",
@@ -13,48 +13,30 @@ Pod::Spec.new do |s|
13
13
  s.platforms = { :ios => min_ios_version_supported }
14
14
  s.source = { :git => "https://github.com/software-mansion/react-native-executorch.git", :tag => "#{s.version}" }
15
15
 
16
- et_binaries_path = File.expand_path('$(PODS_TARGET_SRCROOT)/ios/libs/executorch', __dir__)
17
- tokenizers_binaries_path = File.expand_path('$(PODS_TARGET_SRCROOT)/ios/libs/tokenizers-cpp', __dir__)
16
+ tokenizers_binaries_path = File.expand_path('$(PODS_TARGET_SRCROOT)/third-party/ios/libs/tokenizers-cpp', __dir__)
18
17
 
19
- s.frameworks = [
20
- 'CoreML',
21
- 'Accelerate',
22
- 'Metal',
23
- 'MetalPerformanceShaders',
24
- 'MetalPerformanceShadersGraph'
25
- ]
18
+ pthreadpool_binaries_path = File.expand_path('$(PODS_TARGET_SRCROOT)/third-party/ios/libs/pthreadpool', __dir__)
19
+ cpuinfo_binaries_path = File.expand_path('$(PODS_TARGET_SRCROOT)/third-party/ios/libs/cpuinfo', __dir__)
26
20
 
27
21
  s.user_target_xcconfig = {
28
22
  "HEADER_SEARCH_PATHS" => "$(PODS_TARGET_SRCROOT)/third-party/include",
29
23
 
30
24
  "OTHER_LDFLAGS[sdk=iphoneos*]" => [
31
- '$(inherited)',
32
- "-force_load \"#{et_binaries_path}\"/libbackend_coreml_ios.a",
33
- "-force_load \"#{et_binaries_path}\"/libbackend_mps_ios.a",
34
- "-force_load \"#{et_binaries_path}\"/libbackend_xnnpack_ios.a",
35
- "-force_load \"#{et_binaries_path}\"/libexecutorch_ios.a",
36
- "-force_load \"#{et_binaries_path}\"/libkernels_custom_ios.a",
37
- "-force_load \"#{et_binaries_path}\"/libkernels_optimized_ios.a",
38
- "-force_load \"#{et_binaries_path}\"/libkernels_quantized_ios.a",
39
- "\"#{et_binaries_path}\"/libkernels_portable_ios.a",
25
+ '$(inherited)',
40
26
  "\"#{tokenizers_binaries_path}/physical-arm64-release/libtokenizers_cpp.a\"",
41
27
  "\"#{tokenizers_binaries_path}/physical-arm64-release/libsentencepiece.a\"",
42
- "\"#{tokenizers_binaries_path}/physical-arm64-release/libtokenizers_c.a\""
28
+ "\"#{tokenizers_binaries_path}/physical-arm64-release/libtokenizers_c.a\"",
29
+ "\"#{pthreadpool_binaries_path}/physical-arm64-release/libpthreadpool.a\"",
30
+ "\"#{cpuinfo_binaries_path}/libcpuinfo.a\""
43
31
  ].join(' '),
44
32
 
45
33
  "OTHER_LDFLAGS[sdk=iphonesimulator*]" => [
46
- '$(inherited)',
47
- "-force_load \"#{et_binaries_path}\"/libbackend_coreml_simulator.a",
48
- "-force_load \"#{et_binaries_path}\"/libbackend_mps_simulator.a",
49
- "-force_load \"#{et_binaries_path}\"/libbackend_xnnpack_simulator.a",
50
- "-force_load \"#{et_binaries_path}\"/libexecutorch_simulator.a",
51
- "-force_load \"#{et_binaries_path}\"/libkernels_custom_simulator.a",
52
- "-force_load \"#{et_binaries_path}\"/libkernels_optimized_simulator.a",
53
- "-force_load \"#{et_binaries_path}\"/libkernels_quantized_simulator.a",
54
- "\"#{et_binaries_path}\"/libkernels_portable_simulator.a",
34
+ '$(inherited)',
55
35
  "\"#{tokenizers_binaries_path}/simulator-arm64-debug/libtokenizers_cpp.a\"",
56
36
  "\"#{tokenizers_binaries_path}/simulator-arm64-debug/libsentencepiece.a\"",
57
- "\"#{tokenizers_binaries_path}/simulator-arm64-debug/libtokenizers_c.a\""
37
+ "\"#{tokenizers_binaries_path}/simulator-arm64-debug/libtokenizers_c.a\"",
38
+ "\"#{pthreadpool_binaries_path}/simulator-arm64-debug/libpthreadpool.a\"",
39
+ "\"#{cpuinfo_binaries_path}/libcpuinfo.a\""
58
40
  ].join(' '),
59
41
 
60
42
  'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'x86_64',
@@ -76,7 +58,7 @@ Pod::Spec.new do |s|
76
58
  ]
77
59
 
78
60
  s.libraries = "z"
79
-
61
+ s.ios.vendored_frameworks = "third-party/ios/ExecutorchLib.xcframework"
80
62
  # Exclude file with tests to not introduce gtest dependency.
81
63
  # Do not include the headers from common/rnexecutorch/jsi/ as source files.
82
64
  # Xcode/Cocoapods leaks them to other pods that an app also depends on, so if
@@ -93,7 +75,6 @@ Pod::Spec.new do |s|
93
75
  s.preserve_paths = "common/rnexecutorch/jsi/*.{h,hpp}"
94
76
 
95
77
  s.dependency "opencv-rne", "~> 4.11.0"
96
- s.dependency "sqlite3"
97
78
 
98
79
  install_modules_dependencies(s)
99
80
  end
@@ -6,6 +6,7 @@ import { DEFAULT_CHAT_CONFIG } from '../constants/llmDefaults';
6
6
  import { readAsStringAsync } from 'expo-file-system';
7
7
  import {
8
8
  ChatConfig,
9
+ GenerationConfig,
9
10
  LLMTool,
10
11
  Message,
11
12
  SPECIAL_TOKENS,
@@ -132,13 +133,23 @@ export class LLMController {
132
133
  this.nativeModule = global.loadLLM(modelPath, tokenizerPath);
133
134
  this.isReadyCallback(true);
134
135
  this.onToken = (data: string) => {
136
+ if (!data) {
137
+ return;
138
+ }
139
+
140
+ if (
141
+ SPECIAL_TOKENS.EOS_TOKEN in this.tokenizerConfig &&
142
+ data.indexOf(this.tokenizerConfig.eos_token) >= 0
143
+ ) {
144
+ data = data.replaceAll(this.tokenizerConfig.eos_token, '');
145
+ }
135
146
  if (
136
- !data ||
137
- (SPECIAL_TOKENS.EOS_TOKEN in this.tokenizerConfig &&
138
- data === this.tokenizerConfig.eos_token) ||
139
- (SPECIAL_TOKENS.PAD_TOKEN in this.tokenizerConfig &&
140
- data === this.tokenizerConfig.pad_token)
147
+ SPECIAL_TOKENS.PAD_TOKEN in this.tokenizerConfig &&
148
+ data.indexOf(this.tokenizerConfig.pad_token) >= 0
141
149
  ) {
150
+ data = data.replaceAll(this.tokenizerConfig.pad_token, '');
151
+ }
152
+ if (data.length === 0) {
142
153
  return;
143
154
  }
144
155
 
@@ -158,13 +169,22 @@ export class LLMController {
158
169
  public configure({
159
170
  chatConfig,
160
171
  toolsConfig,
172
+ generationConfig,
161
173
  }: {
162
174
  chatConfig?: Partial<ChatConfig>;
163
175
  toolsConfig?: ToolsConfig;
176
+ generationConfig?: GenerationConfig;
164
177
  }) {
165
178
  this.chatConfig = { ...DEFAULT_CHAT_CONFIG, ...chatConfig };
166
179
  this.toolsConfig = toolsConfig;
167
180
 
181
+ if (generationConfig?.outputTokenBatchSize) {
182
+ this.nativeModule.setCountInterval(generationConfig.outputTokenBatchSize);
183
+ }
184
+ if (generationConfig?.batchTimeInterval) {
185
+ this.nativeModule.setTimeInterval(generationConfig.batchTimeInterval);
186
+ }
187
+
168
188
  // reset inner state when loading new configuration
169
189
  this.responseCallback('');
170
190
  this.messageHistoryCallback(this.chatConfig.initialMessageHistory);
@@ -206,6 +226,10 @@ export class LLMController {
206
226
  this.nativeModule.interrupt();
207
227
  }
208
228
 
229
+ public getGeneratedTokenCount(): number {
230
+ return this.nativeModule.getGeneratedTokenCount();
231
+ }
232
+
209
233
  public async generate(messages: Message[], tools?: LLMTool[]) {
210
234
  if (!this._isReady) {
211
235
  throw new Error(getError(ETError.ModuleNotLoaded));
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
2
2
  import { ResourceSource } from '../../types/common';
3
3
  import {
4
4
  ChatConfig,
5
+ GenerationConfig,
5
6
  LLMTool,
6
7
  LLMType,
7
8
  Message,
@@ -82,10 +83,17 @@ export const useLLM = ({
82
83
  ({
83
84
  chatConfig,
84
85
  toolsConfig,
86
+ generationConfig,
85
87
  }: {
86
88
  chatConfig?: Partial<ChatConfig>;
87
89
  toolsConfig?: ToolsConfig;
88
- }) => controllerInstance.configure({ chatConfig, toolsConfig }),
90
+ generationConfig?: GenerationConfig;
91
+ }) =>
92
+ controllerInstance.configure({
93
+ chatConfig,
94
+ toolsConfig,
95
+ generationConfig,
96
+ }),
89
97
  [controllerInstance]
90
98
  );
91
99
 
@@ -115,6 +123,11 @@ export const useLLM = ({
115
123
  [controllerInstance]
116
124
  );
117
125
 
126
+ const getGeneratedTokenCount = useCallback(
127
+ () => controllerInstance.getGeneratedTokenCount(),
128
+ [controllerInstance]
129
+ );
130
+
118
131
  return {
119
132
  messageHistory,
120
133
  response,
@@ -123,6 +136,7 @@ export const useLLM = ({
123
136
  isGenerating,
124
137
  downloadProgress,
125
138
  error,
139
+ getGeneratedTokenCount: getGeneratedTokenCount,
126
140
  configure: configure,
127
141
  generate: generate,
128
142
  sendMessage: sendMessage,
@@ -1,6 +1,12 @@
1
1
  import { LLMController } from '../../controllers/LLMController';
2
2
  import { ResourceSource } from '../../types/common';
3
- import { ChatConfig, LLMTool, Message, ToolsConfig } from '../../types/llm';
3
+ import {
4
+ ChatConfig,
5
+ GenerationConfig,
6
+ LLMTool,
7
+ Message,
8
+ ToolsConfig,
9
+ } from '../../types/llm';
4
10
 
5
11
  export class LLMModule {
6
12
  private controller: LLMController;
@@ -46,11 +52,13 @@ export class LLMModule {
46
52
  configure({
47
53
  chatConfig,
48
54
  toolsConfig,
55
+ generationConfig,
49
56
  }: {
50
57
  chatConfig?: Partial<ChatConfig>;
51
58
  toolsConfig?: ToolsConfig;
59
+ generationConfig?: GenerationConfig;
52
60
  }) {
53
- this.controller.configure({ chatConfig, toolsConfig });
61
+ this.controller.configure({ chatConfig, toolsConfig, generationConfig });
54
62
  }
55
63
 
56
64
  async forward(input: string): Promise<string> {
package/src/types/llm.ts CHANGED
@@ -6,12 +6,15 @@ export interface LLMType {
6
6
  isGenerating: boolean;
7
7
  downloadProgress: number;
8
8
  error: string | null;
9
+ getGeneratedTokenCount: () => number;
9
10
  configure: ({
10
11
  chatConfig,
11
12
  toolsConfig,
13
+ generationConfig,
12
14
  }: {
13
15
  chatConfig?: Partial<ChatConfig>;
14
16
  toolsConfig?: ToolsConfig;
17
+ generationConfig?: GenerationConfig;
15
18
  }) => void;
16
19
  generate: (messages: Message[], tools?: LLMTool[]) => Promise<void>;
17
20
  sendMessage: (message: string) => Promise<void>;
@@ -47,6 +50,11 @@ export interface ToolsConfig {
47
50
  displayToolCalls?: boolean;
48
51
  }
49
52
 
53
+ export interface GenerationConfig {
54
+ outputTokenBatchSize?: number;
55
+ batchTimeInterval?: number;
56
+ }
57
+
50
58
  export const SPECIAL_TOKENS = {
51
59
  BOS_TOKEN: 'bos_token',
52
60
  EOS_TOKEN: 'eos_token',
@@ -2,95 +2,11 @@
2
2
  #ifndef C10_MACROS_EXPORT_H_
3
3
  #define C10_MACROS_EXPORT_H_
4
4
 
5
- /* Header file to define the common scaffolding for exported symbols.
6
- *
7
- * Export is by itself a quite tricky situation to deal with, and if you are
8
- * hitting this file, make sure you start with the background here:
9
- * - Linux: https://gcc.gnu.org/wiki/Visibility
10
- * - Windows:
11
- * https://docs.microsoft.com/en-us/cpp/cpp/dllexport-dllimport?view=vs-2017
12
- *
13
- * Do NOT include this file directly. Instead, use c10/macros/Macros.h
14
- */
15
-
16
- // You do not need to edit this part of file unless you are changing the core
17
- // pytorch export abstractions.
18
- //
19
- // This part defines the C10 core export and import macros. This is controlled
20
- // by whether we are building shared libraries or not, which is determined
21
- // during build time and codified in c10/core/cmake_macros.h.
22
- // When the library is built as a shared lib, EXPORT and IMPORT will contain
23
- // visibility attributes. If it is being built as a static lib, then EXPORT
24
- // and IMPORT basically have no effect.
25
-
26
- // As a rule of thumb, you should almost NEVER mix static and shared builds for
27
- // libraries that depend on c10. AKA, if c10 is built as a static library, we
28
- // recommend everything dependent on c10 to be built statically. If c10 is built
29
- // as a shared library, everything dependent on it should be built as shared. In
30
- // the PyTorch project, all native libraries shall use the macro
31
- // C10_BUILD_SHARED_LIB to check whether pytorch is building shared or static
32
- // libraries.
33
-
34
- // For build systems that do not directly depend on CMake and directly build
35
- // from the source directory (such as Buck), one may not have a cmake_macros.h
36
- // file at all. In this case, the build system is responsible for providing
37
- // correct macro definitions corresponding to the cmake_macros.h.in file.
38
- //
39
- // In such scenarios, one should define the macro
40
- // C10_USING_CUSTOM_GENERATED_MACROS
41
- // to inform this header that it does not need to include the cmake_macros.h
42
- // file.
43
-
44
5
  #ifndef C10_USING_CUSTOM_GENERATED_MACROS
45
6
  #include <c10/macros/cmake_macros.h>
46
7
  #endif // C10_USING_CUSTOM_GENERATED_MACROS
47
8
 
48
- #ifdef _WIN32
49
- #define C10_HIDDEN
50
- #if defined(C10_BUILD_SHARED_LIBS)
51
- #define C10_EXPORT __declspec(dllexport)
52
- #define C10_IMPORT __declspec(dllimport)
53
- #else
54
- #define C10_EXPORT
55
- #define C10_IMPORT
56
- #endif
57
- #else // _WIN32
58
- #if defined(__GNUC__)
59
- #define C10_EXPORT __attribute__((__visibility__("default")))
60
- #define C10_HIDDEN __attribute__((__visibility__("hidden")))
61
- #else // defined(__GNUC__)
62
- #define C10_EXPORT
63
- #define C10_HIDDEN
64
- #endif // defined(__GNUC__)
65
- #define C10_IMPORT C10_EXPORT
66
- #endif // _WIN32
67
-
68
- #ifdef NO_EXPORT
69
- #undef C10_EXPORT
70
- #define C10_EXPORT
71
- #endif
72
-
73
- // Definition of an adaptive XX_API macro, that depends on whether you are
74
- // building the library itself or not, routes to XX_EXPORT and XX_IMPORT.
75
- // Basically, you will need to do this for each shared library that you are
76
- // building, and the instruction is as follows: assuming that you are building
77
- // a library called libawesome.so. You should:
78
- // (1) for your cmake target (usually done by "add_library(awesome, ...)"),
79
- // define a macro called AWESOME_BUILD_MAIN_LIB using
80
- // target_compile_options.
81
- // (2) define the AWESOME_API macro similar to the one below.
82
- // And in the source file of your awesome library, use AWESOME_API to
83
- // annotate public symbols.
84
-
85
- // Here, for the C10 library, we will define the macro C10_API for both import
86
- // and export.
87
-
88
- // This one is being used by libc10.so
89
- #ifdef C10_BUILD_MAIN_LIB
90
- #define C10_API C10_EXPORT
91
- #else
92
- #define C10_API C10_IMPORT
93
- #endif
9
+ #include <torch/headeronly/macros/Export.h>
94
10
 
95
11
  // This one is being used by libtorch.so
96
12
  #ifdef CAFFE2_BUILD_MAIN_LIB
@@ -160,4 +76,4 @@
160
76
  #define C10_API_ENUM
161
77
  #endif
162
78
 
163
- #endif // C10_MACROS_MACROS_H_
79
+ #endif // C10_MACROS_EXPORT_H_
@@ -242,7 +242,7 @@ using namespace c10::xpu;
242
242
  #ifdef __HIPCC__
243
243
  // Unlike CUDA, HIP requires a HIP header to be included for __host__ to work.
244
244
  // We do this #include here so that C10_HOST_DEVICE and friends will Just Work.
245
- // See https://github.com/ROCm-Developer-Tools/HIP/issues/441
245
+ // See https://github.com/ROCm/hip/issues/441
246
246
  #include <hip/hip_runtime.h>
247
247
  #endif
248
248
 
@@ -390,11 +390,24 @@ __host__ __device__
390
390
  #endif // __SYCL_DEVICE_ONLY__
391
391
  }
392
392
  #endif // NDEBUG
393
- // ROCm disable kernel assert by default
393
+ // ROCm disables kernel assert by default for performance considerations.
394
+ // Though ROCm supports __assert_fail, it uses kernel printf which has
395
+ // a non-negligible performance impact even if the assert condition is
396
+ // never triggered. We choose to use abort() instead which will still
397
+ // terminate the application but without a more useful error message.
394
398
  #if !defined(C10_USE_ROCM_KERNEL_ASSERT) and defined(USE_ROCM)
395
- #define CUDA_KERNEL_ASSERT(cond)
396
- #define CUDA_KERNEL_ASSERT_MSG(cond, msg)
397
- #define SYCL_KERNEL_ASSERT(cond)
399
+ #define CUDA_KERNEL_ASSERT(cond) \
400
+ if C10_UNLIKELY (!(cond)) { \
401
+ abort(); \
402
+ }
403
+ #define CUDA_KERNEL_ASSERT_MSG(cond, msg) \
404
+ if C10_UNLIKELY (!(cond)) { \
405
+ abort(); \
406
+ }
407
+ #define SYCL_KERNEL_ASSERT(cond) \
408
+ if C10_UNLIKELY (!(cond)) { \
409
+ abort(); \
410
+ }
398
411
  #else
399
412
  #define CUDA_KERNEL_ASSERT(cond) \
400
413
  if (C10_UNLIKELY(!(cond))) { \
@@ -494,4 +507,14 @@ __host__ __device__
494
507
 
495
508
  #endif
496
509
 
510
+ // This macro is used to find older C++ compilers
511
+ // that don't support move optimization for return values.
512
+
513
+ #if (defined(__GNUC__) && __GNUC__ < 13) || \
514
+ (defined(__clang_major__) && __clang_major__ < 13)
515
+ #define C10_RETURN_MOVE_IF_OLD_COMPILER 1
516
+ #else
517
+ #define C10_RETURN_MOVE_IF_OLD_COMPILER 0
518
+ #endif
519
+
497
520
  #endif // C10_MACROS_MACROS_H_
@@ -10,14 +10,11 @@ C10_CLANG_DIAGNOSTIC_PUSH()
10
10
  C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-int-float-conversion")
11
11
  #endif
12
12
 
13
- #if defined(SYCL_EXT_ONEAPI_BFLOAT16_MATH_FUNCTIONS)
14
13
  #if defined(CL_SYCL_LANGUAGE_VERSION)
15
14
  #include <CL/sycl.hpp> // for SYCL 1.2.1
16
- #else
15
+ #elif defined(SYCL_LANGUAGE_VERSION)
17
16
  #include <sycl/sycl.hpp> // for SYCL 2020
18
17
  #endif
19
- #include <ext/oneapi/bfloat16.hpp>
20
- #endif
21
18
 
22
19
  namespace c10 {
23
20