Skip to content

feat: port LLMs to C++#415

Merged
chmjkb merged 34 commits intomainfrom
@chmjkb/llm-cpp-port
Jun 30, 2025
Merged

feat: port LLMs to C++#415
chmjkb merged 34 commits intomainfrom
@chmjkb/llm-cpp-port

Conversation

@chmjkb
Copy link
Copy Markdown
Collaborator

@chmjkb chmjkb commented Jun 24, 2025

Description

This PR ports the current LLM functionality to C++, getting rid of the Runner within the ExecutorchLib framework. I've also made some changes to the build system.

tokenizers-cpp

  • Previously the library was linked in ExecutorchLib in XCode via a build script, now it is completely removed from the frameworks.
  • I've prebuiilt static libraries from tokenizers-cpp repo, which I uploaded to common/ios/libs/tokenizers-cpp, similarly to the pre-build ExecuTorch binaries.
  • The includes for tokenizers-cpp are now in react-native-executorch/third-party/include/tokenizers-cpp/tokenizers_cpp.h
  • Made some changes to the libs directory structure, please see the podspec for reference.
  • These headers are then included from the llama runner source code.
  • Since tokenizers-cpp for Android is pre-built with the ExecuTorch aar, I'm not making any changes here. This will need to be updated once we bump the ExecuTorch runtime and when we can safely get rid of the aar/jitpack setup. We can keep tokenizers-cpp as our submodule and then just reference it in Android's CMake.

runner

  • The runner source along with headers was moved from ExecuTorchLib to common/runner, similarly to ada and is compiled on the fly when our library compiles.
  • In the current situation, I think that we will be soon able to get rid of the ET fork and the submodule.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improves or adds clarity to existing documentation)

Tested on

  • iOS
  • Android

Testing instructions

Screenshots

Related issues

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional notes

@chmjkb chmjkb changed the base branch from main to @chmjkb/text-embeddings-cpp-port June 24, 2025 13:35
@chmjkb chmjkb force-pushed the @chmjkb/text-embeddings-cpp-port branch from 0200048 to 2cfb189 Compare June 25, 2025 08:15
Base automatically changed from @chmjkb/text-embeddings-cpp-port to main June 25, 2025 10:43
@chmjkb chmjkb force-pushed the @chmjkb/llm-cpp-port branch from 46d597e to 45938f3 Compare June 25, 2025 10:55
@chmjkb chmjkb self-assigned this Jun 27, 2025
@chmjkb chmjkb added this to the v0.5.0 milestone Jun 27, 2025
@chmjkb chmjkb linked an issue Jun 27, 2025 that may be closed by this pull request
@chmjkb chmjkb marked this pull request as ready for review June 27, 2025 10:29
@chmjkb chmjkb requested a review from mkopcins June 27, 2025 10:29
Comment thread packages/react-native-executorch/common/rnexecutorch/models/llm/LLM.cpp Outdated
Comment thread packages/react-native-executorch/common/rnexecutorch/models/llm/LLM.cpp Outdated
Comment thread packages/react-native-executorch/common/runner/sampler.h
* SOFTWARE.
*/

// #include <executorch/extension/llm/sampler/sampler.h>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly sure why that line was here in the first place. Below you can see a line:

#include "sampler.h"

Which literally includes the same thing. Also, we can't access extension/llm/sampler/sampler.h since there is no such header in our code, so it wouldn't compile.

@chmjkb chmjkb merged commit 0f4de4e into main Jun 30, 2025
2 checks passed
@chmjkb chmjkb deleted the @chmjkb/llm-cpp-port branch June 30, 2025 13:00
@msluszniak msluszniak mentioned this pull request Jul 14, 2025
10 tasks
mkopcins pushed a commit that referenced this pull request Oct 15, 2025
## Description

This PR ports the current LLM functionality to C++, getting rid of the
`Runner` within the `ExecutorchLib` framework. I've also made some
changes to the build system.

`tokenizers-cpp`
- Previously the library was linked in `ExecutorchLib` in XCode via a
build script, now it is completely removed from the frameworks.
- I've prebuiilt static libraries from `tokenizers-cpp` repo, which I
uploaded to `common/ios/libs/tokenizers-cpp`, similarly to the pre-build
ExecuTorch binaries.
- The includes for tokenizers-cpp are now in
`react-native-executorch/third-party/include/tokenizers-cpp/tokenizers_cpp.h`
- Made some changes to the `libs` directory structure, please see the
podspec for reference.
- These headers are then included from the llama runner source code.
- Since `tokenizers-cpp` for Android is pre-built with the `ExecuTorch`
aar, I'm not making any changes here. This will need to be updated once
we bump the ExecuTorch runtime and when we can safely get rid of the
aar/jitpack setup. We can keep tokenizers-cpp as our submodule and then
just reference it in Android's CMake.

`runner`
- The runner source along with headers was moved from `ExecuTorchLib` to
`common/runner`, similarly to `ada` and is compiled on the fly when our
library compiles.
- In the current situation, I think that we will be soon able to get rid
of the ET fork and the submodule.




### Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Documentation update (improves or adds clarity to existing
documentation)

### Tested on

- [x] iOS
- [x] Android

### Testing instructions

<!-- Provide step-by-step instructions on how to test your changes.
Include setup details if necessary. -->

### Screenshots

<!-- Add screenshots here, if applicable -->

### Related issues

<!-- Link related issues here using #issue-number -->

### Checklist

- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have updated the documentation accordingly
- [ ] My changes generate no new warnings

### Additional notes

<!-- Include any additional information, assumptions, or context that
reviewers might need to understand this PR. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port LLMs to C++ native code

3 participants